Skip to content

Commit

Permalink
Rename 'readers'->'viewers', 'writers'->'editors'.
Browse files Browse the repository at this point in the history
Improve correspondence w/ role names used by pubsub.

Addresses:
#1654 (comment)
#1654 (comment).
  • Loading branch information
tseaver committed Mar 29, 2016
1 parent 21cfae6 commit e770e9e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 80 deletions.
16 changes: 8 additions & 8 deletions gcloud/pubsub/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __init__(self, etag=None, version=None):
self.etag = etag
self.version = version
self.owners = set()
self.writers = set()
self.readers = set()
self.editors = set()
self.viewers = set()

@staticmethod
def user(email):
Expand Down Expand Up @@ -128,9 +128,9 @@ def from_api_repr(cls, resource):
if role == OWNER_ROLE:
policy.owners = members
elif role == EDITOR_ROLE:
policy.writers = members
policy.editors = members
elif role == VIEWER_ROLE:
policy.readers = members
policy.viewers = members
else:
raise ValueError('Unknown role: %s' % (role,))
return policy
Expand All @@ -155,13 +155,13 @@ def to_api_repr(self):
bindings.append(
{'role': OWNER_ROLE, 'members': sorted(self.owners)})

if self.writers:
if self.editors:
bindings.append(
{'role': EDITOR_ROLE, 'members': sorted(self.writers)})
{'role': EDITOR_ROLE, 'members': sorted(self.editors)})

if self.readers:
if self.viewers:
bindings.append(
{'role': VIEWER_ROLE, 'members': sorted(self.readers)})
{'role': VIEWER_ROLE, 'members': sorted(self.viewers)})

if bindings:
resource['bindings'] = bindings
Expand Down
48 changes: 24 additions & 24 deletions gcloud/pubsub/test_iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_ctor_defaults(self):
self.assertEqual(policy.etag, None)
self.assertEqual(policy.version, None)
self.assertEqual(list(policy.owners), [])
self.assertEqual(list(policy.writers), [])
self.assertEqual(list(policy.readers), [])
self.assertEqual(list(policy.editors), [])
self.assertEqual(list(policy.viewers), [])

def test_ctor_explicit(self):
VERSION = 17
Expand All @@ -39,8 +39,8 @@ def test_ctor_explicit(self):
self.assertEqual(policy.etag, ETAG)
self.assertEqual(policy.version, VERSION)
self.assertEqual(list(policy.owners), [])
self.assertEqual(list(policy.writers), [])
self.assertEqual(list(policy.readers), [])
self.assertEqual(list(policy.editors), [])
self.assertEqual(list(policy.viewers), [])

def test_user(self):
EMAIL = 'phred@example.com'
Expand Down Expand Up @@ -83,33 +83,33 @@ def test_from_api_repr_only_etag(self):
self.assertEqual(policy.etag, 'ACAB')
self.assertEqual(policy.version, None)
self.assertEqual(list(policy.owners), [])
self.assertEqual(list(policy.writers), [])
self.assertEqual(list(policy.readers), [])
self.assertEqual(list(policy.editors), [])
self.assertEqual(list(policy.viewers), [])

