GetBucketPolicy retrieves the access permissions policy for the bucket. If no bucket policy exists, returns an empty string with no error. Parameters: - ctx: Context for request cancellation and timeout - bucketName: Name of the bucket Returns the policy as a JSON string or an error if the operati
(ctx context.Context, bucketName string)
| 113 | // |
| 114 | // Returns the policy as a JSON string or an error if the operation fails. |
| 115 | func (c *Client) GetBucketPolicy(ctx context.Context, bucketName string) (string, error) { |
| 116 | // Input validation. |
| 117 | if err := s3utils.CheckValidBucketName(bucketName); err != nil { |
| 118 | return "", err |
| 119 | } |
| 120 | bucketPolicy, err := c.getBucketPolicy(ctx, bucketName) |
| 121 | if err != nil { |
| 122 | errResponse := ToErrorResponse(err) |
| 123 | if errResponse.Code == NoSuchBucketPolicy { |
| 124 | return "", nil |
| 125 | } |
| 126 | return "", err |
| 127 | } |
| 128 | return bucketPolicy, nil |
| 129 | } |
| 130 | |
| 131 | // Request server for current bucket policy. |
| 132 | func (c *Client) getBucketPolicy(ctx context.Context, bucketName string) (string, error) { |
no test coverage detected