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"
|
2018-01-22 17:54:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
adminAPIPathPrefix = "/minio/admin"
|
|
|
|
)
|
2016-12-16 01:26:15 -05:00
|
|
|
|
2019-04-09 14:39:42 -04:00
|
|
|
// adminAPIHandlers provides HTTP handlers for MinIO admin API.
|
2016-12-16 01:26:15 -05:00
|
|
|
type adminAPIHandlers struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2018-04-21 22:23:54 -04:00
|
|
|
adminRouter := router.PathPrefix(adminAPIPathPrefix).Subrouter()
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
// Version handler
|
|
|
|
adminV1Router := adminRouter.PathPrefix("/v1").Subrouter()
|
2016-12-16 01:26:15 -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-08-27 14:37:47 -04:00
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/service").HandlerFunc(httpTraceAll(adminAPI.ServiceActionHandler)).Queries("action", "{action:.*}")
|
2019-08-28 18:04:43 -04:00
|
|
|
// Update MinIO servers.
|
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/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
|
2018-06-07 13:41:13 -04:00
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/info").HandlerFunc(httpTraceAll(adminAPI.ServerInfoHandler))
|
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.
|
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/heal/").HandlerFunc(httpTraceAll(adminAPI.HealHandler))
|
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/heal/{bucket}").HandlerFunc(httpTraceAll(adminAPI.HealHandler))
|
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/heal/{bucket}/{prefix:.*}").HandlerFunc(httpTraceAll(adminAPI.HealHandler))
|
2018-12-31 12:46:44 -05:00
|
|
|
|
2019-06-25 19:42:24 -04:00
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/background-heal/status").HandlerFunc(httpTraceAll(adminAPI.BackgroundHealStatusHandler))
|
|
|
|
|
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
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/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
|
2018-09-27 00:02:05 -04:00
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/profiling/start").HandlerFunc(httpTraceAll(adminAPI.StartProfilingHandler)).
|
|
|
|
Queries("profilerType", "{profilerType:.*}")
|
2018-09-18 19:46:35 -04:00
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/profiling/download").HandlerFunc(httpTraceAll(adminAPI.DownloadProfilingHandler))
|
|
|
|
|
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
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/config").HandlerFunc(httpTraceHdrs(adminAPI.GetConfigHandler))
|
|
|
|
// Set config
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/config").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigHandler))
|
2018-09-06 11:03:18 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Get config keys/values
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/config-keys").HandlerFunc(httpTraceHdrs(adminAPI.GetConfigKeysHandler))
|
|
|
|
// Set config keys/values
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/config-keys").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigKeysHandler))
|
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-01-23 14:10:59 -05:00
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/add-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.AddCannedPolicy)).Queries("name",
|
|
|
|
"{name:.*}")
|
2018-10-16 15:48:19 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Add user IAM
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/add-user").HandlerFunc(httpTraceHdrs(adminAPI.AddUser)).Queries("accessKey", "{accessKey:.*}")
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/set-user-status").HandlerFunc(httpTraceHdrs(adminAPI.SetUserStatus)).
|
|
|
|
Queries("accessKey", "{accessKey:.*}").Queries("status", "{status:.*}")
|
2018-10-16 15:48:19 -04:00
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Remove policy IAM
|
|
|
|
adminV1Router.Methods(http.MethodDelete).Path("/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
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/set-user-or-group-policy").
|
|
|
|
HandlerFunc(httpTraceHdrs(adminAPI.SetPolicyForUserOrGroup)).
|
|
|
|
Queries("policyName", "{policyName:.*}", "userOrGroup", "{userOrGroup:.*}", "isGroup", "{isGroup:true|false}")
|
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// Remove user IAM
|
|
|
|
adminV1Router.Methods(http.MethodDelete).Path("/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
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/list-users").HandlerFunc(httpTraceHdrs(adminAPI.ListUsers))
|
2018-10-13 03:18:43 -04:00
|
|
|
|
2019-08-13 16:41:06 -04:00
|
|
|
// User info
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/user-info").HandlerFunc(httpTraceHdrs(adminAPI.GetUserInfo)).Queries("accessKey", "{accessKey:.*}")
|
|
|
|
|
2019-08-02 17:25:00 -04:00
|
|
|
// Add/Remove members from group
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/update-group-members").HandlerFunc(httpTraceHdrs(adminAPI.UpdateGroupMembers))
|
|
|
|
|
|
|
|
// Get Group
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/group").HandlerFunc(httpTraceHdrs(adminAPI.GetGroup)).Queries("group", "{group:.*}")
|
|
|
|
|
|
|
|
// List Groups
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/groups").HandlerFunc(httpTraceHdrs(adminAPI.ListGroups))
|
|
|
|
|
|
|
|
// Set Group Status
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/set-group-status").HandlerFunc(httpTraceHdrs(adminAPI.SetGroupStatus)).Queries("group", "{group:.*}").Queries("status", "{status:.*}")
|
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
// List policies
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/list-canned-policies").HandlerFunc(httpTraceHdrs(adminAPI.ListCannedPolicies))
|
|
|
|
}
|
2018-10-17 20:25:16 -04:00
|
|
|
|
2019-01-24 10:22:14 -05:00
|
|
|
// -- Top APIs --
|
|
|
|
// Top locks
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/top/locks").HandlerFunc(httpTraceHdrs(adminAPI.TopLocksHandler))
|
|
|
|
|
2019-06-08 18:54:41 -04:00
|
|
|
// HTTP Trace
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/trace").HandlerFunc(adminAPI.TraceHandler)
|
2018-12-18 16:03:26 -05:00
|
|
|
// If none of the routes match, return error.
|
|
|
|
adminV1Router.NotFoundHandler = http.HandlerFunc(httpTraceHdrs(notFoundHandlerJSON))
|
2016-12-16 01:26:15 -05:00
|
|
|
}
|