2017-02-20 15:58:50 -05:00
|
|
|
/*
|
2019-10-23 01:59:13 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2017-2019 MinIO, Inc.
|
2017-02-20 15:58:50 -05:00
|
|
|
*
|
|
|
|
* 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 (
|
2018-08-15 00:41:47 -04:00
|
|
|
"bytes"
|
2020-03-20 18:00:44 -04:00
|
|
|
"context"
|
2017-02-27 14:40:27 -05:00
|
|
|
"io"
|
2017-02-20 15:58:50 -05:00
|
|
|
"net/http"
|
2017-02-27 14:40:27 -05:00
|
|
|
)
|
|
|
|
|
2018-08-15 00:41:47 -04:00
|
|
|
// GetConfig - returns the config.json of a minio setup, incoming data is encrypted.
|
2020-03-20 18:00:44 -04:00
|
|
|
func (adm *AdminClient) GetConfig(ctx context.Context) ([]byte, error) {
|
2019-10-23 00:01:14 -04:00
|
|
|
// Execute GET on /minio/admin/v2/config to get config of a setup.
|
2020-03-20 18:00:44 -04:00
|
|
|
resp, err := adm.executeMethod(ctx,
|
|
|
|
http.MethodGet,
|
2019-10-23 00:01:14 -04:00
|
|
|
requestData{relPath: adminAPIPrefix + "/config"})
|
2017-02-20 15:58:50 -05:00
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-02-27 14:40:27 -05:00
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
return nil, httpRespToErrorResponse(resp)
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:00:01 -04:00
|
|
|
return DecryptData(adm.secretAccessKey, resp.Body)
|
2017-02-20 15:58:50 -05:00
|
|
|
}
|
2017-02-27 14:40:27 -05:00
|
|
|
|
|
|
|
// SetConfig - set config supplied as config.json for the setup.
|
2020-03-20 18:00:44 -04:00
|
|
|
func (adm *AdminClient) SetConfig(ctx context.Context, config io.Reader) (err error) {
|
2018-07-03 14:07:46 -04:00
|
|
|
const maxConfigJSONSize = 256 * 1024 // 256KiB
|
|
|
|
|
|
|
|
// Read configuration bytes
|
|
|
|
configBuf := make([]byte, maxConfigJSONSize+1)
|
|
|
|
n, err := io.ReadFull(config, configBuf)
|
|
|
|
if err == nil {
|
2018-10-09 17:00:01 -04:00
|
|
|
return bytes.ErrTooLarge
|
2018-07-03 14:07:46 -04:00
|
|
|
}
|
|
|
|
if err != io.ErrUnexpectedEOF {
|
2018-08-17 21:51:34 -04:00
|
|
|
return err
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|
2018-07-03 14:07:46 -04:00
|
|
|
configBytes := configBuf[:n]
|
2018-10-09 17:00:01 -04:00
|
|
|
econfigBytes, err := EncryptData(adm.secretAccessKey, configBytes)
|
2018-08-15 00:41:47 -04:00
|
|
|
if err != nil {
|
2018-08-17 21:51:34 -04:00
|
|
|
return err
|
2018-08-15 00:41:47 -04:00
|
|
|
}
|
|
|
|
|
2017-02-27 14:40:27 -05:00
|
|
|
reqData := requestData{
|
2019-10-23 00:01:14 -04:00
|
|
|
relPath: adminAPIPrefix + "/config",
|
2018-08-15 00:41:47 -04:00
|
|
|
content: econfigBytes,
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|
|
|
|
|
2019-10-23 00:01:14 -04:00
|
|
|
// Execute PUT on /minio/admin/v2/config to set config.
|
2020-03-20 18:00:44 -04:00
|
|
|
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
2017-02-27 14:40:27 -05:00
|
|
|
|
|
|
|
defer closeResponse(resp)
|
|
|
|
if err != nil {
|
2018-08-17 21:51:34 -04:00
|
|
|
return err
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
2018-08-17 21:51:34 -04:00
|
|
|
return httpRespToErrorResponse(resp)
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|
|
|
|
|
2018-08-17 21:51:34 -04:00
|
|
|
return nil
|
2017-02-27 14:40:27 -05:00
|
|
|
}
|