2016-12-16 07:26:15 +01:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2016, 2017, 2018, 2019 MinIO, Inc.
|
2016-12-16 07:26:15 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2018-01-22 23:54:55 +01:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-04-22 04:23:54 +02:00
|
|
|
"github.com/gorilla/mux"
|
2019-10-23 06:01:14 +02:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2018-01-22 23:54:55 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-11-04 18:30:59 +01:00
|
|
|
adminPathPrefix = minioReservedBucketPath + "/admin"
|
|
|
|
adminAPIVersion = madmin.AdminAPIVersion
|
|
|
|
adminAPIVersionPrefix = SlashSeparator + madmin.AdminAPIVersion
|
2018-01-22 23:54:55 +01:00
|
|
|
)
|
2016-12-16 07:26:15 +01:00
|
|
|
|
2019-04-09 20:39:42 +02:00
|
|
|
// adminAPIHandlers provides HTTP handlers for MinIO admin API.
|
2019-11-04 18:30:59 +01:00
|
|
|
type adminAPIHandlers struct{}
|
2016-12-16 07:26:15 +01:00
|
|
|
|
|
|
|
// registerAdminRouter - Add handler functions for each service REST API routes.
|
2019-01-23 20:10:59 +01:00
|
|
|
func registerAdminRouter(router *mux.Router, enableConfigOps, enableIAMOps bool) {
|
2016-12-16 07:26:15 +01:00
|
|
|
|
|
|
|
adminAPI := adminAPIHandlers{}
|
|
|
|
// Admin router
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter := router.PathPrefix(adminPathPrefix).Subrouter()
|
2018-01-22 23:54:55 +01:00
|
|
|
|
2017-01-04 08:39:22 +01:00
|
|
|
/// Service operations
|
2016-12-16 07:26:15 +01:00
|
|
|
|
2019-08-29 00:04:43 +02:00
|
|
|
// Restart and stop MinIO service.
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix+"/service").HandlerFunc(httpTraceAll(adminAPI.ServiceActionHandler)).Queries("action", "{action:.*}")
|
2019-08-29 00:04:43 +02:00
|
|
|
// Update MinIO servers.
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix+"/update").HandlerFunc(httpTraceAll(adminAPI.ServerUpdateHandler)).Queries("updateURL", "{updateURL:.*}")
|
2017-01-04 08:39:22 +01:00
|
|
|
|
2017-02-15 19:45:45 +01:00
|
|
|
// Info operations
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/info").HandlerFunc(httpTraceAll(adminAPI.ServerInfoHandler))
|
2019-10-03 16:48:38 +02:00
|
|
|
// Harware Info operations
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/hardware").HandlerFunc(httpTraceAll(adminAPI.ServerHardwareInfoHandler)).Queries("hwType", "{hwType:.*}")
|
2019-10-23 06:01:14 +02:00
|
|
|
|
|
|
|
// StorageInfo operations
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/storageinfo").HandlerFunc(httpTraceAll(adminAPI.StorageInfoHandler))
|
2019-12-12 15:02:37 +01:00
|
|
|
// DataUsageInfo operations
|
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/datausageinfo").HandlerFunc(httpTraceAll(adminAPI.DataUsageInfoHandler))
|
2017-02-15 19:45:45 +01:00
|
|
|
|
2018-10-18 02:25:16 +02:00
|
|
|
if globalIsDistXL || globalIsXL {
|
|
|
|
/// Heal operations
|
2017-01-17 19:02:58 +01:00
|
|
|
|
2018-10-18 02:25:16 +02:00
|
|
|
// Heal processing endpoint.
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix + "/heal/").HandlerFunc(httpTraceAll(adminAPI.HealHandler))
|
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix + "/heal/{bucket}").HandlerFunc(httpTraceAll(adminAPI.HealHandler))
|
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix + "/heal/{bucket}/{prefix:.*}").HandlerFunc(httpTraceAll(adminAPI.HealHandler))
|
2018-12-31 18:46:44 +01:00
|
|
|
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix + "/background-heal/status").HandlerFunc(httpTraceAll(adminAPI.BackgroundHealStatusHandler))
|
2019-06-26 01:42:24 +02:00
|
|
|
|
2018-12-31 18:46:44 +01:00
|
|
|
/// Health operations
|
|
|
|
|
2018-10-18 02:25:16 +02:00
|
|
|
}
|
2019-01-10 04:04:19 +01:00
|
|
|
// Performance command - return performance details based on input type
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/performance").HandlerFunc(httpTraceAll(adminAPI.PerfInfoHandler)).Queries("perfType", "{perfType:.*}")
|
2017-02-20 21:58:50 +01:00
|
|
|
|
2018-09-19 01:46:35 +02:00
|
|
|
// Profiling operations
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix+"/profiling/start").HandlerFunc(httpTraceAll(adminAPI.StartProfilingHandler)).
|
2018-09-27 06:02:05 +02:00
|
|
|
Queries("profilerType", "{profilerType:.*}")
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/profiling/download").HandlerFunc(httpTraceAll(adminAPI.DownloadProfilingHandler))
|
2018-09-19 01:46:35 +02:00
|
|
|
|
2019-10-23 07:59:13 +02:00
|
|
|
// Config KV operations.
|
|
|
|
if enableConfigOps {
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/get-config-kv").HandlerFunc(httpTraceHdrs(adminAPI.GetConfigKVHandler)).Queries("key", "{key:.*}")
|
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix + "/set-config-kv").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigKVHandler))
|
|
|
|
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix + "/del-config-kv").HandlerFunc(httpTraceHdrs(adminAPI.DelConfigKVHandler))
|
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/help-config-kv").HandlerFunc(httpTraceAll(adminAPI.HelpConfigKVHandler)).Queries("subSys", "{subSys:.*}", "key", "{key:.*}")
|
2019-11-05 15:18:26 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/list-config-history-kv").HandlerFunc(httpTraceAll(adminAPI.ListConfigHistoryKVHandler)).Queries("count", "{count:[0-9]+}")
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix+"/clear-config-history-kv").HandlerFunc(httpTraceHdrs(adminAPI.ClearConfigHistoryKVHandler)).Queries("restoreId", "{restoreId:.*}")
|
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/restore-config-history-kv").HandlerFunc(httpTraceHdrs(adminAPI.RestoreConfigHistoryKVHandler)).Queries("restoreId", "{restoreId:.*}")
|
2019-10-23 07:59:13 +02:00
|
|
|
}
|
|
|
|
|
2017-02-20 21:58:50 +01:00
|
|
|
/// Config operations
|
2019-01-23 20:10:59 +01:00
|
|
|
if enableConfigOps {
|
2018-12-18 22:03:26 +01:00
|
|
|
// Get config
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/config").HandlerFunc(httpTraceHdrs(adminAPI.GetConfigHandler))
|
2018-12-18 22:03:26 +01:00
|
|
|
// Set config
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix + "/config").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigHandler))
|
2019-01-23 20:10:59 +01:00
|
|
|
}
|
2018-10-09 23:00:01 +02:00
|
|
|
|
2019-01-23 20:10:59 +01:00
|
|
|
if enableIAMOps {
|
2018-12-18 22:03:26 +01:00
|
|
|
// -- IAM APIs --
|
2018-10-13 09:18:43 +02:00
|
|
|
|
2018-12-18 22:03:26 +01:00
|
|
|
// Add policy IAM
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/add-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.AddCannedPolicy)).Queries("name",
|
2019-01-23 20:10:59 +01:00
|
|
|
"{name:.*}")
|
2018-10-16 21:48:19 +02:00
|
|
|
|
2018-12-18 22:03:26 +01:00
|
|
|
// Add user IAM
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/add-user").HandlerFunc(httpTraceHdrs(adminAPI.AddUser)).Queries("accessKey", "{accessKey:.*}")
|
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/set-user-status").HandlerFunc(httpTraceHdrs(adminAPI.SetUserStatus)).
|
2018-12-18 22:03:26 +01:00
|
|
|
Queries("accessKey", "{accessKey:.*}").Queries("status", "{status:.*}")
|
2018-10-16 21:48:19 +02:00
|
|
|
|
2019-09-26 20:23:13 +02:00
|
|
|
// Info policy IAM
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/info-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.InfoCannedPolicy)).Queries("name", "{name:.*}")
|
2019-09-26 20:23:13 +02:00
|
|
|
|
2018-12-18 22:03:26 +01:00
|
|
|
// Remove policy IAM
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix+"/remove-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.RemoveCannedPolicy)).Queries("name", "{name:.*}")
|
2018-10-09 23:00:01 +02:00
|
|
|
|
2019-08-13 22:41:06 +02:00
|
|
|
// Set user or group policy
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/set-user-or-group-policy").
|
2019-08-13 22:41:06 +02:00
|
|
|
HandlerFunc(httpTraceHdrs(adminAPI.SetPolicyForUserOrGroup)).
|
|
|
|
Queries("policyName", "{policyName:.*}", "userOrGroup", "{userOrGroup:.*}", "isGroup", "{isGroup:true|false}")
|
|
|
|
|
2018-12-18 22:03:26 +01:00
|
|
|
// Remove user IAM
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix+"/remove-user").HandlerFunc(httpTraceHdrs(adminAPI.RemoveUser)).Queries("accessKey", "{accessKey:.*}")
|
2018-10-09 23:00:01 +02:00
|
|
|
|
2018-12-18 22:03:26 +01:00
|
|
|
// List users
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/list-users").HandlerFunc(httpTraceHdrs(adminAPI.ListUsers))
|
2018-10-13 09:18:43 +02:00
|
|
|
|
2019-08-13 22:41:06 +02:00
|
|
|
// User info
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/user-info").HandlerFunc(httpTraceHdrs(adminAPI.GetUserInfo)).Queries("accessKey", "{accessKey:.*}")
|
2019-08-13 22:41:06 +02:00
|
|
|
|
2019-08-02 23:25:00 +02:00
|
|
|
// Add/Remove members from group
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix + "/update-group-members").HandlerFunc(httpTraceHdrs(adminAPI.UpdateGroupMembers))
|
2019-08-02 23:25:00 +02:00
|
|
|
|
|
|
|
// Get Group
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/group").HandlerFunc(httpTraceHdrs(adminAPI.GetGroup)).Queries("group", "{group:.*}")
|
2019-08-02 23:25:00 +02:00
|
|
|
|
|
|
|
// List Groups
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/groups").HandlerFunc(httpTraceHdrs(adminAPI.ListGroups))
|
2019-08-02 23:25:00 +02:00
|
|
|
|
|
|
|
// Set Group Status
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/set-group-status").HandlerFunc(httpTraceHdrs(adminAPI.SetGroupStatus)).Queries("group", "{group:.*}").Queries("status", "{status:.*}")
|
2019-08-02 23:25:00 +02:00
|
|
|
|
2018-12-18 22:03:26 +01:00
|
|
|
// List policies
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/list-canned-policies").HandlerFunc(httpTraceHdrs(adminAPI.ListCannedPolicies))
|
2018-12-18 22:03:26 +01:00
|
|
|
}
|
2018-10-18 02:25:16 +02:00
|
|
|
|
2019-01-24 16:22:14 +01:00
|
|
|
// -- Top APIs --
|
|
|
|
// Top locks
|
2019-11-04 18:30:59 +01:00
|
|
|
if globalIsDistXL {
|
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/top/locks").HandlerFunc(httpTraceHdrs(adminAPI.TopLocksHandler))
|
|
|
|
}
|
2019-01-24 16:22:14 +01:00
|
|
|
|
2019-06-09 00:54:41 +02:00
|
|
|
// HTTP Trace
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/trace").HandlerFunc(adminAPI.TraceHandler)
|
2019-09-04 22:19:44 +02:00
|
|
|
|
2019-09-03 20:10:48 +02:00
|
|
|
// Console Logs
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/log").HandlerFunc(httpTraceAll(adminAPI.ConsoleLogHandler))
|
2019-09-03 20:10:48 +02:00
|
|
|
|
2019-09-04 22:19:44 +02:00
|
|
|
// -- KMS APIs --
|
|
|
|
//
|
2019-11-04 18:30:59 +01:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/kms/key/status").HandlerFunc(httpTraceAll(adminAPI.KMSKeyStatusHandler))
|
2019-09-04 22:19:44 +02:00
|
|
|
|
2019-11-04 18:30:59 +01:00
|
|
|
// If none of the routes match add default error handler routes
|
|
|
|
adminRouter.NotFoundHandler = http.HandlerFunc(httpTraceAll(errorResponseHandler))
|
|
|
|
adminRouter.MethodNotAllowedHandler = http.HandlerFunc(httpTraceAll(errorResponseHandler))
|
2016-12-16 07:26:15 +01:00
|
|
|
}
|