def test_from_api_repr_complete(self):
from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE
OWNER1 = 'user:phred@example.com'
OWNER2 = 'group:cloud-logs@google.com'
WRITER1 = 'domain:google.com'
WRITER2 = 'user:phred@example.com'
READER1 = 'serviceAccount:1234-abcdef@service.example.com'
READER2 = 'user:phred@example.com'
EDITOR1 = 'domain:google.com'
EDITOR2 = 'user:phred@example.com'
VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com'
VIEWER2 = 'user:phred@example.com'
RESOURCE = {
'etag': 'DEADBEEF',
'version': 17,
'bindings': [
{'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]},
{'role': EDITOR_ROLE, 'members': [WRITER1, WRITER2]},
{'role': VIEWER_ROLE, 'members': [READER1, READER2]},
{'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]},
{'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]},
],
}
klass = self._getTargetClass()
policy = klass.from_api_repr(RESOURCE)
self.assertEqual(policy.etag, 'DEADBEEF')
self.assertEqual(policy.version, 17)
self.assertEqual(sorted(policy.owners), [OWNER2, OWNER1])
self.assertEqual(sorted(policy.writers), [WRITER1, WRITER2])
self.assertEqual(sorted(policy.readers), [READER1, READER2])
self.assertEqual(sorted(policy.editors), [EDITOR1, EDITOR2])
self.assertEqual(sorted(policy.viewers), [VIEWER1, VIEWER2])

def test_from_api_repr_bad_role(self):
BOGUS1 = 'user:phred@example.com'
Expand Down Expand Up @@ -137,24 +137,24 @@ def test_to_api_repr_full(self):
from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE
OWNER1 = 'group:cloud-logs@google.com'
OWNER2 = 'user:phred@example.com'
WRITER1 = 'domain:google.com'
WRITER2 = 'user:phred@example.com'
READER1 = 'serviceAccount:1234-abcdef@service.example.com'
READER2 = 'user:phred@example.com'
EDITOR1 = 'domain:google.com'
EDITOR2 = 'user:phred@example.com'
VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com'
VIEWER2 = 'user:phred@example.com'
EXPECTED = {
'etag': 'DEADBEEF',
'version': 17,
'bindings': [
{'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]},
{'role': EDITOR_ROLE, 'members': [WRITER1, WRITER2]},
{'role': VIEWER_ROLE, 'members': [READER1, READER2]},
{'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]},
{'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]},
],
}
policy = self._makeOne('DEADBEEF', 17)
policy.owners.add(OWNER1)
policy.owners.add(OWNER2)
policy.writers.add(WRITER1)
policy.writers.add(WRITER2)
policy.readers.add(READER1)
policy.readers.add(READER2)
policy.editors.add(EDITOR1)
policy.editors.add(EDITOR2)
policy.viewers.add(VIEWER1)
policy.viewers.add(VIEWER2)
self.assertEqual(policy.to_api_repr(), EXPECTED)
48 changes: 24 additions & 24 deletions gcloud/pubsub/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,17 @@ def test_get_iam_policy_w_bound_client(self):
from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE
OWNER1 = 'user:phred@example.com'
OWNER2 = 'group:cloud-logs@google.com'
WRITER1 = 'domain:google.com'
WRITER2 = 'user:phred@example.com'
READER1 = 'serviceAccount:1234-abcdef@service.example.com'
READER2 = 'user:phred@example.com'
EDITOR1 = 'domain:google.com'
EDITOR2 = 'user:phred@example.com'
VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com'
VIEWER2 = 'user:phred@example.com'
POLICY = {
'etag': 'DEADBEEF',
'version': 17,
'bindings': [
{'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]},
{'role': EDITOR_ROLE, 'members': [WRITER1, WRITER2]},
{'role': VIEWER_ROLE, 'members': [READER1, READER2]},
{'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]},
{'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]},
],
}
PROJECT = 'PROJECT'
Expand All @@ -517,8 +517,8 @@ def test_get_iam_policy_w_bound_client(self):
self.assertEqual(policy.etag, 'DEADBEEF')
self.assertEqual(policy.version, 17)
self.assertEqual(sorted(policy.owners), [OWNER2, OWNER1])
self.assertEqual(sorted(policy.writers), [WRITER1, WRITER2])
self.assertEqual(sorted(policy.readers), [READER1, READER2])
self.assertEqual(sorted(policy.editors), [EDITOR1, EDITOR2])
self.assertEqual(sorted(policy.viewers), [VIEWER1, VIEWER2])

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
Expand Down Expand Up @@ -547,8 +547,8 @@ def test_get_iam_policy_w_alternate_client(self):
self.assertEqual(policy.etag, 'ACAB')
self.assertEqual(policy.version, None)
self.assertEqual(sorted(policy.owners), [])
self.assertEqual(sorted(policy.writers), [])
self.assertEqual(sorted(policy.readers), [])
self.assertEqual(sorted(policy.editors), [])
self.assertEqual(sorted(policy.viewers), [])

self.assertEqual(len(conn1._requested), 0)
self.assertEqual(len(conn2._requested), 1)
Expand All @@ -561,17 +561,17 @@ def test_set_iam_policy_w_bound_client(self):
from gcloud.pubsub.iam import Policy
OWNER1 = 'group:cloud-logs@google.com'
OWNER2 = 'user:phred@example.com'
WRITER1 = 'domain:google.com'
WRITER2 = 'user:phred@example.com'
READER1 = 'serviceAccount:1234-abcdef@service.example.com'
READER2 = 'user:phred@example.com'
EDITOR1 = 'domain:google.com'
EDITOR2 = 'user:phred@example.com'
VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com'
VIEWER2 = 'user:phred@example.com'
POLICY = {
'etag': 'DEADBEEF',
'version': 17,
'bindings': [
{'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]},
{'role': EDITOR_ROLE, 'members': [WRITER1, WRITER2]},
{'role': VIEWER_ROLE, 'members': [READER1, READER2]},
{'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]},
{'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]},
],
}
RESPONSE = POLICY.copy()
Expand All @@ -590,18 +590,18 @@ def test_set_iam_policy_w_bound_client(self):
policy = Policy('DEADBEEF', 17)
policy.owners.add(OWNER1)
policy.owners.add(OWNER2)
policy.writers.add(WRITER1)
policy.writers.add(WRITER2)
policy.readers.add(READER1)
policy.readers.add(READER2)
policy.editors.add(EDITOR1)
policy.editors.add(EDITOR2)
policy.viewers.add(VIEWER1)
policy.viewers.add(VIEWER2)

new_policy = subscription.set_iam_policy(policy)

self.assertEqual(new_policy.etag, 'ABACABAF')
self.assertEqual(new_policy.version, 18)
self.assertEqual(sorted(new_policy.owners), [OWNER1, OWNER2])
self.assertEqual(sorted(new_policy.writers), [WRITER1, WRITER2])
self.assertEqual(sorted(new_policy.readers), [READER1, READER2])
self.assertEqual(sorted(new_policy.editors), [EDITOR1, EDITOR2])
self.assertEqual(sorted(new_policy.viewers), [VIEWER1, VIEWER2])

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
Expand Down Expand Up @@ -631,8 +631,8 @@ def test_set_iam_policy_w_alternate_client(self):
self.assertEqual(new_policy.etag, 'ACAB')
self.assertEqual(new_policy.version, None)
self.assertEqual(sorted(new_policy.owners), [])
self.assertEqual(sorted(new_policy.writers), [])
self.assertEqual(sorted(new_policy.readers), [])
self.assertEqual(sorted(new_policy.editors), [])
self.assertEqual(sorted(new_policy.viewers), [])

self.assertEqual(len(conn1._requested), 0)
self.assertEqual(len(conn2._requested), 1)
Expand Down
48 changes: 24 additions & 24 deletions gcloud/pubsub/test_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,17 @@ def test_get_iam_policy_w_bound_client(self):
from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE
OWNER1 = 'user:phred@example.com'
OWNER2 = 'group:cloud-logs@google.com'
WRITER1 = 'domain:google.com'
WRITER2 = 'user:phred@example.com'
READER1 = 'serviceAccount:1234-abcdef@service.example.com'
READER2 = 'user:phred@example.com'
EDITOR1 = 'domain:google.com'
EDITOR2 = 'user:phred@example.com'
VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com'
VIEWER2 = 'user:phred@example.com'
POLICY = {
'etag': 'DEADBEEF',
'version': 17,
'bindings': [
{'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]},
{'role': EDITOR_ROLE, 'members': [WRITER1, WRITER2]},
{'role': VIEWER_ROLE, 'members': [READER1, READER2]},
{'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]},
{'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]},
],
}
TOPIC_NAME = 'topic_name'
Expand All @@ -483,8 +483,8 @@ def test_get_iam_policy_w_bound_client(self):
self.assertEqual(policy.etag, 'DEADBEEF')
self.assertEqual(policy.version, 17)
self.assertEqual(sorted(policy.owners), [OWNER2, OWNER1])
self.assertEqual(sorted(policy.writers), [WRITER1, WRITER2])
self.assertEqual(sorted(policy.readers), [READER1, READER2])
self.assertEqual(sorted(policy.editors), [EDITOR1, EDITOR2])
self.assertEqual(sorted(policy.viewers), [VIEWER1, VIEWER2])

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
Expand All @@ -511,8 +511,8 @@ def test_get_iam_policy_w_alternate_client(self):
self.assertEqual(policy.etag, 'ACAB')
self.assertEqual(policy.version, None)
self.assertEqual(sorted(policy.owners), [])
self.assertEqual(sorted(policy.writers), [])
self.assertEqual(sorted(policy.readers), [])
self.assertEqual(sorted(policy.editors), [])
self.assertEqual(sorted(policy.viewers), [])

self.assertEqual(len(conn1._requested), 0)
self.assertEqual(len(conn2._requested), 1)
Expand All @@ -525,17 +525,17 @@ def test_set_iam_policy_w_bound_client(self):
from gcloud.pubsub.iam import OWNER_ROLE, EDITOR_ROLE, VIEWER_ROLE
OWNER1 = 'group:cloud-logs@google.com'
OWNER2 = 'user:phred@example.com'
WRITER1 = 'domain:google.com'
WRITER2 = 'user:phred@example.com'
READER1 = 'serviceAccount:1234-abcdef@service.example.com'
READER2 = 'user:phred@example.com'
EDITOR1 = 'domain:google.com'
EDITOR2 = 'user:phred@example.com'
VIEWER1 = 'serviceAccount:1234-abcdef@service.example.com'
VIEWER2 = 'user:phred@example.com'
POLICY = {
'etag': 'DEADBEEF',
'version': 17,
'bindings': [
{'role': OWNER_ROLE, 'members': [OWNER1, OWNER2]},
{'role': EDITOR_ROLE, 'members': [WRITER1, WRITER2]},
{'role': VIEWER_ROLE, 'members': [READER1, READER2]},
{'role': EDITOR_ROLE, 'members': [EDITOR1, EDITOR2]},
{'role': VIEWER_ROLE, 'members': [VIEWER1, VIEWER2]},
],
}
RESPONSE = POLICY.copy()
Expand All @@ -552,18 +552,18 @@ def test_set_iam_policy_w_bound_client(self):
policy = Policy('DEADBEEF', 17)
policy.owners.add(OWNER1)
policy.owners.add(OWNER2)
policy.writers.add(WRITER1)
policy.writers.add(WRITER2)
policy.readers.add(READER1)
policy.readers.add(READER2)
policy.editors.add(EDITOR1)
policy.editors.add(EDITOR2)
policy.viewers.add(VIEWER1)
policy.viewers.add(VIEWER2)

new_policy = topic.set_iam_policy(policy)

self.assertEqual(new_policy.etag, 'ABACABAF')
self.assertEqual(new_policy.version, 18)
self.assertEqual(sorted(new_policy.owners), [OWNER1, OWNER2])
self.assertEqual(sorted(new_policy.writers), [WRITER1, WRITER2])
self.assertEqual(sorted(new_policy.readers), [READER1, READER2])
self.assertEqual(sorted(new_policy.editors), [EDITOR1, EDITOR2])
self.assertEqual(sorted(new_policy.viewers), [VIEWER1, VIEWER2])

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
Expand Down Expand Up @@ -591,8 +591,8 @@ def test_set_iam_policy_w_alternate_client(self):
self.assertEqual(new_policy.etag, 'ACAB')
self.assertEqual(new_policy.version, None)
self.assertEqual(sorted(new_policy.owners), [])
self.assertEqual(sorted(new_policy.writers), [])
self.assertEqual(sorted(new_policy.readers), [])
self.assertEqual(sorted(new_policy.editors), [])
self.assertEqual(sorted(new_policy.viewers), [])

self.assertEqual(len(conn1._requested), 0)
self.assertEqual(len(conn2._requested), 1)
Expand Down

0 comments on commit e770e9e

Please sign in to comment.