mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
Add madmin package context support (#9172)
This is to improve responsiveness for all admin API operations and allowing callers to cancel any on-going admin operations, if they happen to be waiting too long.
This commit is contained in:
parent
1ffa983a9d
commit
ae654831aa
@ -1436,7 +1436,7 @@ func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Reque
|
|||||||
OffDisks += v
|
OffDisks += v
|
||||||
}
|
}
|
||||||
|
|
||||||
backend = madmin.XlBackend{
|
backend = madmin.XLBackend{
|
||||||
Type: madmin.ErasureType,
|
Type: madmin.ErasureType,
|
||||||
OnlineDisks: OnDisks,
|
OnlineDisks: OnDisks,
|
||||||
OfflineDisks: OffDisks,
|
OfflineDisks: OffDisks,
|
||||||
@ -1446,7 +1446,7 @@ func (a adminAPIHandlers) ServerInfoHandler(w http.ResponseWriter, r *http.Reque
|
|||||||
RRSCParity: storageInfo.Backend.RRSCParity,
|
RRSCParity: storageInfo.Backend.RRSCParity,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
backend = madmin.FsBackend{
|
backend = madmin.FSBackend{
|
||||||
Type: madmin.FsType,
|
Type: madmin.FsType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,12 +118,12 @@ func (sys *HTTPConsoleLoggerSys) Subscribe(subCh chan interface{}, doneCh chan s
|
|||||||
// Send log message 'e' to console and publish to console
|
// Send log message 'e' to console and publish to console
|
||||||
// log pubsub system
|
// log pubsub system
|
||||||
func (sys *HTTPConsoleLoggerSys) Send(e interface{}, logKind string) error {
|
func (sys *HTTPConsoleLoggerSys) Send(e interface{}, logKind string) error {
|
||||||
var lg madmin.LogInfo
|
var lg log.Info
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case log.Entry:
|
case log.Entry:
|
||||||
lg = madmin.LogInfo{Entry: e, NodeName: sys.nodeName}
|
lg = log.Info{Entry: e, NodeName: sys.nodeName}
|
||||||
case string:
|
case string:
|
||||||
lg = madmin.LogInfo{ConsoleMsg: e, NodeName: sys.nodeName}
|
lg = log.Info{ConsoleMsg: e, NodeName: sys.nodeName}
|
||||||
}
|
}
|
||||||
|
|
||||||
sys.pubsub.Publish(lg)
|
sys.pubsub.Publish(lg)
|
||||||
|
@ -50,3 +50,11 @@ type Entry struct {
|
|||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Trace *Trace `json:"error,omitempty"`
|
Trace *Trace `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Info holds console log messages
|
||||||
|
type Info struct {
|
||||||
|
Entry
|
||||||
|
ConsoleMsg string
|
||||||
|
NodeName string `json:"node"`
|
||||||
|
Err error `json:"-"`
|
||||||
|
}
|
||||||
|
52
pkg/madmin/api-log-entry.go
Normal file
52
pkg/madmin/api-log-entry.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Cloud Storage, (C) 2020 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 madmin
|
||||||
|
|
||||||
|
// Args - defines the arguments for the API.
|
||||||
|
type logArgs struct {
|
||||||
|
Bucket string `json:"bucket,omitempty"`
|
||||||
|
Object string `json:"object,omitempty"`
|
||||||
|
Metadata map[string]string `json:"metadata,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trace - defines the trace.
|
||||||
|
type logTrace struct {
|
||||||
|
Message string `json:"message,omitempty"`
|
||||||
|
Source []string `json:"source,omitempty"`
|
||||||
|
Variables map[string]string `json:"variables,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// API - defines the api type and its args.
|
||||||
|
type logAPI struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Args *logArgs `json:"args,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Entry - defines fields and values of each log entry.
|
||||||
|
type logEntry struct {
|
||||||
|
DeploymentID string `json:"deploymentid,omitempty"`
|
||||||
|
Level string `json:"level"`
|
||||||
|
LogKind string `json:"errKind"`
|
||||||
|
Time string `json:"time"`
|
||||||
|
API *logAPI `json:"api,omitempty"`
|
||||||
|
RemoteHost string `json:"remotehost,omitempty"`
|
||||||
|
Host string `json:"host,omitempty"`
|
||||||
|
RequestID string `json:"requestID,omitempty"`
|
||||||
|
UserAgent string `json:"userAgent,omitempty"`
|
||||||
|
Message string `json:"message,omitempty"`
|
||||||
|
Trace *logTrace `json:"error,omitempty"`
|
||||||
|
}
|
@ -17,18 +17,17 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/minio/minio/cmd/logger/message/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LogInfo holds console log messages
|
// LogInfo holds console log messages
|
||||||
type LogInfo struct {
|
type LogInfo struct {
|
||||||
log.Entry
|
logEntry
|
||||||
ConsoleMsg string
|
ConsoleMsg string
|
||||||
NodeName string `json:"node"`
|
NodeName string `json:"node"`
|
||||||
Err error `json:"-"`
|
Err error `json:"-"`
|
||||||
@ -42,7 +41,7 @@ func (l LogInfo) SendLog(node, logKind string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLogs - listen on console log messages.
|
// GetLogs - listen on console log messages.
|
||||||
func (adm AdminClient) GetLogs(node string, lineCnt int, logKind string, doneCh <-chan struct{}) <-chan LogInfo {
|
func (adm AdminClient) GetLogs(ctx context.Context, node string, lineCnt int, logKind string) <-chan LogInfo {
|
||||||
logCh := make(chan LogInfo, 1)
|
logCh := make(chan LogInfo, 1)
|
||||||
|
|
||||||
// Only success, start a routine to start reading line by line.
|
// Only success, start a routine to start reading line by line.
|
||||||
@ -58,7 +57,7 @@ func (adm AdminClient) GetLogs(node string, lineCnt int, logKind string, doneCh
|
|||||||
queryValues: urlValues,
|
queryValues: urlValues,
|
||||||
}
|
}
|
||||||
// Execute GET to call log handler
|
// Execute GET to call log handler
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closeResponse(resp)
|
closeResponse(resp)
|
||||||
return
|
return
|
||||||
@ -75,7 +74,7 @@ func (adm AdminClient) GetLogs(node string, lineCnt int, logKind string, doneCh
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-doneCh:
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case logCh <- info:
|
case logCh <- info:
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,9 @@ package madmin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -109,7 +111,7 @@ func privateNew(endpoint, accessKeyID, secretAccessKey string, secure bool) (*Ad
|
|||||||
endpointURL: *endpointURL,
|
endpointURL: *endpointURL,
|
||||||
// Instantiate http client and bucket location cache.
|
// Instantiate http client and bucket location cache.
|
||||||
httpClient: &http.Client{
|
httpClient: &http.Client{
|
||||||
Transport: http.DefaultTransport,
|
Transport: DefaultTransport(secure),
|
||||||
},
|
},
|
||||||
// Introduce a new locked random seed.
|
// Introduce a new locked random seed.
|
||||||
random: rand.New(&lockedRandSource{src: rand.NewSource(time.Now().UTC().UnixNano())}),
|
random: rand.New(&lockedRandSource{src: rand.NewSource(time.Now().UTC().UnixNano())}),
|
||||||
@ -263,38 +265,19 @@ func (adm AdminClient) dumpHTTP(req *http.Request, resp *http.Response) error {
|
|||||||
|
|
||||||
// do - execute http request.
|
// do - execute http request.
|
||||||
func (adm AdminClient) do(req *http.Request) (*http.Response, error) {
|
func (adm AdminClient) do(req *http.Request) (*http.Response, error) {
|
||||||
var resp *http.Response
|
resp, err := adm.httpClient.Do(req)
|
||||||
var err error
|
if err != nil {
|
||||||
// Do the request in a loop in case of 307 http is met since golang still doesn't
|
// Handle this specifically for now until future Golang versions fix this issue properly.
|
||||||
// handle properly this situation (https://github.com/golang/go/issues/7912)
|
if urlErr, ok := err.(*url.Error); ok {
|
||||||
for {
|
if strings.Contains(urlErr.Err.Error(), "EOF") {
|
||||||
resp, err = adm.httpClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
// Close idle connections upon error.
|
|
||||||
adm.httpClient.CloseIdleConnections()
|
|
||||||
|
|
||||||
// Handle this specifically for now until future Golang
|
|
||||||
// versions fix this issue properly.
|
|
||||||
urlErr, ok := err.(*url.Error)
|
|
||||||
if ok && strings.Contains(urlErr.Err.Error(), "EOF") {
|
|
||||||
return nil, &url.Error{
|
return nil, &url.Error{
|
||||||
Op: urlErr.Op,
|
Op: urlErr.Op,
|
||||||
URL: urlErr.URL,
|
URL: urlErr.URL,
|
||||||
Err: fmt.Errorf("Connection closed by foreign host %s", urlErr.URL),
|
Err: errors.New("Connection closed by foreign host " + urlErr.URL + ". Retry again."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// Redo the request with the new redirect url if http 307 is returned, quit the loop otherwise
|
|
||||||
if resp != nil && resp.StatusCode == http.StatusTemporaryRedirect {
|
|
||||||
newURL, uErr := url.Parse(resp.Header.Get("Location"))
|
|
||||||
if uErr != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
req.URL = newURL
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response cannot be non-nil, report if its the case.
|
// Response cannot be non-nil, report if its the case.
|
||||||
@ -323,16 +306,23 @@ var successStatus = []int{
|
|||||||
// executeMethod - instantiates a given method, and retries the
|
// executeMethod - instantiates a given method, and retries the
|
||||||
// request upon any error up to maxRetries attempts in a binomially
|
// request upon any error up to maxRetries attempts in a binomially
|
||||||
// delayed manner using a standard back off algorithm.
|
// delayed manner using a standard back off algorithm.
|
||||||
func (adm AdminClient) executeMethod(method string, reqData requestData) (res *http.Response, err error) {
|
func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData requestData) (res *http.Response, err error) {
|
||||||
var reqRetry = MaxRetry // Indicates how many times we can retry the request
|
var reqRetry = MaxRetry // Indicates how many times we can retry the request
|
||||||
|
|
||||||
// Create a done channel to control 'ListObjects' go routine.
|
defer func() {
|
||||||
doneCh := make(chan struct{}, 1)
|
if err != nil {
|
||||||
|
// close idle connections before returning, upon error.
|
||||||
|
adm.httpClient.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Create cancel context to control 'newRetryTimer' go routine.
|
||||||
|
retryCtx, cancel := context.WithCancel(ctx)
|
||||||
|
|
||||||
// Indicate to our routine to exit cleanly upon return.
|
// Indicate to our routine to exit cleanly upon return.
|
||||||
defer close(doneCh)
|
defer cancel()
|
||||||
|
|
||||||
for range adm.newRetryTimer(reqRetry, DefaultRetryUnit, DefaultRetryCap, MaxJitter, doneCh) {
|
for range adm.newRetryTimer(retryCtx, reqRetry, DefaultRetryUnit, DefaultRetryCap, MaxJitter) {
|
||||||
// Instantiate a new request.
|
// Instantiate a new request.
|
||||||
var req *http.Request
|
var req *http.Request
|
||||||
req, err = adm.newRequest(method, reqData)
|
req, err = adm.newRequest(method, reqData)
|
||||||
@ -340,6 +330,9 @@ func (adm AdminClient) executeMethod(method string, reqData requestData) (res *h
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add context to request
|
||||||
|
req = req.WithContext(ctx)
|
||||||
|
|
||||||
// Initiate the request.
|
// Initiate the request.
|
||||||
res, err = adm.do(req)
|
res, err = adm.do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -19,14 +19,16 @@ package madmin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetConfig - returns the config.json of a minio setup, incoming data is encrypted.
|
// GetConfig - returns the config.json of a minio setup, incoming data is encrypted.
|
||||||
func (adm *AdminClient) GetConfig() ([]byte, error) {
|
func (adm *AdminClient) GetConfig(ctx context.Context) ([]byte, error) {
|
||||||
// Execute GET on /minio/admin/v2/config to get config of a setup.
|
// Execute GET on /minio/admin/v2/config to get config of a setup.
|
||||||
resp, err := adm.executeMethod(http.MethodGet,
|
resp, err := adm.executeMethod(ctx,
|
||||||
|
http.MethodGet,
|
||||||
requestData{relPath: adminAPIPrefix + "/config"})
|
requestData{relPath: adminAPIPrefix + "/config"})
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -41,7 +43,7 @@ func (adm *AdminClient) GetConfig() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetConfig - set config supplied as config.json for the setup.
|
// SetConfig - set config supplied as config.json for the setup.
|
||||||
func (adm *AdminClient) SetConfig(config io.Reader) (err error) {
|
func (adm *AdminClient) SetConfig(ctx context.Context, config io.Reader) (err error) {
|
||||||
const maxConfigJSONSize = 256 * 1024 // 256KiB
|
const maxConfigJSONSize = 256 * 1024 // 256KiB
|
||||||
|
|
||||||
// Read configuration bytes
|
// Read configuration bytes
|
||||||
@ -65,7 +67,7 @@ func (adm *AdminClient) SetConfig(config io.Reader) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/config to set config.
|
// Execute PUT on /minio/admin/v2/config to set config.
|
||||||
resp, err := adm.executeMethod(http.MethodPut, reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -45,7 +46,7 @@ type HelpKV struct {
|
|||||||
type HelpKVS []HelpKV
|
type HelpKVS []HelpKV
|
||||||
|
|
||||||
// HelpConfigKV - return help for a given sub-system.
|
// HelpConfigKV - return help for a given sub-system.
|
||||||
func (adm *AdminClient) HelpConfigKV(subSys, key string, envOnly bool) (Help, error) {
|
func (adm *AdminClient) HelpConfigKV(ctx context.Context, subSys, key string, envOnly bool) (Help, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("subSys", subSys)
|
v.Set("subSys", subSys)
|
||||||
v.Set("key", key)
|
v.Set("key", key)
|
||||||
@ -59,7 +60,7 @@ func (adm *AdminClient) HelpConfigKV(subSys, key string, envOnly bool) (Help, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/help-config-kv
|
// Execute GET on /minio/admin/v2/help-config-kv
|
||||||
resp, err := adm.executeMethod(http.MethodGet, reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Help{}, err
|
return Help{}, err
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -28,7 +29,7 @@ import (
|
|||||||
// ClearConfigHistoryKV - clears the config entry represented by restoreID.
|
// ClearConfigHistoryKV - clears the config entry represented by restoreID.
|
||||||
// optionally allows setting `all` as a special keyword to automatically
|
// optionally allows setting `all` as a special keyword to automatically
|
||||||
// erase all config set history entires.
|
// erase all config set history entires.
|
||||||
func (adm *AdminClient) ClearConfigHistoryKV(restoreID string) (err error) {
|
func (adm *AdminClient) ClearConfigHistoryKV(ctx context.Context, restoreID string) (err error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("restoreId", restoreID)
|
v.Set("restoreId", restoreID)
|
||||||
reqData := requestData{
|
reqData := requestData{
|
||||||
@ -37,7 +38,7 @@ func (adm *AdminClient) ClearConfigHistoryKV(restoreID string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute DELETE on /minio/admin/v2/clear-config-history-kv
|
// Execute DELETE on /minio/admin/v2/clear-config-history-kv
|
||||||
resp, err := adm.executeMethod(http.MethodDelete, reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,7 +54,7 @@ func (adm *AdminClient) ClearConfigHistoryKV(restoreID string) (err error) {
|
|||||||
|
|
||||||
// RestoreConfigHistoryKV - Restore a previous config set history.
|
// RestoreConfigHistoryKV - Restore a previous config set history.
|
||||||
// Input is a unique id which represents the previous setting.
|
// Input is a unique id which represents the previous setting.
|
||||||
func (adm *AdminClient) RestoreConfigHistoryKV(restoreID string) (err error) {
|
func (adm *AdminClient) RestoreConfigHistoryKV(ctx context.Context, restoreID string) (err error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("restoreId", restoreID)
|
v.Set("restoreId", restoreID)
|
||||||
reqData := requestData{
|
reqData := requestData{
|
||||||
@ -62,7 +63,7 @@ func (adm *AdminClient) RestoreConfigHistoryKV(restoreID string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/set-config-kv to set config key/value.
|
// Execute PUT on /minio/admin/v2/set-config-kv to set config key/value.
|
||||||
resp, err := adm.executeMethod(http.MethodPut, reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,7 +91,7 @@ func (ch ConfigHistoryEntry) CreateTimeFormatted() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListConfigHistoryKV - lists a slice of ConfigHistoryEntries sorted by createTime.
|
// ListConfigHistoryKV - lists a slice of ConfigHistoryEntries sorted by createTime.
|
||||||
func (adm *AdminClient) ListConfigHistoryKV(count int) ([]ConfigHistoryEntry, error) {
|
func (adm *AdminClient) ListConfigHistoryKV(ctx context.Context, count int) ([]ConfigHistoryEntry, error) {
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
count = 10
|
count = 10
|
||||||
}
|
}
|
||||||
@ -98,7 +99,8 @@ func (adm *AdminClient) ListConfigHistoryKV(count int) ([]ConfigHistoryEntry, er
|
|||||||
v.Set("count", strconv.Itoa(count))
|
v.Set("count", strconv.Itoa(count))
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/list-config-history-kv
|
// Execute GET on /minio/admin/v2/list-config-history-kv
|
||||||
resp, err := adm.executeMethod(http.MethodGet,
|
resp, err := adm.executeMethod(ctx,
|
||||||
|
http.MethodGet,
|
||||||
requestData{
|
requestData{
|
||||||
relPath: adminAPIPrefix + "/list-config-history-kv",
|
relPath: adminAPIPrefix + "/list-config-history-kv",
|
||||||
queryValues: v,
|
queryValues: v,
|
||||||
|
@ -18,12 +18,13 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DelConfigKV - delete key from server config.
|
// DelConfigKV - delete key from server config.
|
||||||
func (adm *AdminClient) DelConfigKV(k string) (err error) {
|
func (adm *AdminClient) DelConfigKV(ctx context.Context, k string) (err error) {
|
||||||
econfigBytes, err := EncryptData(adm.secretAccessKey, []byte(k))
|
econfigBytes, err := EncryptData(adm.secretAccessKey, []byte(k))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -35,7 +36,7 @@ func (adm *AdminClient) DelConfigKV(k string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute DELETE on /minio/admin/v2/del-config-kv to delete config key.
|
// Execute DELETE on /minio/admin/v2/del-config-kv to delete config key.
|
||||||
resp, err := adm.executeMethod(http.MethodDelete, reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -50,7 +51,7 @@ func (adm *AdminClient) DelConfigKV(k string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetConfigKV - set key value config to server.
|
// SetConfigKV - set key value config to server.
|
||||||
func (adm *AdminClient) SetConfigKV(kv string) (err error) {
|
func (adm *AdminClient) SetConfigKV(ctx context.Context, kv string) (err error) {
|
||||||
econfigBytes, err := EncryptData(adm.secretAccessKey, []byte(kv))
|
econfigBytes, err := EncryptData(adm.secretAccessKey, []byte(kv))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -62,7 +63,7 @@ func (adm *AdminClient) SetConfigKV(kv string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/set-config-kv to set config key/value.
|
// Execute PUT on /minio/admin/v2/set-config-kv to set config key/value.
|
||||||
resp, err := adm.executeMethod(http.MethodPut, reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -77,12 +78,13 @@ func (adm *AdminClient) SetConfigKV(kv string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetConfigKV - returns the key, value of the requested key, incoming data is encrypted.
|
// GetConfigKV - returns the key, value of the requested key, incoming data is encrypted.
|
||||||
func (adm *AdminClient) GetConfigKV(key string) (Targets, error) {
|
func (adm *AdminClient) GetConfigKV(ctx context.Context, key string) (Targets, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("key", key)
|
v.Set("key", key)
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/get-config-kv?key={key} to get value of key.
|
// Execute GET on /minio/admin/v2/get-config-kv?key={key} to get value of key.
|
||||||
resp, err := adm.executeMethod(http.MethodGet,
|
resp, err := adm.executeMethod(ctx,
|
||||||
|
http.MethodGet,
|
||||||
requestData{
|
requestData{
|
||||||
relPath: adminAPIPrefix + "/get-config-kv",
|
relPath: adminAPIPrefix + "/get-config-kv",
|
||||||
queryValues: v,
|
queryValues: v,
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountingUsageInfo, err := madmClnt.AccountingUsageInfo()
|
accountingUsageInfo, err := madmClnt.AccountingUsageInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ func main() {
|
|||||||
// Create policy
|
// Create policy
|
||||||
policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::testbucket/*"],"Sid": ""}]}`
|
policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::testbucket/*"],"Sid": ""}]}`
|
||||||
|
|
||||||
creds, err := madmClnt.AddServiceAccount("parentuser", policy)
|
creds, err := madmClnt.AddServiceAccount(context.Background(), "parentuser", policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -39,18 +40,18 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = madmClnt.AddUser("newuser", "newstrongpassword"); err != nil {
|
if err = madmClnt.AddUser(context.Background(), "newuser", "newstrongpassword"); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create policy
|
// Create policy
|
||||||
policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}`
|
policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}`
|
||||||
|
|
||||||
if err = madmClnt.AddCannedPolicy("get-only", policy); err != nil {
|
if err = madmClnt.AddCannedPolicy(context.Background(), "get-only", policy); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = madmClnt.SetUserPolicy("newuser", "get-only"); err != nil {
|
if err = madmClnt.SetUserPolicy(context.Background(), "newuser", "get-only"); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := madmClnt.ServerCPULoadInfo()
|
st, err := madmClnt.ServerCPULoadInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataUsageInfo, err := madmClnt.DataUsageInfo()
|
dataUsageInfo, err := madmClnt.DataUsageInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := madmClnt.ServerDrivesPerfInfo(madmin.DefaultDrivePerfSize)
|
st, err := madmClnt.ServerDrivesPerfInfo(context.Background(), madmin.DefaultDrivePerfSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
creds, err := madmClnt.GetServiceAccount("service-account-access-key")
|
creds, err := madmClnt.GetServiceAccount(context.Background(), "service-account-access-key")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -38,7 +39,7 @@ func main() {
|
|||||||
|
|
||||||
// Heal bucket mybucket - dry run
|
// Heal bucket mybucket - dry run
|
||||||
isDryRun := true
|
isDryRun := true
|
||||||
err = madmClnt.HealBucket("mybucket", isDryRun)
|
err = madmClnt.HealBucket(context.Background(), "mybucket", isDryRun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ func main() {
|
|||||||
|
|
||||||
// Heal bucket mybucket - for real this time.
|
// Heal bucket mybucket - for real this time.
|
||||||
isDryRun := false
|
isDryRun := false
|
||||||
err = madmClnt.HealBucket("mybucket", isDryRun)
|
err = madmClnt.HealBucket(context.Background(), "mybucket", isDryRun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ package main
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// List buckets that need healing
|
// List buckets that need healing
|
||||||
healBucketsList, err := madmClnt.ListBucketsHeal()
|
healBucketsList, err := madmClnt.ListBucketsHeal(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -41,14 +42,14 @@ func main() {
|
|||||||
|
|
||||||
// Attempt healing format in dry-run mode.
|
// Attempt healing format in dry-run mode.
|
||||||
isDryRun := true
|
isDryRun := true
|
||||||
err = madmClnt.HealFormat(isDryRun)
|
err = madmClnt.HealFormat(context.Background(), isDryRun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform actual healing of format.
|
// Perform actual healing of format.
|
||||||
isDryRun = false
|
isDryRun = false
|
||||||
err = madmClnt.HealFormat(isDryRun)
|
err = madmClnt.HealFormat(context.Background(), isDryRun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -41,14 +42,14 @@ func main() {
|
|||||||
|
|
||||||
// Heal object mybucket/myobject - dry run.
|
// Heal object mybucket/myobject - dry run.
|
||||||
isDryRun := true
|
isDryRun := true
|
||||||
_, err = madmClnt.HealObject("mybucket", "myobject", isDryRun)
|
_, err = madmClnt.HealObject(context.Background(), "mybucket", "myobject", isDryRun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Heal object mybucket/myobject - this time for real.
|
// Heal object mybucket/myobject - this time for real.
|
||||||
isDryRun = false
|
isDryRun = false
|
||||||
healResult, err := madmClnt.HealObject("mybucket", "myobject", isDryRun)
|
healResult, err := madmClnt.HealObject(context.Background(), "mybucket", "myobject", isDryRun)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
healStatusResult, err := madmClnt.BackgroundHealStatus()
|
healStatusResult, err := madmClnt.BackgroundHealStatus(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -35,7 +36,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
st, err := madmClnt.ServerCPUHardwareInfo()
|
st, err := madmClnt.ServerCPUHardwareInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -35,7 +36,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
st, err := madmClnt.ServerNetworkHardwareInfo()
|
st, err := madmClnt.ServerNetworkHardwareInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := madmClnt.GetKeyStatus("") // empty string refers to the default master key
|
status, err := madmClnt.GetKeyStatus(context.Background(), "") // empty string refers to the default master key
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ func main() {
|
|||||||
|
|
||||||
// Clear locks held on mybucket/myprefix for longer than 30s.
|
// Clear locks held on mybucket/myprefix for longer than 30s.
|
||||||
olderThan := time.Duration(30 * time.Second)
|
olderThan := time.Duration(30 * time.Second)
|
||||||
locksCleared, err := madmClnt.ClearLocks("mybucket", "myprefix", olderThan)
|
locksCleared, err := madmClnt.ClearLocks(context.Background(), "mybucket", "myprefix", olderThan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := madmClnt.ServerMemUsageInfo()
|
st, err := madmClnt.ServerMemUsageInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := madmClnt.NetPerfInfo(madmin.DefaultNetPerfSize)
|
st, err := madmClnt.NetPerfInfo(context.Background(), madmin.DefaultNetPerfSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -45,7 +46,7 @@ func main() {
|
|||||||
profiler := madmin.ProfilerCPU
|
profiler := madmin.ProfilerCPU
|
||||||
log.Println("Starting " + profiler + " profiling..")
|
log.Println("Starting " + profiler + " profiling..")
|
||||||
|
|
||||||
startResults, err := madmClnt.StartProfiling(profiler)
|
startResults, err := madmClnt.StartProfiling(context.Background(), profiler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
@ -63,7 +64,7 @@ func main() {
|
|||||||
|
|
||||||
log.Println("Stopping profiling..")
|
log.Println("Stopping profiling..")
|
||||||
|
|
||||||
profilingData, err := madmClnt.DownloadProfilingData()
|
profilingData, err := madmClnt.DownloadProfilingData(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := madmClnt.ServerInfo()
|
st, err := madmClnt.ServerInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = madmClnt.ServiceRestart()
|
err = madmClnt.ServiceRestart(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ func main() {
|
|||||||
// in the minio cluster.
|
// in the minio cluster.
|
||||||
allTrace := false
|
allTrace := false
|
||||||
errTrace := false
|
errTrace := false
|
||||||
traceCh := madmClnt.ServiceTrace(allTrace, errTrace, doneCh)
|
traceCh := madmClnt.ServiceTrace(context.Background(), allTrace, errTrace, doneCh)
|
||||||
for traceInfo := range traceCh {
|
for traceInfo := range traceCh {
|
||||||
if traceInfo.Err != nil {
|
if traceInfo.Err != nil {
|
||||||
fmt.Println(traceInfo.Err)
|
fmt.Println(traceInfo.Err)
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/madmin"
|
"github.com/minio/minio/pkg/madmin"
|
||||||
@ -36,7 +37,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
st, err := madmClnt.StorageInfo()
|
st, err := madmClnt.StorageInfo(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ func main() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
locks, err := madmClnt.TopLocks()
|
locks, err := madmClnt.TopLocks(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed due to: %v", err)
|
log.Fatalf("failed due to: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -34,7 +35,7 @@ type GroupAddRemove struct {
|
|||||||
// UpdateGroupMembers - adds/removes users to/from a group. Server
|
// UpdateGroupMembers - adds/removes users to/from a group. Server
|
||||||
// creates the group as needed. Group is removed if remove request is
|
// creates the group as needed. Group is removed if remove request is
|
||||||
// made on empty group.
|
// made on empty group.
|
||||||
func (adm *AdminClient) UpdateGroupMembers(g GroupAddRemove) error {
|
func (adm *AdminClient) UpdateGroupMembers(ctx context.Context, g GroupAddRemove) error {
|
||||||
data, err := json.Marshal(g)
|
data, err := json.Marshal(g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -46,7 +47,7 @@ func (adm *AdminClient) UpdateGroupMembers(g GroupAddRemove) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/update-group-members
|
// Execute PUT on /minio/admin/v2/update-group-members
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -70,7 +71,7 @@ type GroupDesc struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetGroupDescription - fetches information on a group.
|
// GetGroupDescription - fetches information on a group.
|
||||||
func (adm *AdminClient) GetGroupDescription(group string) (*GroupDesc, error) {
|
func (adm *AdminClient) GetGroupDescription(ctx context.Context, group string) (*GroupDesc, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("group", group)
|
v.Set("group", group)
|
||||||
reqData := requestData{
|
reqData := requestData{
|
||||||
@ -78,7 +79,7 @@ func (adm *AdminClient) GetGroupDescription(group string) (*GroupDesc, error) {
|
|||||||
queryValues: v,
|
queryValues: v,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -102,12 +103,12 @@ func (adm *AdminClient) GetGroupDescription(group string) (*GroupDesc, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListGroups - lists all groups names present on the server.
|
// ListGroups - lists all groups names present on the server.
|
||||||
func (adm *AdminClient) ListGroups() ([]string, error) {
|
func (adm *AdminClient) ListGroups(ctx context.Context) ([]string, error) {
|
||||||
reqData := requestData{
|
reqData := requestData{
|
||||||
relPath: adminAPIPrefix + "/groups",
|
relPath: adminAPIPrefix + "/groups",
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -140,7 +141,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// SetGroupStatus - sets the status of a group.
|
// SetGroupStatus - sets the status of a group.
|
||||||
func (adm *AdminClient) SetGroupStatus(group string, status GroupStatus) error {
|
func (adm *AdminClient) SetGroupStatus(ctx context.Context, group string, status GroupStatus) error {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("group", group)
|
v.Set("group", group)
|
||||||
v.Set("status", string(status))
|
v.Set("status", string(status))
|
||||||
@ -150,7 +151,7 @@ func (adm *AdminClient) SetGroupStatus(group string, status GroupStatus) error {
|
|||||||
queryValues: v,
|
queryValues: v,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -47,13 +48,15 @@ type ServerCPUHardwareInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerCPUHardwareInfo - Returns cpu hardware information
|
// ServerCPUHardwareInfo - Returns cpu hardware information
|
||||||
func (adm *AdminClient) ServerCPUHardwareInfo() ([]ServerCPUHardwareInfo, error) {
|
func (adm *AdminClient) ServerCPUHardwareInfo(ctx context.Context) ([]ServerCPUHardwareInfo, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set(HARDWARE, string(CPU))
|
v.Set(HARDWARE, string(CPU))
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/hardware",
|
http.MethodGet, requestData{
|
||||||
queryValues: v,
|
relPath: adminAPIPrefix + "/hardware",
|
||||||
})
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -88,13 +91,15 @@ type ServerNetworkHardwareInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerNetworkHardwareInfo - Returns network hardware information
|
// ServerNetworkHardwareInfo - Returns network hardware information
|
||||||
func (adm *AdminClient) ServerNetworkHardwareInfo() ([]ServerNetworkHardwareInfo, error) {
|
func (adm *AdminClient) ServerNetworkHardwareInfo(ctx context.Context) ([]ServerNetworkHardwareInfo, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set(HARDWARE, string(NETWORK))
|
v.Set(HARDWARE, string(NETWORK))
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: "/v1/hardware",
|
http.MethodGet, requestData{
|
||||||
queryValues: v,
|
relPath: "/v1/hardware",
|
||||||
})
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -195,8 +196,8 @@ func (hri *HealResultItem) GetOnlineCounts() (b, a int) {
|
|||||||
// forceStart and forceStop are mutually exclusive, you can either
|
// forceStart and forceStop are mutually exclusive, you can either
|
||||||
// set one of them to 'true'. If both are set 'forceStart' will be
|
// set one of them to 'true'. If both are set 'forceStart' will be
|
||||||
// honored.
|
// honored.
|
||||||
func (adm *AdminClient) Heal(bucket, prefix string, healOpts HealOpts,
|
func (adm *AdminClient) Heal(ctx context.Context, bucket, prefix string,
|
||||||
clientToken string, forceStart, forceStop bool) (
|
healOpts HealOpts, clientToken string, forceStart, forceStop bool) (
|
||||||
healStart HealStartSuccess, healTaskStatus HealTaskStatus, err error) {
|
healStart HealStartSuccess, healTaskStatus HealTaskStatus, err error) {
|
||||||
|
|
||||||
if forceStart && forceStop {
|
if forceStart && forceStop {
|
||||||
@ -227,11 +228,12 @@ func (adm *AdminClient) Heal(bucket, prefix string, healOpts HealOpts,
|
|||||||
queryVals.Set("forceStop", "true")
|
queryVals.Set("forceStop", "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := adm.executeMethod("POST", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: path,
|
http.MethodPost, requestData{
|
||||||
content: body,
|
relPath: path,
|
||||||
queryValues: queryVals,
|
content: body,
|
||||||
})
|
queryValues: queryVals,
|
||||||
|
})
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return healStart, healTaskStatus, err
|
return healStart, healTaskStatus, err
|
||||||
@ -279,9 +281,11 @@ type BgHealState struct {
|
|||||||
|
|
||||||
// BackgroundHealStatus returns the background heal status of the
|
// BackgroundHealStatus returns the background heal status of the
|
||||||
// current server or cluster.
|
// current server or cluster.
|
||||||
func (adm *AdminClient) BackgroundHealStatus() (BgHealState, error) {
|
func (adm *AdminClient) BackgroundHealStatus(ctx context.Context) (BgHealState, error) {
|
||||||
// Execute POST request to background heal status api
|
// Execute POST request to background heal status api
|
||||||
resp, err := adm.executeMethod("POST", requestData{relPath: adminAPIPrefix + "/background-heal/status"})
|
resp, err := adm.executeMethod(ctx,
|
||||||
|
http.MethodPost,
|
||||||
|
requestData{relPath: adminAPIPrefix + "/background-heal/status"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BgHealState{}, err
|
return BgHealState{}, err
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@ -114,8 +115,8 @@ func (d1 BackendDisks) Merge(d2 BackendDisks) BackendDisks {
|
|||||||
|
|
||||||
// StorageInfo - Connect to a minio server and call Storage Info Management API
|
// StorageInfo - Connect to a minio server and call Storage Info Management API
|
||||||
// to fetch server's information represented by StorageInfo structure
|
// to fetch server's information represented by StorageInfo structure
|
||||||
func (adm *AdminClient) StorageInfo() (StorageInfo, error) {
|
func (adm *AdminClient) StorageInfo(ctx context.Context) (StorageInfo, error) {
|
||||||
resp, err := adm.executeMethod("GET", requestData{relPath: adminAPIPrefix + "/storageinfo"})
|
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{relPath: adminAPIPrefix + "/storageinfo"})
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return StorageInfo{}, err
|
return StorageInfo{}, err
|
||||||
@ -178,8 +179,8 @@ type DataUsageInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DataUsageInfo - returns data usage of the current object API
|
// DataUsageInfo - returns data usage of the current object API
|
||||||
func (adm *AdminClient) DataUsageInfo() (DataUsageInfo, error) {
|
func (adm *AdminClient) DataUsageInfo(ctx context.Context) (DataUsageInfo, error) {
|
||||||
resp, err := adm.executeMethod("GET", requestData{relPath: adminAPIPrefix + "/datausageinfo"})
|
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{relPath: adminAPIPrefix + "/datausageinfo"})
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DataUsageInfo{}, err
|
return DataUsageInfo{}, err
|
||||||
@ -222,8 +223,8 @@ type BucketAccountingUsage struct {
|
|||||||
|
|
||||||
// AccountingUsageInfo returns the accounting usage info, currently it returns
|
// AccountingUsageInfo returns the accounting usage info, currently it returns
|
||||||
// the type of access of different accounts to the different buckets.
|
// the type of access of different accounts to the different buckets.
|
||||||
func (adm *AdminClient) AccountingUsageInfo() (map[string]BucketAccountingUsage, error) {
|
func (adm *AdminClient) AccountingUsageInfo(ctx context.Context) (map[string]BucketAccountingUsage, error) {
|
||||||
resp, err := adm.executeMethod(http.MethodGet, requestData{relPath: adminAPIPrefix + "/accountingusageinfo"})
|
resp, err := adm.executeMethod(ctx, http.MethodGet, requestData{relPath: adminAPIPrefix + "/accountingusageinfo"})
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -260,16 +261,18 @@ type ServerDrivesPerfInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerDrivesPerfInfo - Returns drive's read and write performance information
|
// ServerDrivesPerfInfo - Returns drive's read and write performance information
|
||||||
func (adm *AdminClient) ServerDrivesPerfInfo(size int64) ([]ServerDrivesPerfInfo, error) {
|
func (adm *AdminClient) ServerDrivesPerfInfo(ctx context.Context, size int64) ([]ServerDrivesPerfInfo, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("perfType", string("drive"))
|
v.Set("perfType", string("drive"))
|
||||||
|
|
||||||
v.Set("size", strconv.FormatInt(size, 10))
|
v.Set("size", strconv.FormatInt(size, 10))
|
||||||
|
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx, http.MethodGet,
|
||||||
relPath: adminAPIPrefix + "/performance",
|
requestData{
|
||||||
queryValues: v,
|
relPath: adminAPIPrefix + "/performance",
|
||||||
})
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -307,13 +310,15 @@ type ServerCPULoadInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerCPULoadInfo - Returns cpu utilization information
|
// ServerCPULoadInfo - Returns cpu utilization information
|
||||||
func (adm *AdminClient) ServerCPULoadInfo() ([]ServerCPULoadInfo, error) {
|
func (adm *AdminClient) ServerCPULoadInfo(ctx context.Context) ([]ServerCPULoadInfo, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("perfType", string("cpu"))
|
v.Set("perfType", string("cpu"))
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/performance",
|
http.MethodGet, requestData{
|
||||||
queryValues: v,
|
relPath: adminAPIPrefix + "/performance",
|
||||||
})
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -351,13 +356,16 @@ type ServerMemUsageInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServerMemUsageInfo - Returns mem utilization information
|
// ServerMemUsageInfo - Returns mem utilization information
|
||||||
func (adm *AdminClient) ServerMemUsageInfo() ([]ServerMemUsageInfo, error) {
|
func (adm *AdminClient) ServerMemUsageInfo(ctx context.Context) ([]ServerMemUsageInfo, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("perfType", string("mem"))
|
v.Set("perfType", string("mem"))
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/performance",
|
http.MethodGet,
|
||||||
queryValues: v,
|
requestData{
|
||||||
})
|
relPath: adminAPIPrefix + "/performance",
|
||||||
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -393,16 +401,19 @@ type NetPerfInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NetPerfInfo - Returns network performance information of all cluster nodes.
|
// NetPerfInfo - Returns network performance information of all cluster nodes.
|
||||||
func (adm *AdminClient) NetPerfInfo(size int) (map[string][]NetPerfInfo, error) {
|
func (adm *AdminClient) NetPerfInfo(ctx context.Context, size int) (map[string][]NetPerfInfo, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("perfType", "net")
|
v.Set("perfType", "net")
|
||||||
if size > 0 {
|
if size > 0 {
|
||||||
v.Set("size", strconv.Itoa(size))
|
v.Set("size", strconv.Itoa(size))
|
||||||
}
|
}
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/performance",
|
http.MethodGet,
|
||||||
queryValues: v,
|
requestData{
|
||||||
})
|
relPath: adminAPIPrefix + "/performance",
|
||||||
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -509,13 +520,13 @@ const (
|
|||||||
ErasureType = backendType("Erasure")
|
ErasureType = backendType("Erasure")
|
||||||
)
|
)
|
||||||
|
|
||||||
// FsBackend contains specific FS storage information
|
// FSBackend contains specific FS storage information
|
||||||
type FsBackend struct {
|
type FSBackend struct {
|
||||||
Type backendType `json:"backendType,omitempty"`
|
Type backendType `json:"backendType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// XlBackend contains specific erasure storage information
|
// XLBackend contains specific erasure storage information
|
||||||
type XlBackend struct {
|
type XLBackend struct {
|
||||||
Type backendType `json:"backendType,omitempty"`
|
Type backendType `json:"backendType,omitempty"`
|
||||||
OnlineDisks int `json:"onlineDisks,omitempty"`
|
OnlineDisks int `json:"onlineDisks,omitempty"`
|
||||||
OfflineDisks int `json:"offlineDisks,omitempty"`
|
OfflineDisks int `json:"offlineDisks,omitempty"`
|
||||||
@ -557,9 +568,11 @@ type Disk struct {
|
|||||||
|
|
||||||
// ServerInfo - Connect to a minio server and call Server Admin Info Management API
|
// ServerInfo - Connect to a minio server and call Server Admin Info Management API
|
||||||
// to fetch server's information represented by infoMessage structure
|
// to fetch server's information represented by infoMessage structure
|
||||||
func (adm *AdminClient) ServerInfo() (InfoMessage, error) {
|
func (adm *AdminClient) ServerInfo(ctx context.Context) (InfoMessage, error) {
|
||||||
|
resp, err := adm.executeMethod(ctx,
|
||||||
resp, err := adm.executeMethod("GET", requestData{relPath: adminAPIPrefix + "/info"})
|
http.MethodGet,
|
||||||
|
requestData{relPath: adminAPIPrefix + "/info"},
|
||||||
|
)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return InfoMessage{}, err
|
return InfoMessage{}, err
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -25,7 +26,7 @@ import (
|
|||||||
// GetKeyStatus requests status information about the key referenced by keyID
|
// GetKeyStatus requests status information about the key referenced by keyID
|
||||||
// from the KMS connected to a MinIO by performing a Admin-API request.
|
// from the KMS connected to a MinIO by performing a Admin-API request.
|
||||||
// It basically hits the `/minio/admin/v2/kms/key/status` API endpoint.
|
// It basically hits the `/minio/admin/v2/kms/key/status` API endpoint.
|
||||||
func (adm *AdminClient) GetKeyStatus(keyID string) (*KMSKeyStatus, error) {
|
func (adm *AdminClient) GetKeyStatus(ctx context.Context, keyID string) (*KMSKeyStatus, error) {
|
||||||
// GET /minio/admin/v2/kms/key/status?key-id=<keyID>
|
// GET /minio/admin/v2/kms/key/status?key-id=<keyID>
|
||||||
qv := url.Values{}
|
qv := url.Values{}
|
||||||
qv.Set("key-id", keyID)
|
qv.Set("key-id", keyID)
|
||||||
@ -34,7 +35,7 @@ func (adm *AdminClient) GetKeyStatus(keyID string) (*KMSKeyStatus, error) {
|
|||||||
queryValues: qv,
|
queryValues: qv,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -25,7 +26,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// InfoCannedPolicy - expand canned policy into JSON structure.
|
// InfoCannedPolicy - expand canned policy into JSON structure.
|
||||||
func (adm *AdminClient) InfoCannedPolicy(policyName string) ([]byte, error) {
|
func (adm *AdminClient) InfoCannedPolicy(ctx context.Context, policyName string) ([]byte, error) {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("name", policyName)
|
queryValues.Set("name", policyName)
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ func (adm *AdminClient) InfoCannedPolicy(policyName string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/info-canned-policy
|
// Execute GET on /minio/admin/v2/info-canned-policy
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -50,13 +51,13 @@ func (adm *AdminClient) InfoCannedPolicy(policyName string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListCannedPolicies - list all configured canned policies.
|
// ListCannedPolicies - list all configured canned policies.
|
||||||
func (adm *AdminClient) ListCannedPolicies() (map[string][]byte, error) {
|
func (adm *AdminClient) ListCannedPolicies(ctx context.Context) (map[string][]byte, error) {
|
||||||
reqData := requestData{
|
reqData := requestData{
|
||||||
relPath: adminAPIPrefix + "/list-canned-policies",
|
relPath: adminAPIPrefix + "/list-canned-policies",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/list-canned-policies
|
// Execute GET on /minio/admin/v2/list-canned-policies
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -81,7 +82,7 @@ func (adm *AdminClient) ListCannedPolicies() (map[string][]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveCannedPolicy - remove a policy for a canned.
|
// RemoveCannedPolicy - remove a policy for a canned.
|
||||||
func (adm *AdminClient) RemoveCannedPolicy(policyName string) error {
|
func (adm *AdminClient) RemoveCannedPolicy(ctx context.Context, policyName string) error {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("name", policyName)
|
queryValues.Set("name", policyName)
|
||||||
|
|
||||||
@ -91,7 +92,7 @@ func (adm *AdminClient) RemoveCannedPolicy(policyName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute DELETE on /minio/admin/v2/remove-canned-policy to remove policy.
|
// Execute DELETE on /minio/admin/v2/remove-canned-policy to remove policy.
|
||||||
resp, err := adm.executeMethod("DELETE", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -106,7 +107,7 @@ func (adm *AdminClient) RemoveCannedPolicy(policyName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddCannedPolicy - adds a policy for a canned.
|
// AddCannedPolicy - adds a policy for a canned.
|
||||||
func (adm *AdminClient) AddCannedPolicy(policyName, policy string) error {
|
func (adm *AdminClient) AddCannedPolicy(ctx context.Context, policyName, policy string) error {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("name", policyName)
|
queryValues.Set("name", policyName)
|
||||||
|
|
||||||
@ -117,7 +118,7 @@ func (adm *AdminClient) AddCannedPolicy(policyName, policy string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/add-canned-policy to set policy.
|
// Execute PUT on /minio/admin/v2/add-canned-policy to set policy.
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -132,7 +133,7 @@ func (adm *AdminClient) AddCannedPolicy(policyName, policy string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetPolicy - sets the policy for a user or a group.
|
// SetPolicy - sets the policy for a user or a group.
|
||||||
func (adm *AdminClient) SetPolicy(policyName, entityName string, isGroup bool) error {
|
func (adm *AdminClient) SetPolicy(ctx context.Context, policyName, entityName string, isGroup bool) error {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("policyName", policyName)
|
queryValues.Set("policyName", policyName)
|
||||||
queryValues.Set("userOrGroup", entityName)
|
queryValues.Set("userOrGroup", entityName)
|
||||||
@ -148,7 +149,7 @@ func (adm *AdminClient) SetPolicy(policyName, entityName string, isGroup bool) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/set-user-or-group-policy to set policy.
|
// Execute PUT on /minio/admin/v2/set-user-or-group-policy to set policy.
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -52,13 +53,15 @@ type StartProfilingResult struct {
|
|||||||
|
|
||||||
// StartProfiling makes an admin call to remotely start profiling on a standalone
|
// StartProfiling makes an admin call to remotely start profiling on a standalone
|
||||||
// server or the whole cluster in case of a distributed setup.
|
// server or the whole cluster in case of a distributed setup.
|
||||||
func (adm *AdminClient) StartProfiling(profiler ProfilerType) ([]StartProfilingResult, error) {
|
func (adm *AdminClient) StartProfiling(ctx context.Context, profiler ProfilerType) ([]StartProfilingResult, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("profilerType", string(profiler))
|
v.Set("profilerType", string(profiler))
|
||||||
resp, err := adm.executeMethod("POST", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/profiling/start",
|
http.MethodPost, requestData{
|
||||||
queryValues: v,
|
relPath: adminAPIPrefix + "/profiling/start",
|
||||||
})
|
queryValues: v,
|
||||||
|
},
|
||||||
|
)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -84,11 +87,13 @@ func (adm *AdminClient) StartProfiling(profiler ProfilerType) ([]StartProfilingR
|
|||||||
|
|
||||||
// DownloadProfilingData makes an admin call to download profiling data of a standalone
|
// DownloadProfilingData makes an admin call to download profiling data of a standalone
|
||||||
// server or of the whole cluster in case of a distributed setup.
|
// server or of the whole cluster in case of a distributed setup.
|
||||||
func (adm *AdminClient) DownloadProfilingData() (io.ReadCloser, error) {
|
func (adm *AdminClient) DownloadProfilingData(ctx context.Context) (io.ReadCloser, error) {
|
||||||
path := fmt.Sprintf(adminAPIPrefix + "/profiling/download")
|
path := fmt.Sprintf(adminAPIPrefix + "/profiling/download")
|
||||||
resp, err := adm.executeMethod("GET", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: path,
|
http.MethodGet, requestData{
|
||||||
})
|
relPath: path,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closeResponse(resp)
|
closeResponse(resp)
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -68,7 +69,7 @@ func (r *lockedRandSource) Seed(seed int64) {
|
|||||||
|
|
||||||
// newRetryTimer creates a timer with exponentially increasing
|
// newRetryTimer creates a timer with exponentially increasing
|
||||||
// delays until the maximum retry attempts are reached.
|
// delays until the maximum retry attempts are reached.
|
||||||
func (adm AdminClient) newRetryTimer(maxRetry int, unit time.Duration, cap time.Duration, jitter float64, doneCh chan struct{}) <-chan int {
|
func (adm AdminClient) newRetryTimer(ctx context.Context, maxRetry int, unit time.Duration, cap time.Duration, jitter float64) <-chan int {
|
||||||
attemptCh := make(chan int)
|
attemptCh := make(chan int)
|
||||||
|
|
||||||
// computes the exponential backoff duration according to
|
// computes the exponential backoff duration according to
|
||||||
@ -96,14 +97,15 @@ func (adm AdminClient) newRetryTimer(maxRetry int, unit time.Duration, cap time.
|
|||||||
go func() {
|
go func() {
|
||||||
defer close(attemptCh)
|
defer close(attemptCh)
|
||||||
for i := 0; i < maxRetry; i++ {
|
for i := 0; i < maxRetry; i++ {
|
||||||
select {
|
|
||||||
// Attempts start from 1.
|
// Attempts start from 1.
|
||||||
case attemptCh <- i + 1:
|
attemptCh <- i + 1
|
||||||
case <-doneCh:
|
|
||||||
|
select {
|
||||||
|
case <-time.After(exponentialBackoffWait(i)):
|
||||||
|
case <-ctx.Done():
|
||||||
// Stop the routine.
|
// Stop the routine.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
time.Sleep(exponentialBackoffWait(i))
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return attemptCh
|
return attemptCh
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -27,13 +28,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ServiceRestart - restarts the MinIO cluster
|
// ServiceRestart - restarts the MinIO cluster
|
||||||
func (adm *AdminClient) ServiceRestart() error {
|
func (adm *AdminClient) ServiceRestart(ctx context.Context) error {
|
||||||
return adm.serviceCallAction(ServiceActionRestart)
|
return adm.serviceCallAction(ctx, ServiceActionRestart)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceStop - stops the MinIO cluster
|
// ServiceStop - stops the MinIO cluster
|
||||||
func (adm *AdminClient) ServiceStop() error {
|
func (adm *AdminClient) ServiceStop(ctx context.Context) error {
|
||||||
return adm.serviceCallAction(ServiceActionStop)
|
return adm.serviceCallAction(ctx, ServiceActionStop)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceAction - type to restrict service-action values
|
// ServiceAction - type to restrict service-action values
|
||||||
@ -47,15 +48,17 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// serviceCallAction - call service restart/update/stop API.
|
// serviceCallAction - call service restart/update/stop API.
|
||||||
func (adm *AdminClient) serviceCallAction(action ServiceAction) error {
|
func (adm *AdminClient) serviceCallAction(ctx context.Context, action ServiceAction) error {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("action", string(action))
|
queryValues.Set("action", string(action))
|
||||||
|
|
||||||
// Request API to Restart server
|
// Request API to Restart server
|
||||||
resp, err := adm.executeMethod("POST", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/service",
|
http.MethodPost, requestData{
|
||||||
queryValues: queryValues,
|
relPath: adminAPIPrefix + "/service",
|
||||||
})
|
queryValues: queryValues,
|
||||||
|
},
|
||||||
|
)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -75,7 +78,7 @@ type ServiceTraceInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServiceTrace - listen on http trace notifications.
|
// ServiceTrace - listen on http trace notifications.
|
||||||
func (adm AdminClient) ServiceTrace(allTrace, errTrace bool, doneCh <-chan struct{}) <-chan ServiceTraceInfo {
|
func (adm AdminClient) ServiceTrace(ctx context.Context, allTrace, errTrace bool) <-chan ServiceTraceInfo {
|
||||||
traceInfoCh := make(chan ServiceTraceInfo)
|
traceInfoCh := make(chan ServiceTraceInfo)
|
||||||
// Only success, start a routine to start reading line by line.
|
// Only success, start a routine to start reading line by line.
|
||||||
go func(traceInfoCh chan<- ServiceTraceInfo) {
|
go func(traceInfoCh chan<- ServiceTraceInfo) {
|
||||||
@ -89,7 +92,7 @@ func (adm AdminClient) ServiceTrace(allTrace, errTrace bool, doneCh <-chan struc
|
|||||||
queryValues: urlValues,
|
queryValues: urlValues,
|
||||||
}
|
}
|
||||||
// Execute GET to call trace handler
|
// Execute GET to call trace handler
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closeResponse(resp)
|
closeResponse(resp)
|
||||||
return
|
return
|
||||||
@ -107,7 +110,7 @@ func (adm AdminClient) ServiceTrace(allTrace, errTrace bool, doneCh <-chan struc
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-doneCh:
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case traceInfoCh <- ServiceTraceInfo{Trace: info}:
|
case traceInfoCh <- ServiceTraceInfo{Trace: info}:
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -53,11 +54,13 @@ func (l LockEntries) Swap(i, j int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TopLocks - returns the oldest locks in a minio setup.
|
// TopLocks - returns the oldest locks in a minio setup.
|
||||||
func (adm *AdminClient) TopLocks() (LockEntries, error) {
|
func (adm *AdminClient) TopLocks(ctx context.Context) (LockEntries, error) {
|
||||||
// Execute GET on /minio/admin/v2/top/locks
|
// Execute GET on /minio/admin/v2/top/locks
|
||||||
// to get the oldest locks in a minio setup.
|
// to get the oldest locks in a minio setup.
|
||||||
resp, err := adm.executeMethod("GET",
|
resp, err := adm.executeMethod(ctx,
|
||||||
requestData{relPath: adminAPIPrefix + "/top/locks"})
|
http.MethodGet,
|
||||||
|
requestData{relPath: adminAPIPrefix + "/top/locks"},
|
||||||
|
)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
60
pkg/madmin/transport.go
Normal file
60
pkg/madmin/transport.go
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Cloud Storage, (C) 2020 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 madmin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultTransport - this default transport is similar to
|
||||||
|
// http.DefaultTransport but with additional param DisableCompression
|
||||||
|
// is set to true to avoid decompressing content with 'gzip' encoding.
|
||||||
|
var DefaultTransport = func(secure bool) http.RoundTripper {
|
||||||
|
tr := &http.Transport{
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
DialContext: (&net.Dialer{
|
||||||
|
Timeout: 5 * time.Second,
|
||||||
|
KeepAlive: 15 * time.Second,
|
||||||
|
}).DialContext,
|
||||||
|
MaxIdleConns: 1024,
|
||||||
|
MaxIdleConnsPerHost: 1024,
|
||||||
|
ResponseHeaderTimeout: 60 * time.Second,
|
||||||
|
IdleConnTimeout: 60 * time.Second,
|
||||||
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
|
// Set this value so that the underlying transport round-tripper
|
||||||
|
// doesn't try to auto decode the body of objects with
|
||||||
|
// content-encoding set to `gzip`.
|
||||||
|
//
|
||||||
|
// Refer:
|
||||||
|
// https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
|
||||||
|
DisableCompression: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
if secure {
|
||||||
|
tr.TLSClientConfig = &tls.Config{
|
||||||
|
// Can't use SSLv3 because of POODLE and BEAST
|
||||||
|
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
|
||||||
|
// Can't use TLSv1.1 because of RC4 cipher usage
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tr
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -32,15 +33,17 @@ type ServerUpdateStatus struct {
|
|||||||
|
|
||||||
// ServerUpdate - updates and restarts the MinIO cluster to latest version.
|
// ServerUpdate - updates and restarts the MinIO cluster to latest version.
|
||||||
// optionally takes an input URL to specify a custom update binary link
|
// optionally takes an input URL to specify a custom update binary link
|
||||||
func (adm *AdminClient) ServerUpdate(updateURL string) (us ServerUpdateStatus, err error) {
|
func (adm *AdminClient) ServerUpdate(ctx context.Context, updateURL string) (us ServerUpdateStatus, err error) {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("updateURL", updateURL)
|
queryValues.Set("updateURL", updateURL)
|
||||||
|
|
||||||
// Request API to Restart server
|
// Request API to Restart server
|
||||||
resp, err := adm.executeMethod("POST", requestData{
|
resp, err := adm.executeMethod(ctx,
|
||||||
relPath: adminAPIPrefix + "/update",
|
http.MethodPost, requestData{
|
||||||
queryValues: queryValues,
|
relPath: adminAPIPrefix + "/update",
|
||||||
})
|
queryValues: queryValues,
|
||||||
|
},
|
||||||
|
)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return us, err
|
return us, err
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package madmin
|
package madmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -44,7 +45,7 @@ type UserInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveUser - remove a user.
|
// RemoveUser - remove a user.
|
||||||
func (adm *AdminClient) RemoveUser(accessKey string) error {
|
func (adm *AdminClient) RemoveUser(ctx context.Context, accessKey string) error {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("accessKey", accessKey)
|
queryValues.Set("accessKey", accessKey)
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ func (adm *AdminClient) RemoveUser(accessKey string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute DELETE on /minio/admin/v2/remove-user to remove a user.
|
// Execute DELETE on /minio/admin/v2/remove-user to remove a user.
|
||||||
resp, err := adm.executeMethod("DELETE", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,13 +70,13 @@ func (adm *AdminClient) RemoveUser(accessKey string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ListUsers - list all users.
|
// ListUsers - list all users.
|
||||||
func (adm *AdminClient) ListUsers() (map[string]UserInfo, error) {
|
func (adm *AdminClient) ListUsers(ctx context.Context) (map[string]UserInfo, error) {
|
||||||
reqData := requestData{
|
reqData := requestData{
|
||||||
relPath: adminAPIPrefix + "/list-users",
|
relPath: adminAPIPrefix + "/list-users",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/list-users
|
// Execute GET on /minio/admin/v2/list-users
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,7 +101,7 @@ func (adm *AdminClient) ListUsers() (map[string]UserInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUserInfo - get info on a user
|
// GetUserInfo - get info on a user
|
||||||
func (adm *AdminClient) GetUserInfo(name string) (u UserInfo, err error) {
|
func (adm *AdminClient) GetUserInfo(ctx context.Context, name string) (u UserInfo, err error) {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("accessKey", name)
|
queryValues.Set("accessKey", name)
|
||||||
|
|
||||||
@ -110,7 +111,7 @@ func (adm *AdminClient) GetUserInfo(name string) (u UserInfo, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/user-info
|
// Execute GET on /minio/admin/v2/user-info
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -134,7 +135,7 @@ func (adm *AdminClient) GetUserInfo(name string) (u UserInfo, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetUser - sets a user info.
|
// SetUser - sets a user info.
|
||||||
func (adm *AdminClient) SetUser(accessKey, secretKey string, status AccountStatus) error {
|
func (adm *AdminClient) SetUser(ctx context.Context, accessKey, secretKey string, status AccountStatus) error {
|
||||||
|
|
||||||
if !auth.IsAccessKeyValid(accessKey) {
|
if !auth.IsAccessKeyValid(accessKey) {
|
||||||
return auth.ErrInvalidAccessKeyLength
|
return auth.ErrInvalidAccessKeyLength
|
||||||
@ -166,7 +167,7 @@ func (adm *AdminClient) SetUser(accessKey, secretKey string, status AccountStatu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/add-user to set a user.
|
// Execute PUT on /minio/admin/v2/add-user to set a user.
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,12 +182,12 @@ func (adm *AdminClient) SetUser(accessKey, secretKey string, status AccountStatu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddUser - adds a user.
|
// AddUser - adds a user.
|
||||||
func (adm *AdminClient) AddUser(accessKey, secretKey string) error {
|
func (adm *AdminClient) AddUser(ctx context.Context, accessKey, secretKey string) error {
|
||||||
return adm.SetUser(accessKey, secretKey, AccountEnabled)
|
return adm.SetUser(ctx, accessKey, secretKey, AccountEnabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUserStatus - adds a status for a user.
|
// SetUserStatus - adds a status for a user.
|
||||||
func (adm *AdminClient) SetUserStatus(accessKey string, status AccountStatus) error {
|
func (adm *AdminClient) SetUserStatus(ctx context.Context, accessKey string, status AccountStatus) error {
|
||||||
queryValues := url.Values{}
|
queryValues := url.Values{}
|
||||||
queryValues.Set("accessKey", accessKey)
|
queryValues.Set("accessKey", accessKey)
|
||||||
queryValues.Set("status", string(status))
|
queryValues.Set("status", string(status))
|
||||||
@ -197,7 +198,7 @@ func (adm *AdminClient) SetUserStatus(accessKey string, status AccountStatus) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/set-user-status to set status.
|
// Execute PUT on /minio/admin/v2/set-user-status to set status.
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
|
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -224,7 +225,7 @@ type AddServiceAccountResp struct {
|
|||||||
|
|
||||||
// AddServiceAccount - creates a new service account belonging to the given parent user
|
// AddServiceAccount - creates a new service account belonging to the given parent user
|
||||||
// while restricting the service account permission by the given policy document.
|
// while restricting the service account permission by the given policy document.
|
||||||
func (adm *AdminClient) AddServiceAccount(parentUser string, policy string) (auth.Credentials, error) {
|
func (adm *AdminClient) AddServiceAccount(ctx context.Context, parentUser string, policy string) (auth.Credentials, error) {
|
||||||
|
|
||||||
if !auth.IsAccessKeyValid(parentUser) {
|
if !auth.IsAccessKeyValid(parentUser) {
|
||||||
return auth.Credentials{}, auth.ErrInvalidAccessKeyLength
|
return auth.Credentials{}, auth.ErrInvalidAccessKeyLength
|
||||||
@ -249,7 +250,7 @@ func (adm *AdminClient) AddServiceAccount(parentUser string, policy string) (aut
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute PUT on /minio/admin/v2/add-service-account to set a user.
|
// Execute PUT on /minio/admin/v2/add-service-account to set a user.
|
||||||
resp, err := adm.executeMethod("PUT", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return auth.Credentials{}, err
|
return auth.Credentials{}, err
|
||||||
@ -272,7 +273,7 @@ func (adm *AdminClient) AddServiceAccount(parentUser string, policy string) (aut
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetServiceAccount returns the credential of the service account
|
// GetServiceAccount returns the credential of the service account
|
||||||
func (adm *AdminClient) GetServiceAccount(serviceAccountAccessKey string) (auth.Credentials, error) {
|
func (adm *AdminClient) GetServiceAccount(ctx context.Context, serviceAccountAccessKey string) (auth.Credentials, error) {
|
||||||
|
|
||||||
if !auth.IsAccessKeyValid(serviceAccountAccessKey) {
|
if !auth.IsAccessKeyValid(serviceAccountAccessKey) {
|
||||||
return auth.Credentials{}, auth.ErrInvalidAccessKeyLength
|
return auth.Credentials{}, auth.ErrInvalidAccessKeyLength
|
||||||
@ -287,7 +288,7 @@ func (adm *AdminClient) GetServiceAccount(serviceAccountAccessKey string) (auth.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute GET on /minio/admin/v2/get-service-account to set a user.
|
// Execute GET on /minio/admin/v2/get-service-account to set a user.
|
||||||
resp, err := adm.executeMethod("GET", reqData)
|
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||||
defer closeResponse(resp)
|
defer closeResponse(resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return auth.Credentials{}, err
|
return auth.Credentials{}, err
|
||||||
|
Loading…
Reference in New Issue
Block a user