def make_gax_publisher_api(credentials=None, host=None): """Create an instance of the GAX Publisher API. If the ``credentials`` are omitted, then we create an insecure ``channel`` pointing at the local Pub / Sub emulator. :type credentials: :class:`~google.auth.credentials.Credentials` :param credentials: (Optional) Credentials for getting access tokens. :type host: str :param host: (Optional) The host for an insecure channel. Only used if ``credentials`` are omitted. :rtype: :class:`.publisher_client.PublisherClient` :returns: A publisher API instance with the proper channel. """ if credentials is None: channel = insecure_channel(host) else: channel = make_secure_channel(credentials, DEFAULT_USER_AGENT, PublisherClient.SERVICE_ADDRESS) return PublisherClient(channel=channel, lib_name='gccl', lib_version=__version__)
def make_gax_publisher_api(connection): """Create an instance of the GAX Publisher API. If the ``connection`` is intended for a local emulator, then an insecure ``channel`` is created pointing at the local Pub / Sub server. :type connection: :class:`~google.cloud.pubsub._http.Connection` :param connection: The connection that holds configuration details. :rtype: :class:`.publisher_client.PublisherClient` :returns: A publisher API instance with the proper connection configuration. """ if connection.in_emulator: channel = insecure_channel(connection.host) else: channel = make_secure_channel(connection.credentials, DEFAULT_USER_AGENT, PublisherClient.SERVICE_ADDRESS) return PublisherClient(channel=channel)