SetBucketPolicy sets the access permissions policy on an existing bucket. The policy should be a valid JSON string that conforms to the IAM policy format. If policy is an empty string, the existing bucket policy will be removed. Parameters: - ctx: Context for request cancellation and timeout - buck
(ctx context.Context, bucketName, policy string)
| 37 | // |
| 38 | // Returns an error if the operation fails. |
| 39 | func (c *Client) SetBucketPolicy(ctx context.Context, bucketName, policy string) error { |
| 40 | // Input validation. |
| 41 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | // If policy is empty then delete the bucket policy. |
| 46 | if policy == "" { |
| 47 | return c.removeBucketPolicy(ctx, bucketName) |
| 48 | } |
| 49 | |
| 50 | // Save the updated policies. |
| 51 | return c.putBucketPolicy(ctx, bucketName, policy) |
| 52 | } |
| 53 | |
| 54 | // Saves a new bucket policy. |
| 55 | func (c *Client) putBucketPolicy(ctx context.Context, bucketName, policy string) error { |
no test coverage detected