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-04-21 22:23:54 -04:00
|
|
|
func registerAdminRouter(router *mux.Router) {
|
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))
|
|
|
|
}
|
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-01-22 17:54:55 -05:00
|
|
|
// Update credentials
|
2018-10-09 17:00:01 -04:00
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/config/credential").HandlerFunc(httpTraceHdrs(adminAPI.UpdateAdminCredentialsHandler))
|
2017-02-20 15:58:50 -05:00
|
|
|
// Get config
|
2018-08-17 21:51:34 -04:00
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/config").HandlerFunc(httpTraceHdrs(adminAPI.GetConfigHandler))
|
2018-01-22 17:54:55 -05:00
|
|
|
// Set config
|
2018-08-17 21:51:34 -04:00
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/config").HandlerFunc(httpTraceHdrs(adminAPI.SetConfigHandler))
|
2018-09-06 11:03:18 -04: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-10-13 03:18:43 -04:00
|
|
|
// -- IAM APIs --
|
|
|
|
|
2018-10-16 15:48:19 -04:00
|
|
|
// Add policy IAM
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/add-canned-policy").HandlerFunc(httpTraceHdrs(adminAPI.AddCannedPolicy)).Queries("name", "{name:.*}")
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
// Add user IAM
|
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/add-user").HandlerFunc(httpTraceHdrs(adminAPI.AddUser)).Queries("accessKey", "{accessKey:.*}")
|
2018-10-16 15:48:19 -04:00
|
|
|
adminV1Router.Methods(http.MethodPut).Path("/set-user-policy").HandlerFunc(httpTraceHdrs(adminAPI.SetUserPolicy)).
|
|
|
|
Queries("accessKey", "{accessKey:.*}").Queries("name", "{name:.*}")
|
2018-10-16 17:55:23 -04:00
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// Remove user IAM
|
|
|
|
adminV1Router.Methods(http.MethodDelete).Path("/remove-user").HandlerFunc(httpTraceHdrs(adminAPI.RemoveUser)).Queries("accessKey", "{accessKey:.*}")
|
|
|
|
|
2018-10-13 03:18:43 -04:00
|
|
|
// List users
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/list-users").HandlerFunc(httpTraceHdrs(adminAPI.ListUsers))
|
|
|
|
|
2018-10-16 15:48:19 -04:00
|
|
|
// List policies
|
|
|
|
adminV1Router.Methods(http.MethodGet).Path("/list-canned-policies").HandlerFunc(httpTraceHdrs(adminAPI.ListCannedPolicies))
|
2018-10-17 20:25:16 -04:00
|
|
|
|
|
|
|
// If none of the routes match.
|
|
|
|
adminV1Router.NotFoundHandler = http.HandlerFunc(httpTraceHdrs(notFoundHandler))
|
2016-12-16 01:26:15 -05:00
|
|
|
}
|