From 02653766f56e6482313e7598ca33cd794dd732b7 Mon Sep 17 00:00:00 2001 From: Simon So Date: Mon, 1 Apr 2019 14:12:13 -0700 Subject: [PATCH] fix error when there are no permissions to validate --- .../scripts/preconditions/preconditions.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/core_project_factory/scripts/preconditions/preconditions.py b/modules/core_project_factory/scripts/preconditions/preconditions.py index 653e45f16..7e7327eab 100755 --- a/modules/core_project_factory/scripts/preconditions/preconditions.py +++ b/modules/core_project_factory/scripts/preconditions/preconditions.py @@ -112,14 +112,23 @@ def __init__(self, org_id, shared_vpc=False, parent=False): self.permissions += self.PARENT_PERMISSIONS def validate(self, credentials): + body = {"permissions": self.permissions} + resource = "organizations/" + self.org_id + + # no permissions to validate + if len(self.permissions) == 0: + return { + "type": "Service account permissions on organization", + "name": "organizations/" + self.org_id, + "satisfied": [], + "unsatisfied": [] + } + service = discovery.build( 'cloudresourcemanager', 'v1', credentials=credentials ) - body = {"permissions": self.permissions} - resource = "organizations/" + self.org_id - request = service.organizations().testIamPermissions( resource=resource, body=body)