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