123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package minio
- import (
- "bytes"
- "context"
- "encoding/xml"
- "net/http"
- "net/url"
- "github.com/minio/minio-go/v7/pkg/s3utils"
- "github.com/minio/minio-go/v7/pkg/sse"
- )
- func (c Client) SetBucketEncryption(ctx context.Context, bucketName string, config *sse.Configuration) error {
-
- if err := s3utils.CheckValidBucketName(bucketName); err != nil {
- return err
- }
- if config == nil {
- return errInvalidArgument("configuration cannot be empty")
- }
- buf, err := xml.Marshal(config)
- 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
- }
- func (c Client) RemoveBucketEncryption(ctx context.Context, bucketName string) error {
-
- if err := s3utils.CheckValidBucketName(bucketName); err != nil {
- return err
- }
-
-
- urlValues := make(url.Values)
- urlValues.Set("encryption", "")
-
- resp, err := c.executeMethod(ctx, http.MethodDelete, requestMetadata{
- bucketName: bucketName,
- queryValues: urlValues,
- contentSHA256Hex: emptySHA256Hex,
- })
- defer closeResponse(resp)
- if err != nil {
- return err
- }
- if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
- return httpRespToErrorResponse(resp, bucketName, "")
- }
- return nil
- }
- func (c Client) GetBucketEncryption(ctx context.Context, bucketName string) (*sse.Configuration, error) {
-
- if err := s3utils.CheckValidBucketName(bucketName); err != nil {
- return nil, err
- }
-
-
- urlValues := make(url.Values)
- urlValues.Set("encryption", "")
-
- resp, err := c.executeMethod(ctx, http.MethodGet, requestMetadata{
- bucketName: bucketName,
- queryValues: urlValues,
- })
- defer closeResponse(resp)
- if err != nil {
- return nil, err
- }
- if resp.StatusCode != http.StatusOK {
- return nil, httpRespToErrorResponse(resp, bucketName, "")
- }
- encryptionConfig := &sse.Configuration{}
- if err = xmlDecoder(resp.Body, encryptionConfig); err != nil {
- return nil, err
- }
- return encryptionConfig, nil
- }
|