mirror of
https://github.com/minio/minio.git
synced 2025-11-11 14:30:17 -05:00
Ensure that setConfig uses latest functionality (#6302)
This commit is contained in:
committed by
kannappanr
parent
50a817e3d3
commit
9f14433cbd
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user