github.com/minio/madmin-go@v1.7.5/iam-migrate.go (about) 1 // 2 // MinIO Object Storage (c) 2022 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 package madmin 18 19 import ( 20 "context" 21 "io" 22 "io/ioutil" 23 "net/http" 24 ) 25 26 // ExportIAM makes an admin call to export IAM data 27 func (adm *AdminClient) ExportIAM(ctx context.Context) (io.ReadCloser, error) { 28 path := adminAPIPrefix + "/export-iam" 29 30 resp, err := adm.executeMethod(ctx, 31 http.MethodGet, requestData{ 32 relPath: path, 33 }, 34 ) 35 if err != nil { 36 return nil, err 37 } 38 39 if resp.StatusCode != http.StatusOK { 40 closeResponse(resp) 41 return nil, httpRespToErrorResponse(resp) 42 } 43 return resp.Body, nil 44 } 45 46 // ImportIAM makes an admin call to setup IAM from imported content 47 func (adm *AdminClient) ImportIAM(ctx context.Context, contentReader io.ReadCloser) error { 48 content, err := ioutil.ReadAll(contentReader) 49 if err != nil { 50 return err 51 } 52 53 path := adminAPIPrefix + "/import-iam" 54 resp, err := adm.executeMethod(ctx, 55 http.MethodPut, requestData{ 56 relPath: path, 57 content: content, 58 }, 59 ) 60 defer closeResponse(resp) 61 if err != nil { 62 return err 63 } 64 65 if resp.StatusCode != http.StatusOK { 66 return httpRespToErrorResponse(resp) 67 } 68 return nil 69 }