MCPcopy
hub / github.com/minio/minio-go / SetBucketEncryption

Method SetBucketEncryption

api-bucket-encryption.go:39–78  ·  view source on GitHub ↗

SetBucketEncryption sets the default encryption configuration on an existing bucket. The encryption configuration specifies the default encryption behavior for objects uploaded to the bucket. Parameters: - ctx: Context for request cancellation and timeout - bucketName: Name of the bucket - config:

(ctx context.Context, bucketName string, config *sse.Configuration)

Source from the content-addressed store, hash-verified

37//
38// Returns an error if the operation fails or if config is nil.
39func (c *Client) SetBucketEncryption(ctx context.Context, bucketName string, config *sse.Configuration) error {
40 // Input validation.
41 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
42 return err
43 }
44
45 if config == nil {
46 return errInvalidArgument("configuration cannot be empty")
47 }
48
49 buf, err := xml.Marshal(config)
50 if err != nil {
51 return err
52 }
53
54 // Get resources properly escaped and lined up before
55 // using them in http request.
56 urlValues := make(url.Values)
57 urlValues.Set("encryption", "")
58
59 // Content-length is mandatory to set a default encryption configuration
60 reqMetadata := requestMetadata{
61 bucketName: bucketName,
62 queryValues: urlValues,
63 contentBody: bytes.NewReader(buf),
64 contentLength: int64(len(buf)),
65 contentMD5Base64: sumMD5Base64(buf),
66 }
67
68 // Execute PUT to upload a new bucket default encryption configuration.
69 resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata)
70 defer closeResponse(resp)
71 if err != nil {
72 return err
73 }
74 if resp.StatusCode != http.StatusOK {
75 return httpRespToErrorResponse(resp, bucketName, "")
76 }
77 return nil
78}
79
80// RemoveBucketEncryption removes the default encryption configuration from a bucket.
81// After removal, the bucket will no longer apply default encryption to new objects.

Callers 1

mainFunction · 0.80

Calls 8

executeMethodMethod · 0.95
CheckValidBucketNameFunction · 0.92
errInvalidArgumentFunction · 0.85
sumMD5Base64Function · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
MarshalMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected