2016-12-16 01:26:15 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
// adminAPIHandlers provides HTTP handlers for Minio admin API.
|
|
|
|
type adminAPIHandlers struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// registerAdminRouter - Add handler functions for each service REST API routes.
|
2018-12-18 16:03:26 -05:00
|
|
|
func registerAdminRouter(router *mux.Router, enableIAM 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
|
2018-06-07 13:41:13 -04:00
|
|
|
adminRouter.Methods(http.MethodGet).Path("/version").HandlerFunc(httpTraceAll(adminAPI.VersionHandler))
|
2018-01-22 17:54:55 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Service status
|
2018-06-07 13:41:13 -04:00
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/service").HandlerFunc(httpTraceAll(adminAPI.ServiceStatusHandler))
|
2017-01-14 17:48:52 -05:00
|
|
|
|
2018-01-22 17:54:55 -05:00
|
|
|
// Service restart and stop - TODO
|
2018-06-07 13:41:13 -04:00
|
|
|
adminV1Router.Methods(http.MethodPost).Path("/service").HandlerFunc(httpTraceAll(adminAPI.ServiceStopNRestartHandler))
|
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
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
2018-12-18 16:03:26 -05:00
|
|
|
if enableIAM {
|
|
|
|
// Update credentials
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/config/credential").HandlerFunc(httpTraceHdrs(adminAPI.UpdateAdminCredentialsHandler))
|
|
|
|
// 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))
|
2018-10-09 17:00:01 -04:00
|
|
|
|
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
|
|
|
|
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-policy").HandlerFunc(httpTraceHdrs(adminAPI.SetUserPolicy)).
|
|
|
|
Queries("accessKey", "{accessKey:.*}").Queries("name", "{name:.*}")
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|