示例#1
0
    def __init__(
        self, channel=None, credentials=None, address="pubsub.googleapis.com:443"
    ):
        """Instantiate the transport class.

        Args:
            channel (grpc.Channel): A ``Channel`` instance through
                which to make calls. This argument is mutually exclusive
                with ``credentials``; providing both will raise an exception.
            credentials (google.auth.credentials.Credentials): The
                authorization credentials to attach to requests. These
                credentials identify this application to the service. If none
                are specified, the client will attempt to ascertain the
                credentials from the environment.
            address (str): The address where the service is hosted.
        """
        # If both `channel` and `credentials` are specified, raise an
        # exception (channels come with credentials baked in already).
        if channel is not None and credentials is not None:
            raise ValueError(
                "The `channel` and `credentials` arguments are mutually " "exclusive."
            )

        # Create the channel.
        if channel is None:
            channel = self.create_channel(address=address, credentials=credentials)

        self._channel = channel

        # gRPC uses objects called "stubs" that are bound to the
        # channel and provide a basic method for each RPC.
        self._stubs = {
            "iam_policy_stub": iam_policy_pb2.IAMPolicyStub(channel),
            "publisher_stub": pubsub_pb2_grpc.PublisherStub(channel),
        }
    def __init__(self,
                 transport=None,
                 channel=None,
                 credentials=None,
                 client_config=publisher_client_config.config,
                 client_info=None):
        """Constructor.

        Args:
            transport (Union[~.PublisherGrpcTransport,
                    Callable[[~.Credentials, type], ~.PublisherGrpcTransport]): A transport
                instance, responsible for actually making the API calls.
                The default transport uses the gRPC protocol.
                This argument may also be a callable which returns a
                transport instance. Callables will be sent the credentials
                as the first argument and the default transport class as
                the second argument.
            channel (grpc.Channel): DEPRECATED. A ``Channel`` instance
                through which to make calls. This argument is mutually exclusive
                with ``credentials``; providing both will raise an exception.
            credentials (google.auth.credentials.Credentials): The
                authorization credentials to attach to requests. These
                credentials identify this application to the service. If none
                are specified, the client will attempt to ascertain the
                credentials from the environment.
                This argument is mutually exclusive with providing a
                transport instance to ``transport``; doing so will raise
                an exception.
            client_config (dict): DEPRECATED. A dictionary of call options for
                each method. If not specified, the default configuration is used.
            client_info (google.api_core.gapic_v1.client_info.ClientInfo):
                The client info used to send a user-agent string along with
                API requests. If ``None``, then default info will be used.
                Generally, you only need to set this if you're developing
                your own client library.
        """
        # Raise deprecation warnings for things we want to go away.
        if client_config:
            warnings.warn('The `client_config` argument is deprecated.',
                          PendingDeprecationWarning)
        if channel:
            warnings.warn(
                'The `channel` argument is deprecated; use '
                '`transport` instead.', PendingDeprecationWarning)

        # Instantiate the transport.
        # The transport is responsible for handling serialization and
        # deserialization and actually sending data to the service.
        if transport:
            if callable(transport):
                self.transport = transport(
                    credentials=credentials,
                    default_class=publisher_grpc_transport.
                    PublisherGrpcTransport,
                )
            else:
                if credentials:
                    raise ValueError(
                        'Received both a transport instance and '
                        'credentials; these are mutually exclusive.')
                self.transport = transport
        else:
            self.transport = publisher_grpc_transport.PublisherGrpcTransport(
                address=self.SERVICE_ADDRESS,
                channel=channel,
                credentials=credentials,
            )

        self.iam_policy_stub = (iam_policy_pb2.IAMPolicyStub(channel))
        self.publisher_stub = (pubsub_pb2_grpc.PublisherStub(channel))

        if client_info is None:
            client_info = (
                google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO)
        client_info.gapic_version = _GAPIC_LIBRARY_VERSION
        self._client_info = client_info

        # Parse out the default settings for retry and timeout for each RPC
        # from the client configuration.
        # (Ordinarily, these are the defaults specified in the `*_config.py`
        # file next to this one.)
        self._method_configs = google.api_core.gapic_v1.config.parse_method_configs(
            client_config['interfaces'][self._INTERFACE_NAME], )

        # Save a dictionary of cached API call functions.
        # These are the actual callables which invoke the proper
        # transport methods, wrapped with `wrap_method` to add retry,
        # timeout, and the like.
        self._inner_api_calls = {}
