github.com/minio/madmin-go@v1.7.5/bucket-metadata.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 "encoding/json" 22 "io" 23 "io/ioutil" 24 "net/http" 25 "net/url" 26 ) 27 28 // ExportBucketMetadata makes an admin call to export bucket metadata of a bucket 29 func (adm *AdminClient) ExportBucketMetadata(ctx context.Context, bucket string) (io.ReadCloser, error) { 30 path := adminAPIPrefix + "/export-bucket-metadata" 31 queryValues := url.Values{} 32 queryValues.Set("bucket", bucket) 33 34 resp, err := adm.executeMethod(ctx, 35 http.MethodGet, requestData{ 36 relPath: path, 37 queryValues: queryValues, 38 }, 39 ) 40 if err != nil { 41 return nil, err 42 } 43 44 if resp.StatusCode != http.StatusOK { 45 closeResponse(resp) 46 return nil, httpRespToErrorResponse(resp) 47 } 48 return resp.Body, nil 49 } 50 51 // MetaStatus status of metadata import 52 type MetaStatus struct { 53 IsSet bool `json:"isSet"` 54 Err string `json:"error,omitempty"` 55 } 56 57 // BucketStatus reflects status of bucket metadata import 58 type BucketStatus struct { 59 ObjectLock MetaStatus `json:"olock"` 60 Versioning MetaStatus `json:"versioning"` 61 Policy MetaStatus `json:"policy"` 62 Tagging MetaStatus `json:"tagging"` 63 SSEConfig MetaStatus `json:"sse"` 64 Lifecycle MetaStatus `json:"lifecycle"` 65 Notification MetaStatus `json:"notification"` 66 Quota MetaStatus `json:"quota"` 67 Err string `json:"error,omitempty"` 68 } 69 70 // BucketMetaImportErrs reports on bucket metadata import status. 71 type BucketMetaImportErrs struct { 72 Buckets map[string]BucketStatus `json:"buckets,omitempty"` 73 } 74 75 // ImportBucketMetadata makes an admin call to set bucket metadata of a bucket from imported content 76 func (adm *AdminClient) ImportBucketMetadata(ctx context.Context, bucket string, contentReader io.ReadCloser) (r BucketMetaImportErrs, err error) { 77 content, err := ioutil.ReadAll(contentReader) 78 if err != nil { 79 return r, err 80 } 81 82 path := adminAPIPrefix + "/import-bucket-metadata" 83 queryValues := url.Values{} 84 queryValues.Set("bucket", bucket) 85 86 resp, err := adm.executeMethod(ctx, 87 http.MethodPut, requestData{ 88 relPath: path, 89 queryValues: queryValues, 90 content: content, 91 }, 92 ) 93 defer closeResponse(resp) 94 95 if err != nil { 96 return r, err 97 } 98 99 if resp.StatusCode != http.StatusOK { 100 return r, httpRespToErrorResponse(resp) 101 } 102 103 err = json.NewDecoder(resp.Body).Decode(&r) 104 return r, err 105 }