MCPcopy Create free account
hub / github.com/wal-e/wal-e / make_policy

Function make_policy

tests/s3_integration_help.py:82–112  ·  view source on GitHub ↗

Produces a S3 IAM text for selective access of data. Only a prefix can be listed, gotten, or written to when a credential is subject to this policy text.

(bucket_name, prefix, allow_get_location=False)

Source from the content-addressed store, hash-verified

80
81
82def make_policy(bucket_name, prefix, allow_get_location=False):
83 """Produces a S3 IAM text for selective access of data.
84
85 Only a prefix can be listed, gotten, or written to when a
86 credential is subject to this policy text.
87 """
88 bucket_arn = "arn:aws:s3:::" + bucket_name
89 prefix_arn = "arn:aws:s3:::{0}/{1}/*".format(bucket_name, prefix)
90
91 structure = {
92 "Version": "2012-10-17",
93 "Statement": [
94 {
95 "Action": ["s3:ListBucket"],
96 "Effect": "Allow",
97 "Resource": [bucket_arn],
98 "Condition": {"StringLike": {"s3:prefix": [prefix + '/*']}},
99 },
100 {
101 "Effect": "Allow",
102 "Action": ["s3:PutObject", "s3:GetObject"],
103 "Resource": [prefix_arn]
104 }]}
105
106 if allow_get_location:
107 structure["Statement"].append(
108 {"Action": ["s3:GetBucketLocation"],
109 "Effect": "Allow",
110 "Resource": [bucket_arn]})
111
112 return json.dumps(structure, indent=2)
113
114
115@pytest.fixture

Callers 4

test_policyFunction · 0.90
test_uri_put_fileFunction · 0.90
test_backup_listFunction · 0.90

Calls 1

formatMethod · 0.80

Tested by 4

test_policyFunction · 0.72
test_uri_put_fileFunction · 0.72
test_backup_listFunction · 0.72