Skip to content

Commit 4d5fd71

Browse files
committed
adds check to set_bucket_policy
1 parent a01697f commit 4d5fd71

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

minio/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
get_sha256_hexdigest, get_md5_base64digest, Hasher,
7373
optimal_part_info,
7474
is_valid_bucket_name, PartMetadata, read_full,
75-
is_valid_bucket_notification_config,
75+
is_valid_bucket_notification_config, is_valid_bucket_type_policy,
7676
get_s3_region_from_endpoint,
7777
mkdir_p, dump_http, amzprefix_user_metadata,
7878
is_supported_header,is_amz_header)
@@ -387,8 +387,9 @@ def set_bucket_policy(self, bucket_name, policy):
387387
Set bucket policy of given bucket name.
388388
389389
:param bucket_name: Bucket name.
390-
:param policy: Access policy/ies in JSON format.
390+
:param policy: Access policy/ies in string format.
391391
"""
392+
is_valid_bucket_type_policy(policy)
392393
is_valid_bucket_name(bucket_name)
393394

394395
headers = {

minio/helpers.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import math
4040

4141
from .compat import (urlsplit, urlencode, queryencode,
42-
str, bytes, basestring)
42+
str, bytes, basestring, _is_py2, _is_py3)
4343
from .error import (InvalidBucketError, InvalidEndpointError,
4444
InvalidArgumentError)
4545

@@ -375,6 +375,23 @@ def is_non_empty_string(input_string):
375375

376376
return True
377377

378+
def is_valid_bucket_type_policy(policy):
379+
"""
380+
Validate if policy is type str
381+
382+
:param policy: S3 style Bucket policy.
383+
:return: True if policy parameter is of a valid type, 'string'.
384+
Raise :exc:`TypeError` otherwise.
385+
"""
386+
if _is_py3:
387+
string_types = str,
388+
elif _is_py2:
389+
string_types = basestring
390+
391+
if not isinstance(policy, string_types):
392+
raise TypeError('policy can only be of type str')
393+
is_non_empty_string(policy)
394+
return True
378395

379396
def is_valid_bucket_notification_config(notifications):
380397
"""

0 commit comments

Comments
 (0)