storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/madmin/config-commands.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2017-2019 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 package madmin 19 20 import ( 21 "bytes" 22 "context" 23 "io" 24 "net/http" 25 ) 26 27 // GetConfig - returns the config.json of a minio setup, incoming data is encrypted. 28 func (adm *AdminClient) GetConfig(ctx context.Context) ([]byte, error) { 29 // Execute GET on /minio/admin/v3/config to get config of a setup. 30 resp, err := adm.executeMethod(ctx, 31 http.MethodGet, 32 requestData{relPath: adminAPIPrefix + "/config"}) 33 defer closeResponse(resp) 34 if err != nil { 35 return nil, err 36 } 37 38 if resp.StatusCode != http.StatusOK { 39 return nil, httpRespToErrorResponse(resp) 40 } 41 42 return DecryptData(adm.getSecretKey(), resp.Body) 43 } 44 45 // SetConfig - set config supplied as config.json for the setup. 46 func (adm *AdminClient) SetConfig(ctx context.Context, config io.Reader) (err error) { 47 const maxConfigJSONSize = 256 * 1024 // 256KiB 48 49 // Read configuration bytes 50 configBuf := make([]byte, maxConfigJSONSize+1) 51 n, err := io.ReadFull(config, configBuf) 52 if err == nil { 53 return bytes.ErrTooLarge 54 } 55 if err != io.ErrUnexpectedEOF { 56 return err 57 } 58 configBytes := configBuf[:n] 59 econfigBytes, err := EncryptData(adm.getSecretKey(), configBytes) 60 if err != nil { 61 return err 62 } 63 64 reqData := requestData{ 65 relPath: adminAPIPrefix + "/config", 66 content: econfigBytes, 67 } 68 69 // Execute PUT on /minio/admin/v3/config to set config. 70 resp, err := adm.executeMethod(ctx, http.MethodPut, reqData) 71 72 defer closeResponse(resp) 73 if err != nil { 74 return err 75 } 76 77 if resp.StatusCode != http.StatusOK { 78 return httpRespToErrorResponse(resp) 79 } 80 81 return nil 82 }