func (c Client) SetBucketEncryptionWithContext(ctx context.Context, bucketName string, configuration ServerSideEncryptionConfiguration) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	buf, err := xml.Marshal(&configuration)
	if err != nil {
		return err
	}
	urlValues := make(url.Values)
	urlValues.Set("encryption", "")
	reqMetadata := requestMetadata{
		bucketName:       bucketName,
		queryValues:      urlValues,
		contentBody:      bytes.NewReader(buf),
		contentLength:    int64(len(buf)),
		contentMD5Base64: sumMD5Base64(buf),
	}
	resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata)
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	if resp.StatusCode != http.StatusOK {
		return httpRespToErrorResponse(resp, bucketName, "")
	}
	return nil
}
SetBucketEncryptionWithContext sets the default encryption configuration on an existing bucket with a context to control cancellations and timeouts.
package minio
import (
	"bytes"
	"context"
	"encoding/xml"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
	"github.com/minio/minio-go/v6/pkg/s3utils"
)
type ApplyServerSideEncryptionByDefault struct {
	KmsMasterKeyID string `xml:"KMSMasterKeyID,omitempty"`
	SSEAlgorithm   string `xml:"SSEAlgorithm"`
}
type Rule struct {
	Apply ApplyServerSideEncryptionByDefault `xml:"ApplyServerSideEncryptionByDefault"`
}
type ServerSideEncryptionConfiguration struct {
	XMLName xml.Name `xml:"ServerSideEncryptionConfiguration"`
	Rules   []Rule   `xml:"Rule"`
}
func (c Client) makeBucket(ctx context.Context, bucketName string, location string, objectLockEnabled bool) (err error) {
	if err := s3utils.CheckValidBucketNameStrict(bucketName); err != nil {
		return err
	}
	err = c.doMakeBucket(ctx, bucketName, location, objectLockEnabled)
	if err != nil && (location == "" || location == "us-east-1") {
		if resp, ok := err.(ErrorResponse); ok && resp.Code == "AuthorizationHeaderMalformed" && resp.Region != "" {
			err = c.doMakeBucket(ctx, bucketName, resp.Region, objectLockEnabled)
		}
	}
	return err
}
func (c Client) doMakeBucket(ctx context.Context, bucketName string, location string, objectLockEnabled bool) (err error) {
	defer func() {
		if err == nil {
			c.bucketLocCache.Set(bucketName, location)
		}
	}()
	if location == "" {
		location = "us-east-1"
		if c.region != "" {
			location = c.region
		}
	}
	reqMetadata := requestMetadata{
		bucketName:     bucketName,
		bucketLocation: location,
	}
	if objectLockEnabled {
		headers := make(http.Header)
		headers.Add("x-amz-bucket-object-lock-enabled", "true")
		reqMetadata.customHeader = headers
	}
	if location != "us-east-1" && location != "" {
		createBucketConfig := createBucketConfiguration{}
		createBucketConfig.Location = location
		var createBucketConfigBytes []byte
		createBucketConfigBytes, err = xml.Marshal(createBucketConfig)
		if err != nil {
			return err
		}
		reqMetadata.contentMD5Base64 = sumMD5Base64(createBucketConfigBytes)
		reqMetadata.contentSHA256Hex = sum256Hex(createBucketConfigBytes)
		reqMetadata.contentBody = bytes.NewReader(createBucketConfigBytes)
		reqMetadata.contentLength = int64(len(createBucketConfigBytes))
	}
	resp, err := c.executeMethod(ctx, "PUT", reqMetadata)
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode != http.StatusOK {
			return httpRespToErrorResponse(resp, bucketName, "")
		}
	}
	return nil
}
func (c Client) MakeBucket(bucketName string, location string) (err error) {
	return c.MakeBucketWithContext(context.Background(), bucketName, location)
}
func (c Client) MakeBucketWithContext(ctx context.Context, bucketName string, location string) (err error) {
	return c.makeBucket(ctx, bucketName, location, false)
}
func (c Client) MakeBucketWithObjectLock(bucketName string, location string) (err error) {
	return c.MakeBucketWithObjectLockWithContext(context.Background(), bucketName, location)
}
func (c Client) MakeBucketWithObjectLockWithContext(ctx context.Context, bucketName string, location string) (err error) {
	return c.makeBucket(ctx, bucketName, location, true)
}
func (c Client) SetBucketPolicy(bucketName, policy string) error {
	return c.SetBucketPolicyWithContext(context.Background(), bucketName, policy)
}
func (c Client) SetBucketPolicyWithContext(ctx context.Context, bucketName, policy string) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	if policy == "" {
		return c.removeBucketPolicy(ctx, bucketName)
	}
	return c.putBucketPolicy(ctx, bucketName, policy)
}
func (c Client) putBucketPolicy(ctx context.Context, bucketName, policy string) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	urlValues := make(url.Values)
	urlValues.Set("policy", "")
	policyReader := strings.NewReader(policy)
	b, err := ioutil.ReadAll(policyReader)
	if err != nil {
		return err
	}
	reqMetadata := requestMetadata{
		bucketName:    bucketName,
		queryValues:   urlValues,
		contentBody:   policyReader,
		contentLength: int64(len(b)),
	}
	resp, err := c.executeMethod(ctx, "PUT", reqMetadata)
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode != http.StatusNoContent {
			return httpRespToErrorResponse(resp, bucketName, "")
		}
	}
	return nil
}
func (c Client) removeBucketPolicy(ctx context.Context, bucketName string) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	urlValues := make(url.Values)
	urlValues.Set("policy", "")
	resp, err := c.executeMethod(ctx, "DELETE", requestMetadata{
		bucketName:       bucketName,
		queryValues:      urlValues,
		contentSHA256Hex: emptySHA256Hex,
	})
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	return nil
}
func (c Client) SetBucketLifecycle(bucketName, lifecycle string) error {
	return c.SetBucketLifecycleWithContext(context.Background(), bucketName, lifecycle)
}
func (c Client) SetBucketLifecycleWithContext(ctx context.Context, bucketName, lifecycle string) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	if lifecycle == "" {
		return c.removeBucketLifecycle(ctx, bucketName)
	}
	return c.putBucketLifecycle(ctx, bucketName, lifecycle)
}
func (c Client) putBucketLifecycle(ctx context.Context, bucketName, lifecycle string) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	urlValues := make(url.Values)
	urlValues.Set("lifecycle", "")
	lifecycleReader := strings.NewReader(lifecycle)
	b, err := ioutil.ReadAll(lifecycleReader)
	if err != nil {
		return err
	}
	reqMetadata := requestMetadata{
		bucketName:       bucketName,
		queryValues:      urlValues,
		contentBody:      lifecycleReader,
		contentLength:    int64(len(b)),
		contentMD5Base64: sumMD5Base64(b),
	}
	resp, err := c.executeMethod(ctx, "PUT", reqMetadata)
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	if resp != nil {
		if resp.StatusCode != http.StatusOK {
			return httpRespToErrorResponse(resp, bucketName, "")
		}
	}
	return nil
}
func (c Client) removeBucketLifecycle(ctx context.Context, bucketName string) error {
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return err
	}
	urlValues := make(url.Values)
	urlValues.Set("lifecycle", "")
	resp, err := c.executeMethod(ctx, "DELETE", requestMetadata{
		bucketName:       bucketName,
		queryValues:      urlValues,
		contentSHA256Hex: emptySHA256Hex,
	})
	defer closeResponse(resp)
	if err != nil {
		return err
	}
	return nil
}
func (c Client) SetBucketEncryption(bucketName string, configuration ServerSideEncryptionConfiguration) error {
	return c.SetBucketEncryptionWithContext(context.Background(), bucketName, configuration)
}