mirror of
https://github.com/ceph/s3-tests.git
synced 2024-12-23 03:41:35 +00:00
policy: refactor make_json_policy to use the new Policy classes
since make_json_policy is redundantly doing most of the same work, refactor to use the new policy classes instead Signed-off-by: Abhishek Lekshmanan <abhishek@suse.com>
This commit is contained in:
parent
47e3772e0b
commit
5da742036e
2 changed files with 9 additions and 23 deletions
|
@ -36,3 +36,11 @@ class Policy(object):
|
|||
}
|
||||
|
||||
return json.dumps(policy_dict)
|
||||
|
||||
def make_json_policy(action, resource, principal={"AWS": "*"}, conditions=None):
|
||||
"""
|
||||
Helper function to make single statement policies
|
||||
"""
|
||||
s = Statement(action, resource, principal, condition=conditions)
|
||||
p = Policy()
|
||||
return p.add_statement(s).to_json()
|
||||
|
|
|
@ -44,7 +44,7 @@ from .utils import assert_raises
|
|||
from .utils import generate_random
|
||||
from .utils import region_sync_meta
|
||||
|
||||
from .policy import Policy, Statement
|
||||
from .policy import Policy, Statement, make_json_policy
|
||||
|
||||
import AnonymousAuth
|
||||
|
||||
|
@ -8744,28 +8744,6 @@ def test_sse_kms_read_declare():
|
|||
def _make_arn_resource(path="*"):
|
||||
return "arn:aws:s3:::{}".format(path)
|
||||
|
||||
def make_json_policy(action, resource, principal={"AWS": "*"}, conditions=None):
|
||||
|
||||
policy = {
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{
|
||||
"Effect": "Allow",
|
||||
"Principal": principal,
|
||||
"Action": action,
|
||||
"Resource": [
|
||||
resource
|
||||
],
|
||||
}]
|
||||
}
|
||||
|
||||
# Currently lets only support adding a common conditional to every
|
||||
# statement in this function
|
||||
for statement in policy["Statement"]:
|
||||
if conditions is not None:
|
||||
statement["Condition"] = conditions
|
||||
|
||||
return json.dumps(policy)
|
||||
|
||||
@attr(resource='bucket')
|
||||
@attr(method='get')
|
||||
@attr(operation='Test Bucket Policy')
|
||||
|
|
Loading…
Reference in a new issue