]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
policy: refactor make_json_policy to use the new Policy classes 191/head
authorAbhishek Lekshmanan <abhishek@suse.com>
Mon, 6 Nov 2017 15:47:05 +0000 (16:47 +0100)
committerAbhishek Lekshmanan <abhishek@suse.com>
Wed, 17 Jan 2018 09:56:33 +0000 (10:56 +0100)
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>
s3tests/functional/policy.py
s3tests/functional/test_s3.py

index 910461a191bdcb8987aaf6bd8029eb3f3af04513..aae54549e2a0b947e50b7bda394757ee6cbf3364 100644 (file)
@@ -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()
index 728766c45e644c7badbd9e21a1ae2957aabceb9a..12b065a6d6984689b4d30f48ef759b96681cb4ea 100644 (file)
@@ -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')