From 69319001f2620a8e32f535d3f6fb2f945846664b Mon Sep 17 00:00:00 2001 From: Jonathan Lui Date: Mon, 6 Jan 2020 17:43:51 -0800 Subject: [PATCH] fix pytype error --- api_core/google/api_core/iam.py | 37 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/api_core/google/api_core/iam.py b/api_core/google/api_core/iam.py index 742aebfb2bb5..8b3f89b501bf 100644 --- a/api_core/google/api_core/iam.py +++ b/api_core/google/api_core/iam.py @@ -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 @@ -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 }, ... ] @@ -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: