2016-12-16 01:26:15 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016, 2017, 2018, 2019 MinIO, Inc.
|
2016-12-16 01:26:15 -05: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 17:54:55 -05:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-04-21 22:23:54 -04:00
|
|
|
"github.com/gorilla/mux"
|
2019-10-23 00:01:14 -04:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2018-01-22 17:54:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-11-04 12:30:59 -05:00
|
|
|
adminPathPrefix = minioReservedBucketPath + "/admin"
|
|
|
|
adminAPIVersion = madmin.AdminAPIVersion
|
|
|
|
adminAPIVersionPrefix = SlashSeparator + madmin.AdminAPIVersion
|
2018-01-22 17:54:55 -05:00
|
|
|
)
|
2016-12-16 01:26:15 -05:00
|
|
|
|
2019-04-09 14:39:42 -04:00
|
|
|
// adminAPIHandlers provides HTTP handlers for MinIO admin API.
|
2019-11-04 12:30:59 -05:00
|
|
|
type adminAPIHandlers struct{}
|
2016-12-16 01:26:15 -05:00
|
|
|
|
|
|
|
// registerAdminRouter - Add handler functions for each service REST API routes.
|
2019-01-23 14:10:59 -05:00
|
|
|
func registerAdminRouter(router *mux.Router, enableConfigOps, enableIAMOps bool) {
|
2016-12-16 01:26:15 -05:00
|
|
|
|
|
|
|
adminAPI := adminAPIHandlers{}
|
|
|
|
// Admin router
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter := router.PathPrefix(adminPathPrefix).Subrouter()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
2017-01-04 02:39:22 -05:00
|
|
|
/// Service operations
|
2016-12-16 01:26:15 -05:00
|
|
|
|
2019-08-28 18:04:43 -04:00
|
|
|
// Restart and stop MinIO service.
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix+"/service").HandlerFunc(httpTraceAll(adminAPI.ServiceActionHandler)).Queries("action", "{action:.*}")
|
2019-08-28 18:04:43 -04:00
|
|
|
// Update MinIO servers.
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix+"/update").HandlerFunc(httpTraceAll(adminAPI.ServerUpdateHandler)).Queries("updateURL", "{updateURL:.*}")
|
2017-01-04 02:39:22 -05:00
|
|
|
|
2017-02-15 13:45:45 -05:00
|
|
|
// Info operations
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/info").HandlerFunc(httpTraceAll(adminAPI.ServerInfoHandler))
|
2019-10-03 10:48:38 -04:00
|
|
|
// Harware Info operations
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/hardware").HandlerFunc(httpTraceAll(adminAPI.ServerHardwareInfoHandler)).Queries("hwType", "{hwType:.*}")
|
2019-10-23 00:01:14 -04:00
|
|
|
|
|
|
|
// StorageInfo operations
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/storageinfo").HandlerFunc(httpTraceAll(adminAPI.StorageInfoHandler))
|
2017-02-15 13:45:45 -05:00
|
|
|
|
2018-10-17 20:25:16 -04:00
|
|
|
if globalIsDistXL || globalIsXL {
|
|
|
|
/// Heal operations
|
2017-01-17 13:02:58 -05:00
|
|
|
|
2018-10-17 20:25:16 -04:00
|
|
|
// Heal processing endpoint.
|
2019-11-04 12:30:59 -05: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 12:46:44 -05:00
|
|
|
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix + "/background-heal/status").HandlerFunc(httpTraceAll(adminAPI.BackgroundHealStatusHandler))
|
2019-06-25 19:42:24 -04:00
|
|
|
|
2018-12-31 12:46:44 -05:00
|
|
|
/// Health operations
|
|
|
|
|
2018-10-17 20:25:16 -04:00
|
|
|
}
|
2019-01-09 22:04:19 -05:00
|
|
|
// Performance command - return performance details based on input type
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/performance").HandlerFunc(httpTraceAll(adminAPI.PerfInfoHandler)).Queries("perfType", "{perfType:.*}")
|
2017-02-20 15:58:50 -05:00
|
|
|
|
2018-09-18 19:46:35 -04:00
|
|
|
// Profiling operations
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPost).Path(adminAPIVersionPrefix+"/profiling/start").HandlerFunc(httpTraceAll(adminAPI.StartProfilingHandler)).
|
2018-09-27 00:02:05 -04:00
|
|
|
Queries("profilerType", "{profilerType:.*}")
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/profiling/download").HandlerFunc(httpTraceAll(adminAPI.DownloadProfilingHandler))
|
2018-09-18 19:46:35 -04:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
// Config KV operations.
|
|
|
|
if enableConfigOps {
|
2019-11-04 12:30:59 -05: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 09:18:26 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/list-config-history-kv").HandlerFunc(httpTraceAll(adminAPI.ListConfigHistoryKVHandler)).Queries("count", "{count:[0-9]+}")
|
2019-11-04 12:30:59 -05: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 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
2017-02-20 15:58:50 -05:00
|
|
|
/// Config operations
|
2019-01-23 14:10:59 -05:00
|
|
|
if enableConfigOps {
|
2018-12-18 16:03:26 -05:00
|
|
|
// Get config
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/config").HandlerFunc(httpTraceHdrs(adminAPI.GetConfigHandler))
|
2018-12-18 16:03:26 -05:00
|
|
|
// Set config
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix + "/config").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigHandler))
|
2019-01-23 14:10:59 -05:00
|
|
|
}
|
2018-10-09 17:00:01 -04:00
|
|
|
|
2019-01-23 14:10:59 -05:00
|
|
|
if enableIAMOps {
|
2018-12-18 16:03:26 -05:00
|
|
|
// -- IAM APIs --
|
2018-10-13 03:18:43 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Add policy IAM
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/add-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.AddCannedPolicy)).Queries("name",
|
2019-01-23 14:10:59 -05:00
|
|
|
"{name:.*}")
|
2018-10-16 15:48:19 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Add user IAM
|
2019-11-04 12:30:59 -05: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 16:03:26 -05:00
|
|
|
Queries("accessKey", "{accessKey:.*}").Queries("status", "{status:.*}")
|
2018-10-16 15:48:19 -04:00
|
|
|
|
2019-09-26 14:23:13 -04:00
|
|
|
// Info policy IAM
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/info-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.InfoCannedPolicy)).Queries("name", "{name:.*}")
|
2019-09-26 14:23:13 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Remove policy IAM
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix+"/remove-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.RemoveCannedPolicy)).Queries("name", "{name:.*}")
|
2018-10-09 17:00:01 -04:00
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// Set user or group policy
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/set-user-or-group-policy").
|
2019-08-13 16:41:06 -04:00
|
|
|
HandlerFunc(httpTraceHdrs(adminAPI.SetPolicyForUserOrGroup)).
|
|
|
|
Queries("policyName", "{policyName:.*}", "userOrGroup", "{userOrGroup:.*}", "isGroup", "{isGroup:true|false}")
|
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Remove user IAM
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodDelete).Path(adminAPIVersionPrefix+"/remove-user").HandlerFunc(httpTraceHdrs(adminAPI.RemoveUser)).Queries("accessKey", "{accessKey:.*}")
|
2018-10-09 17:00:01 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// List users
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/list-users").HandlerFunc(httpTraceHdrs(adminAPI.ListUsers))
|
2018-10-13 03:18:43 -04:00
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// User info
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/user-info").HandlerFunc(httpTraceHdrs(adminAPI.GetUserInfo)).Queries("accessKey", "{accessKey:.*}")
|
2019-08-13 16:41:06 -04:00
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// Add/Remove members from group
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix + "/update-group-members").HandlerFunc(httpTraceHdrs(adminAPI.UpdateGroupMembers))
|
2019-08-02 17:25:00 -04:00
|
|
|
|
|
|
|
// Get Group
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix+"/group").HandlerFunc(httpTraceHdrs(adminAPI.GetGroup)).Queries("group", "{group:.*}")
|
2019-08-02 17:25:00 -04:00
|
|
|
|
|
|
|
// List Groups
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/groups").HandlerFunc(httpTraceHdrs(adminAPI.ListGroups))
|
2019-08-02 17:25:00 -04:00
|
|
|
|
|
|
|
// Set Group Status
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodPut).Path(adminAPIVersionPrefix+"/set-group-status").HandlerFunc(httpTraceHdrs(adminAPI.SetGroupStatus)).Queries("group", "{group:.*}").Queries("status", "{status:.*}")
|
2019-08-02 17:25:00 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// List policies
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/list-canned-policies").HandlerFunc(httpTraceHdrs(adminAPI.ListCannedPolicies))
|
2018-12-18 16:03:26 -05:00
|
|
|
}
|
2018-10-17 20:25:16 -04:00
|
|
|
|
2019-01-24 10:22:14 -05:00
|
|
|
// -- Top APIs --
|
|
|
|
// Top locks
|
2019-11-04 12:30:59 -05:00
|
|
|
if globalIsDistXL {
|
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/top/locks").HandlerFunc(httpTraceHdrs(adminAPI.TopLocksHandler))
|
|
|
|
}
|
2019-01-24 10:22:14 -05:00
|
|
|
|
2019-06-08 18:54:41 -04:00
|
|
|
// HTTP Trace
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/trace").HandlerFunc(adminAPI.TraceHandler)
|
2019-09-04 16:19:44 -04:00
|
|
|
|
2019-09-03 14:10:48 -04:00
|
|
|
// Console Logs
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/log").HandlerFunc(httpTraceAll(adminAPI.ConsoleLogHandler))
|
2019-09-03 14:10:48 -04:00
|
|
|
|
2019-09-04 16:19:44 -04:00
|
|
|
// -- KMS APIs --
|
|
|
|
//
|
2019-11-04 12:30:59 -05:00
|
|
|
adminRouter.Methods(http.MethodGet).Path(adminAPIVersionPrefix + "/kms/key/status").HandlerFunc(httpTraceAll(adminAPI.KMSKeyStatusHandler))
|
2019-09-04 16:19:44 -04:00
|
|
|
|
2019-11-04 12:30:59 -05: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 01:26:15 -05:00
|
|
|
}
|