github.com/minio/minio-go/v6@v6.0.57/api-get-bucket-encryption.go (about) 1 /* 2 * MinIO Go Library for Amazon S3 Compatible Cloud Storage 3 * Copyright 2020 MinIO, Inc. 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 minio 18 19 import ( 20 "context" 21 "encoding/xml" 22 "io/ioutil" 23 "net/http" 24 "net/url" 25 26 "github.com/minio/minio-go/v6/pkg/s3utils" 27 ) 28 29 // GetBucketEncryption - get default encryption configuration for a bucket. 30 func (c Client) GetBucketEncryption(bucketName string) (ServerSideEncryptionConfiguration, error) { 31 return c.GetBucketEncryptionWithContext(context.Background(), bucketName) 32 } 33 34 // GetBucketEncryptionWithContext gets the default encryption configuration on an existing bucket with a context to control cancellations and timeouts. 35 func (c Client) GetBucketEncryptionWithContext(ctx context.Context, bucketName string) (ServerSideEncryptionConfiguration, error) { 36 // Input validation. 37 if err := s3utils.CheckValidBucketName(bucketName); err != nil { 38 return ServerSideEncryptionConfiguration{}, err 39 } 40 41 // Get resources properly escaped and lined up before 42 // using them in http request. 43 urlValues := make(url.Values) 44 urlValues.Set("encryption", "") 45 46 // Execute GET on bucket to get the default encryption configuration. 47 resp, err := c.executeMethod(ctx, http.MethodGet, requestMetadata{ 48 bucketName: bucketName, 49 queryValues: urlValues, 50 }) 51 52 defer closeResponse(resp) 53 if err != nil { 54 return ServerSideEncryptionConfiguration{}, err 55 } 56 57 if resp.StatusCode != http.StatusOK { 58 return ServerSideEncryptionConfiguration{}, httpRespToErrorResponse(resp, bucketName, "") 59 } 60 61 bucketEncryptionBuf, err := ioutil.ReadAll(resp.Body) 62 if err != nil { 63 return ServerSideEncryptionConfiguration{}, err 64 } 65 66 encryptionConfig := ServerSideEncryptionConfiguration{} 67 if err := xml.Unmarshal(bucketEncryptionBuf, &encryptionConfig); err != nil { 68 return ServerSideEncryptionConfiguration{}, err 69 } 70 return encryptionConfig, nil 71 }