def set_iam_policy(self, policy, client=None): """Update the IAM policy for the topic. See: https://cloud.google.com/pubsub/reference/rest/v1/projects.topics/setIamPolicy Example: .. literalinclude:: pubsub_snippets.py :start-after: [START topic_set_iam_policy] :end-before: [END topic_set_iam_policy] :type policy: :class:`google.cloud.pubsub.iam.Policy` :param policy: the new policy, typically fetched via :meth:`get_iam_policy` and updated in place. :type client: :class:`~google.cloud.pubsub.client.Client` or ``NoneType`` :param client: the client to use. If not passed, falls back to the ``client`` stored on the current batch. :rtype: :class:`google.cloud.pubsub.iam.Policy` :returns: updated policy created from the resource returned by the ``setIamPolicy`` API request. """ client = self._require_client(client) api = client.iam_policy_api resource = policy.to_api_repr() resp = api.set_iam_policy(self.full_name, resource) return Policy.from_api_repr(resp)
def get_iam_policy(self, client=None): """Fetch the IAM policy for the subscription. See: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/getIamPolicy Example: .. literalinclude:: pubsub_snippets.py :start-after: [START subscription_get_iam_policy] :end-before: [END subscription_get_iam_policy] :type client: :class:`~google.cloud.pubsub.client.Client` or ``NoneType`` :param client: the client to use. If not passed, falls back to the ``client`` stored on the current subscription's topic. :rtype: :class:`google.cloud.pubsub.iam.Policy` :returns: policy created from the resource returned by the ``getIamPolicy`` API request. """ client = self._require_client(client) api = client.iam_policy_api resp = api.get_iam_policy(self.full_name) return Policy.from_api_repr(resp)
def set_iam_policy(self, policy, client=None): """Update the IAM policy for the topic. See: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/setIamPolicy Example: .. literalinclude:: pubsub_snippets.py :start-after: [START topic_set_iam_policy] :end-before: [END topic_set_iam_policy] :type policy: :class:`google.cloud.pubsub.iam.Policy` :param policy: the new policy, typically fetched via :meth:`get_iam_policy` and updated in place. :type client: :class:`~google.cloud.pubsub.client.Client` or ``NoneType`` :param client: the client to use. If not passed, falls back to the ``client`` stored on the current batch. :rtype: :class:`google.cloud.pubsub.iam.Policy` :returns: updated policy created from the resource returned by the ``setIamPolicy`` API request. """ client = self._require_client(client) api = client.iam_policy_api resource = policy.to_api_repr() resp = api.set_iam_policy(self.full_name, resource) return Policy.from_api_repr(resp)