2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-02-20 15:58:50 -05:00
|
|
|
|
|
|
|
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) {
|
2020-04-07 22:30:59 -04:00
|
|
|
// Execute GET on /minio/admin/v3/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)
|
|
|
|
}
|
|
|
|
|
2020-04-01 16:34:20 -04:00
|
|
|
return DecryptData(adm.getSecretKey(), 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]
|
2020-04-01 16:34:20 -04:00
|
|
|
econfigBytes, err := EncryptData(adm.getSecretKey(), 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
|
|
|
}
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// Execute PUT on /minio/admin/v3/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
|
|
|
}
|