Update madmin API with latest server changes (#2516)
This commit is contained in:
committed by
kannappanr
parent
3b78c115f6
commit
073ed250fe
+4
-21
@@ -18,14 +18,12 @@ package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
var adminConfigSetCmd = cli.Command{
|
||||
@@ -52,25 +50,12 @@ EXAMPLES:
|
||||
|
||||
// configSetMessage container to hold locks information.
|
||||
type configSetMessage struct {
|
||||
Status string `json:"status"`
|
||||
setConfigStatus bool
|
||||
SetConfigNodeSummary []madmin.NodeSummary `json:"nodesSummary"`
|
||||
Status string `json:"status"`
|
||||
setConfigStatus bool
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configSetMessage) String() (msg string) {
|
||||
// For each node, print if set config was successful or not
|
||||
for _, s := range u.SetConfigNodeSummary {
|
||||
if s.ErrSet {
|
||||
// An error occurred when setting the new config
|
||||
msg += console.Colorize("SetConfigFailure",
|
||||
fmt.Sprintf("Failed to apply the new configuration to `%s` (%s).", s.Name, s.ErrMsg))
|
||||
} else {
|
||||
msg += console.Colorize("SetConfigSuccess",
|
||||
fmt.Sprintf("New configuration applied to `%s` successfully.", s.Name))
|
||||
}
|
||||
msg += "\n"
|
||||
}
|
||||
// Print the general set config status
|
||||
if u.setConfigStatus {
|
||||
msg += console.Colorize("SetConfigSuccess",
|
||||
@@ -121,13 +106,11 @@ func mainAdminConfigSet(ctx *cli.Context) error {
|
||||
fatalIf(err, "Cannot get a configured admin connection.")
|
||||
|
||||
// Call get config API
|
||||
c, e := client.SetConfig(os.Stdin)
|
||||
fatalIf(probe.NewError(e), "Cannot set server configuration file.")
|
||||
fatalIf(probe.NewError(client.SetConfig(os.Stdin)), "Cannot set server configuration file.")
|
||||
|
||||
// Print set config result
|
||||
printMsg(configSetMessage{
|
||||
setConfigStatus: c.Status,
|
||||
SetConfigNodeSummary: c.NodeResults,
|
||||
setConfigStatus: true,
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
+10
-31
@@ -32,21 +32,6 @@ import (
|
||||
"golang.org/x/crypto/argon2"
|
||||
)
|
||||
|
||||
// NodeSummary - represents the result of an operation part of
|
||||
// set-config on a node.
|
||||
type NodeSummary struct {
|
||||
Name string `json:"name"`
|
||||
ErrSet bool `json:"errSet"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
}
|
||||
|
||||
// SetConfigResult - represents detailed results of a set-config
|
||||
// operation.
|
||||
type SetConfigResult struct {
|
||||
NodeResults []NodeSummary `json:"nodeResults"`
|
||||
Status bool `json:"status"`
|
||||
}
|
||||
|
||||
// EncryptServerConfigData - encrypts server config data.
|
||||
func EncryptServerConfigData(password string, data []byte) ([]byte, error) {
|
||||
salt := make([]byte, 32)
|
||||
@@ -106,17 +91,17 @@ func (adm *AdminClient) GetConfig() ([]byte, error) {
|
||||
}
|
||||
|
||||
// SetConfig - set config supplied as config.json for the setup.
|
||||
func (adm *AdminClient) SetConfig(config io.Reader) (r SetConfigResult, err error) {
|
||||
func (adm *AdminClient) SetConfig(config io.Reader) (err error) {
|
||||
const maxConfigJSONSize = 256 * 1024 // 256KiB
|
||||
|
||||
// Read configuration bytes
|
||||
configBuf := make([]byte, maxConfigJSONSize+1)
|
||||
n, err := io.ReadFull(config, configBuf)
|
||||
if err == nil {
|
||||
return r, fmt.Errorf("too large file")
|
||||
return fmt.Errorf("too large file")
|
||||
}
|
||||
if err != io.ErrUnexpectedEOF {
|
||||
return r, err
|
||||
return err
|
||||
}
|
||||
configBytes := configBuf[:n]
|
||||
|
||||
@@ -127,21 +112,21 @@ func (adm *AdminClient) SetConfig(config io.Reader) (r SetConfigResult, err erro
|
||||
|
||||
// Check if read data is in json format
|
||||
if err = json.Unmarshal(configBytes, &cfg); err != nil {
|
||||
return r, errors.New("Invalid JSON format: " + err.Error())
|
||||
return errors.New("Invalid JSON format: " + err.Error())
|
||||
}
|
||||
|
||||
// Check if the provided json file has "version" key set
|
||||
if cfg.Version == "" {
|
||||
return r, errors.New("Missing or unset \"version\" key in json file")
|
||||
return errors.New("Missing or unset \"version\" key in json file")
|
||||
}
|
||||
// Validate there are no duplicate keys in the JSON
|
||||
if err = quick.CheckDuplicateKeys(string(configBytes)); err != nil {
|
||||
return r, errors.New("Duplicate key in json file: " + err.Error())
|
||||
return errors.New("Duplicate key in json file: " + err.Error())
|
||||
}
|
||||
|
||||
econfigBytes, err := EncryptServerConfigData(adm.secretAccessKey, configBytes)
|
||||
if err != nil {
|
||||
return r, err
|
||||
return err
|
||||
}
|
||||
|
||||
reqData := requestData{
|
||||
@@ -154,18 +139,12 @@ func (adm *AdminClient) SetConfig(config io.Reader) (r SetConfigResult, err erro
|
||||
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
return r, err
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return r, httpRespToErrorResponse(resp)
|
||||
return httpRespToErrorResponse(resp)
|
||||
}
|
||||
|
||||
jsonBytes, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(jsonBytes, &r)
|
||||
return r, err
|
||||
return nil
|
||||
}
|
||||
|
||||
+5
-5
@@ -19,7 +19,6 @@ package madmin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -38,15 +37,15 @@ func (adm *AdminClient) SetCredentials(access, secret string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// No TLS?
|
||||
if !adm.secure {
|
||||
return fmt.Errorf("credentials cannot be updated over an insecure connection")
|
||||
ebody, err := EncryptServerConfigData(adm.secretAccessKey, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Setup new request
|
||||
reqData := requestData{
|
||||
relPath: "/v1/config/credential",
|
||||
content: body,
|
||||
content: ebody,
|
||||
}
|
||||
|
||||
// Execute GET on bucket to list objects.
|
||||
@@ -62,5 +61,6 @@ func (adm *AdminClient) SetCredentials(access, secret string) error {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return httpRespToErrorResponse(resp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -134,10 +134,10 @@
|
||||
"revisionTime": "2018-07-11T12:25:12Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "35+lUqDwPqhV4AXl3YyV6cAyX4o=",
|
||||
"checksumSHA1": "GTO2Gi65SvrlN6xOVQykGuoZ8fc=",
|
||||
"path": "github.com/minio/minio/pkg/madmin",
|
||||
"revision": "0e02328c98178be462de9544d165c182b40cb1ce",
|
||||
"revisionTime": "2018-08-15T04:41:47Z"
|
||||
"revision": "b2d44edc2659ddbffa6ebd0006bc0b1fbff60de3",
|
||||
"revisionTime": "2018-08-17T23:03:41Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "flg07CqTxM9togozKRQiJugao4s=",
|
||||
|
||||
Reference in New Issue
Block a user