Skip to content

Commit 7d9ee94

Browse files
committed
Add required IAM for notification topic.
1 parent da6dc1c commit 7d9ee94

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

storage/tests/system.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,26 @@ def topic_path(self):
567567
return 'projects/{}/topics/{}'.format(
568568
Config.CLIENT.project, self.TOPIC_NAME)
569569

570-
def setUp(self):
571-
self.case_buckets_to_delete = []
570+
def _intialize_topic(self):
572571
try:
573572
from google.cloud.pubsub_v1 import PublisherClient
574573
except ImportError:
575574
raise unittest.SkipTest("Cannot import pubsub")
576575
self.publisher_client = PublisherClient()
577576
retry_429(self.publisher_client.create_topic)(self.topic_path)
577+
policy = self.publisher_client.get_iam_policy(self.topic_path)
578+
binding = policy.bindings.add()
579+
binding.role = 'roles/pubsub.publisher'
580+
binding.members.append(
581+
'serviceAccount:{}'
582+
'@gs-project-accounts.iam.gserviceaccount.com'.format(
583+
Config.CLIENT.project))
584+
self.publisher_client.set_iam_policy(self.topic_path, policy)
585+
586+
587+
def setUp(self):
588+
self.case_buckets_to_delete = []
589+
self._intialize_topic()
578590

579591
def tearDown(self):
580592
retry_429(self.publisher_client.delete_topic)(self.topic_path)

0 commit comments

Comments
 (0)