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