Skip to content

Commit b97cbb0

Browse files
committed
add docs on dict access
1 parent d4a4746 commit b97cbb0

2 files changed

Lines changed: 48 additions & 13 deletions

File tree

api_core/google/api_core/iam.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,23 @@ class InvalidOperationException(Exception):
9090
class Policy(collections_abc.MutableMapping):
9191
"""IAM Policy
9292
93-
See
94-
https://cloud.google.com/iam/reference/rest/v1/Policy
95-
9693
Args:
9794
etag (Optional[str]): ETag used to identify a unique of the policy
9895
version (Optional[int]): The syntax schema version of the policy.
9996
97+
Note:
98+
Using conditions in bindings requires the policy's version to be set
99+
to `3` or greater, depending on the versions that are currently supported.
100+
101+
Accessing the policy using dict operations will raise InvalidOperationException
102+
when the policy's version is set to 3.
103+
104+
Use the policy.bindings getter/setter to retrieve and modify the policy's bindings.
105+
106+
See:
107+
IAM Policy https://cloud.google.com/iam/reference/rest/v1/Policy
108+
Policy versions https://cloud.google.com/iam/docs/policies#versions
109+
Conditions overview https://cloud.google.com/iam/docs/conditions-overview.
100110
"""
101111

102112
_OWNER_ROLES = (OWNER_ROLE,)
@@ -146,7 +156,7 @@ def __delitem__(self, key):
146156
raise KeyError(key)
147157

148158
def __check_version__(self):
149-
"""Raise InvalidOperationException if version is greater than 1."""
159+
"""Raise InvalidOperationException if version is greater than 1 or policy contains conditions."""
150160
raise_version = self.version is not None and self.version > 1
151161

152162
if raise_version or self._contains_conditions():
@@ -171,15 +181,6 @@ def bindings(self):
171181
description (:obj:str, optional): Description of the condition.
172182
expression: A CEL expression.
173183
174-
Note:
175-
Using conditions in bindings requires the policy's version to be set
176-
to `3` or greater, depending on the versions that are currently supported.
177-
178-
Accessing the policy using dict operations will raise InvalidOperationException
179-
when the policy's version is set to 3.
180-
181-
Use the policy.bindings getter/setter to retrieve and modify the policy's bindings.
182-
183184
See:
184185
Policy versions https://cloud.google.com/iam/docs/policies#versions
185186
Conditions overview https://cloud.google.com/iam/docs/conditions-overview.
@@ -216,6 +217,8 @@ def bindings(self, bindings):
216217
def owners(self):
217218
"""Legacy access to owner role.
218219
220+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
221+
219222
DEPRECATED: use `policy.bindings` to access bindings instead.
220223
"""
221224
result = set()
@@ -228,6 +231,8 @@ def owners(self):
228231
def owners(self, value):
229232
"""Update owners.
230233
234+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
235+
231236
DEPRECATED: use `policy.bindings` to access bindings instead.
232237
"""
233238
warnings.warn(
@@ -239,6 +244,8 @@ def owners(self, value):
239244
def editors(self):
240245
"""Legacy access to editor role.
241246
247+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
248+
242249
DEPRECATED: use `policy.bindings` to access bindings instead.
243250
"""
244251
result = set()
@@ -251,6 +258,8 @@ def editors(self):
251258
def editors(self, value):
252259
"""Update editors.
253260
261+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
262+
254263
DEPRECATED: use `policy.bindings` to modify bindings instead.
255264
"""
256265
warnings.warn(
@@ -263,6 +272,8 @@ def editors(self, value):
263272
def viewers(self):
264273
"""Legacy access to viewer role.
265274
275+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
276+
266277
DEPRECATED: use `policy.bindings` to modify bindings instead.
267278
"""
268279
result = set()
@@ -275,6 +286,8 @@ def viewers(self):
275286
def viewers(self, value):
276287
"""Update viewers.
277288
289+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
290+
278291
DEPRECATED: use `policy.bindings` to modify bindings instead.
279292
"""
280293
warnings.warn(

bigtable/google/cloud/bigtable/policy.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ class Policy(BasePolicy):
7474
existing policy is overwritten blindly.
7575
:type version: int
7676
:param version: The syntax schema version of the policy.
77+
78+
Note:
79+
Using conditions in bindings requires the policy's version to be set
80+
to `3` or greater, depending on the versions that are currently supported.
81+
82+
Accessing the policy using dict operations will raise InvalidOperationException
83+
when the policy's version is set to 3.
84+
85+
Use the policy.bindings getter/setter to retrieve and modify the policy's bindings.
86+
87+
See:
88+
IAM Policy https://cloud.google.com/iam/reference/rest/v1/Policy
89+
Policy versions https://cloud.google.com/iam/docs/policies#versions
90+
Conditions overview https://cloud.google.com/iam/docs/conditions-overview.
7791
"""
7892

7993
def __init__(self, etag=None, version=None):
@@ -85,6 +99,8 @@ def __init__(self, etag=None, version=None):
8599
def bigtable_admins(self):
86100
"""Access to bigtable.admin role memebers
87101
102+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
103+
88104
For example:
89105
90106
.. literalinclude:: snippets.py
@@ -100,6 +116,8 @@ def bigtable_admins(self):
100116
def bigtable_readers(self):
101117
"""Access to bigtable.reader role memebers
102118
119+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
120+
103121
For example:
104122
105123
.. literalinclude:: snippets.py
@@ -115,6 +133,8 @@ def bigtable_readers(self):
115133
def bigtable_users(self):
116134
"""Access to bigtable.user role memebers
117135
136+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
137+
118138
For example:
119139
120140
.. literalinclude:: snippets.py
@@ -130,6 +150,8 @@ def bigtable_users(self):
130150
def bigtable_viewers(self):
131151
"""Access to bigtable.viewer role memebers
132152
153+
Raise InvalidOperationException if version is greater than 1 or policy contains conditions.
154+
133155
For example:
134156
135157
.. literalinclude:: snippets.py

0 commit comments

Comments
 (0)