def _CreateTopic(self, pubsub_topic, service_account):
    'Assures that a topic exists, creating it if necessary.\n\n    Also adds GCS as a publisher on that bucket, if necessary.\n\n    Args:\n      pubsub_topic: name of the Cloud Pub/Sub topic to use/create.\n      service_account: the GCS service account that needs publish permission.\n\n    Returns:\n      true if we modified IAM permissions, otherwise false.\n    '
    pubsub_api = PubsubApi(logger=self.logger)
    try:
        pubsub_api.GetTopic(topic_name=pubsub_topic)
        self.logger.debug('Topic %s already exists', pubsub_topic)
    except NotFoundException:
        self.logger.debug('Creating topic %s', pubsub_topic)
        pubsub_api.CreateTopic(topic_name=pubsub_topic)
        self.logger.info('Created Cloud Pub/Sub topic %s', pubsub_topic)
    policy = pubsub_api.GetTopicIamPolicy(topic_name=pubsub_topic)
    binding = Binding(role='roles/pubsub.publisher', members=[('serviceAccount:%s' % service_account)])
    if (binding not in policy.bindings):
        policy.bindings.append(binding)
        pubsub_api.SetTopicIamPolicy(topic_name=pubsub_topic, policy=policy)
        return True
    else:
        self.logger.debug('GCS already has publish permission to topic %s.', pubsub_topic)
        return False
Assures that a topic exists, creating it if necessary.

Also adds GCS as a publisher on that bucket, if necessary.

Args:
  pubsub_topic: name of the Cloud Pub/Sub topic to use/create.
  service_account: the GCS service account that needs publish permission.

Returns:
  true if we modified IAM permissions, otherwise false.
def _CreateTopic(self, pubsub_topic, service_account):
    'Assures that a topic exists, creating it if necessary.\n\n    Also adds GCS as a publisher on that bucket, if necessary.\n\n    Args:\n      pubsub_topic: name of the Cloud Pub/Sub topic to use/create.\n      service_account: the GCS service account that needs publish permission.\n\n    Returns:\n      true if we modified IAM permissions, otherwise false.\n    '
    pubsub_api = PubsubApi(logger=self.logger)
    try:
        pubsub_api.GetTopic(topic_name=pubsub_topic)
        self.logger.debug('Topic %s already exists', pubsub_topic)
    except NotFoundException:
        self.logger.debug('Creating topic %s', pubsub_topic)
        pubsub_api.CreateTopic(topic_name=pubsub_topic)
        self.logger.info('Created Cloud Pub/Sub topic %s', pubsub_topic)
    policy = pubsub_api.GetTopicIamPolicy(topic_name=pubsub_topic)
    binding = Binding(role='roles/pubsub.publisher', members=[('serviceAccount:%s' % service_account)])
    if (binding not in policy.bindings):
        policy.bindings.append(binding)
        pubsub_api.SetTopicIamPolicy(topic_name=pubsub_topic, policy=policy)
        return True
    else:
        self.logger.debug('GCS already has publish permission to topic %s.', pubsub_topic)
        return False