github.com/minio/madmin-go/v2@v2.2.1/config-commands.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 import ( 23 "bytes" 24 "context" 25 "io" 26 "net/http" 27 ) 28 29 // GetConfig - returns the config.json of a minio setup, incoming data is encrypted. 30 func (adm *AdminClient) GetConfig(ctx context.Context) ([]byte, error) { 31 // Execute GET on /minio/admin/v3/config to get config of a setup. 32 resp, err := adm.executeMethod(ctx, 33 http.MethodGet, 34 requestData{relPath: adminAPIPrefix + "/config"}) 35 defer closeResponse(resp) 36 if err != nil { 37 return nil, err 38 } 39 40 if resp.StatusCode != http.StatusOK { 41 return nil, httpRespToErrorResponse(resp) 42 } 43 44 return DecryptData(adm.getSecretKey(), resp.Body) 45 } 46 47 // SetConfig - set config supplied as config.json for the setup. 48 func (adm *AdminClient) SetConfig(ctx context.Context, config io.Reader) (err error) { 49 const maxConfigJSONSize = 256 * 1024 // 256KiB 50 51 // Read configuration bytes 52 configBuf := make([]byte, maxConfigJSONSize+1) 53 n, err := io.ReadFull(config, configBuf) 54 if err == nil { 55 return bytes.ErrTooLarge 56 } 57 if err != io.ErrUnexpectedEOF { 58 return err 59 } 60 configBytes := configBuf[:n] 61 econfigBytes, err := EncryptData(adm.getSecretKey(), configBytes) 62 if err != nil { 63 return err 64 } 65 66 reqData := requestData{ 67 relPath: adminAPIPrefix + "/config", 68 content: econfigBytes, 69 } 70 71 // Execute PUT on /minio/admin/v3/config to set config. 72 resp, err := adm.executeMethod(ctx, http.MethodPut, reqData) 73 74 defer closeResponse(resp) 75 if err != nil { 76 return err 77 } 78 79 if resp.StatusCode != http.StatusOK { 80 return httpRespToErrorResponse(resp) 81 } 82 83 return nil 84 }