示例#3
0
    def __init__(self,
                 channel=None,
                 credentials=None,
                 client_config=publisher_client_config.config,
                 client_info=None):
        """Constructor.

        Args:
            channel (grpc.Channel): A ``Channel`` instance through
                which to make calls. If specified, then the ``credentials``
                argument is ignored.
            credentials (google.auth.credentials.Credentials): The
                authorization credentials to attach to requests. These
                credentials identify this application to the service. If none
                are specified, the client will attempt to ascertain the
                credentials from the environment.
            client_config (dict):
                A dictionary of call options for each method. If not specified
                the default configuration is used. Generally, you only need
                to set this if you're developing your own client library.
            client_info (google.api_core.gapic_v1.client_info.ClientInfo):
                The client info used to send a user-agent string along with
                API requests. If ``None``, then default info will be used.
                Generally, you only need to set this if you're developing
                your own client library.
        """
        if channel is not None and credentials is not None:
            raise ValueError(
                'channel and credentials arguments to {} are mutually '
                'exclusive.'.format(self.__class__.__name__))

        if channel is None:
            channel = google.api_core.grpc_helpers.create_channel(
                self.SERVICE_ADDRESS,
                credentials=credentials,
                scopes=self._DEFAULT_SCOPES)

        self.iam_policy_stub = (iam_policy_pb2.IAMPolicyStub(channel))
        self.publisher_stub = (pubsub_pb2.PublisherStub(channel))

        if client_info is None:
            client_info = (
                google.api_core.gapic_v1.client_info.DEFAULT_CLIENT_INFO)

        client_info.gapic_version = _GAPIC_LIBRARY_VERSION

        interface_config = client_config['interfaces'][self._INTERFACE_NAME]
        method_configs = google.api_core.gapic_v1.config.parse_method_configs(
            interface_config)

        self._create_topic = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.CreateTopic,
            default_retry=method_configs['CreateTopic'].retry,
            default_timeout=method_configs['CreateTopic'].timeout,
            client_info=client_info)
        self._update_topic = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.UpdateTopic,
            default_retry=method_configs['UpdateTopic'].retry,
            default_timeout=method_configs['UpdateTopic'].timeout,
            client_info=client_info)
        self._publish = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.Publish,
            default_retry=method_configs['Publish'].retry,
            default_timeout=method_configs['Publish'].timeout,
            client_info=client_info)
        self._get_topic = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.GetTopic,
            default_retry=method_configs['GetTopic'].retry,
            default_timeout=method_configs['GetTopic'].timeout,
            client_info=client_info)
        self._list_topics = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.ListTopics,
            default_retry=method_configs['ListTopics'].retry,
            default_timeout=method_configs['ListTopics'].timeout,
            client_info=client_info)
        self._list_topic_subscriptions = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.ListTopicSubscriptions,
            default_retry=method_configs['ListTopicSubscriptions'].retry,
            default_timeout=method_configs['ListTopicSubscriptions'].timeout,
            client_info=client_info)
        self._delete_topic = google.api_core.gapic_v1.method.wrap_method(
            self.publisher_stub.DeleteTopic,
            default_retry=method_configs['DeleteTopic'].retry,
            default_timeout=method_configs['DeleteTopic'].timeout,
            client_info=client_info)
        self._set_iam_policy = google.api_core.gapic_v1.method.wrap_method(
            self.iam_policy_stub.SetIamPolicy,
            default_retry=method_configs['SetIamPolicy'].retry,
            default_timeout=method_configs['SetIamPolicy'].timeout,
            client_info=client_info)
        self._get_iam_policy = google.api_core.gapic_v1.method.wrap_method(
            self.iam_policy_stub.GetIamPolicy,
            default_retry=method_configs['GetIamPolicy'].retry,
            default_timeout=method_configs['GetIamPolicy'].timeout,
            client_info=client_info)
        self._test_iam_permissions = google.api_core.gapic_v1.method.wrap_method(
            self.iam_policy_stub.TestIamPermissions,
            default_retry=method_configs['TestIamPermissions'].retry,
            default_timeout=method_configs['TestIamPermissions'].timeout,
            client_info=client_info)