Skip to content

Commit

Permalink
fix pytype error
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwlui committed Jan 7, 2020
1 parent 1265c7e commit 6931900
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions api_core/google/api_core/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,27 @@ def bindings(self):
""":obj:`list` of :obj:`dict`: The policy's bindings list.
A binding is specified by a dictionary with keys:
role (str): Role that is assigned to `members`.
members (:obj:`set` of str): Specifies the identities associated to this binding.
condition (dict of str:str): Specifies a condition under which this binding will apply.
- title (str): Title for the condition.
- description (:obj:str, optional): Description of the condition.
- expression: A CEL expression.
role (str): Role that is assigned to `members`.
members (:obj:`set` of str): Specifies the identities associated to this binding.
condition (dict of str:str): Specifies a condition under which this binding will apply.
- title (str): Title for the condition.
- description (:obj:str, optional): Description of the condition.
- expression: A CEL expression.
See:
Policy versions https://cloud.google.com/iam/docs/policies#versions
Conditions overview https://cloud.google.com/iam/docs/conditions-overview.
Policy versions https://cloud.google.com/iam/docs/policies#versions
Conditions overview https://cloud.google.com/iam/docs/conditions-overview.
Example:
.. code-block:: python
USER = "user:phred@example.com"
ADMIN_GROUP = "group:admins@groups.example.com"
SERVICE_ACCOUNT = "serviceAccount:account-1234@accounts.example.com"
condition = {
"title": "request_time",
"description": "Requests made before 2021-01-01T00:00:00Z", # Optional
"expression": "request.time < timestamp(\"2021-01-01T00:00:00Z\")"
}
# Set policy's version to 3 before setting bindings containing conditions.
policy.version = 3
Expand All @@ -197,11 +202,7 @@ def bindings(self):
{
"role": "roles/viewer",
"members": {USER, ADMIN_GROUP, SERVICE_ACCOUNT},
"condition": {
"title": "request_time",
"description": "Requests made before 2021-01-01T00:00:00Z", # Optional
"expression": "request.time < timestamp(\"2021-01-01T00:00:00Z\")"
}
"condition": CONDITION
},
...
]
Expand Down Expand Up @@ -429,13 +430,15 @@ def to_api_repr(self):
if self._bindings and len(self._bindings) > 0:
bindings = []
for binding in self._bindings:
if binding["members"]:
members = binding.get("members")
if members:
new_binding = {
"role": binding["role"],
"members": sorted(binding["members"])
"members": sorted(members)
}
if binding.get("condition"):
new_binding["condition"] = binding["condition"]
condition = binding.get("condition")
if condition:
new_binding["condition"] = condition
bindings.append(new_binding)

if bindings:
Expand Down

0 comments on commit 6931900

Please sign in to comment.