コード例 #1
0
ファイル: _gax.py プロジェクト: andre622/web_tracking_gcs
def make_gax_subscriber_api(credentials=None, host=None):
    """Create an instance of the GAX Subscriber 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:`.subscriber_client.SubscriberClient`
    :returns: A subscriber API instance with the proper channel.
    """
    if credentials is None:
        channel = insecure_channel(host)
    else:
        channel = make_secure_channel(credentials, DEFAULT_USER_AGENT,
                                      SubscriberClient.SERVICE_ADDRESS)
    return SubscriberClient(channel=channel,
                            lib_name='gccl',
                            lib_version=__version__)
コード例 #2
0
def make_datastore_api(client):
    """Create an instance of the GAPIC Datastore API.

    :type client: :class:`~google.cloud.datastore.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`.datastore.v1.datastore_client.DatastoreClient`
    :returns: A datastore API instance with the proper credentials.
    """
    parse_result = six.moves.urllib_parse.urlparse(
        client._base_url)
    host = parse_result.netloc
    if parse_result.scheme == 'https':
        channel = make_secure_channel(
            client._credentials, DEFAULT_USER_AGENT, host)
    else:
        channel = insecure_channel(host)

    return datastore_client.DatastoreClient(
        channel=channel,
        client_info=client_info.ClientInfo(
            client_library_version=__version__,
            gapic_version=__version__,
        ),
    )
コード例 #3
0
    def __init__(self, project=None, namespace=None, credentials=None):
        self.namespace = namespace
        self.host = os.environ.get(environment_vars.GCD_HOST,
                                   DATASTORE_API_HOST)
        self.client_info = _CLIENT_INFO

        # Use insecure connection when using Datastore Emulator, otherwise
        # use secure connection
        emulator = bool(os.environ.get("DATASTORE_EMULATOR_HOST"))
        self.secure = not emulator

        if emulator:
            # When using the emulator, in theory, the client shouldn't need to
            # call home to authenticate, as you don't need to authenticate to
            # use the local emulator. Unfortunately, the client calls home to
            # authenticate anyway, unless you pass ``requests.Session`` to
            # ``_http`` which seems to be the preferred work around.
            super(Client, self).__init__(
                project=project,
                credentials=credentials,
                _http=requests.Session,
            )
        else:
            super(Client, self).__init__(project=project,
                                         credentials=credentials)

        if emulator:
            channel = grpc.insecure_channel(self.host)

        else:
            user_agent = _CLIENT_INFO.to_user_agent()
            channel = _helpers.make_secure_channel(self._credentials,
                                                   user_agent, self.host)

        self.stub = datastore_pb2_grpc.DatastoreStub(channel)
コード例 #4
0
ファイル: _gax.py プロジェクト: vicros/google-cloud-python
 def __init__(self, client=None):
     self._client = client
     credentials = self._client._connection.credentials
     channel = make_secure_channel(credentials, DEFAULT_USER_AGENT,
                                   SpeechApi.SERVICE_ADDRESS)
     self._gapic_api = SpeechApi(channel=channel)
     self._operations_stub = make_secure_stub(
         credentials, DEFAULT_USER_AGENT, operations_grpc.OperationsStub,
         OPERATIONS_API_HOST)
コード例 #5
0
ファイル: ros_adapter.py プロジェクト: robotlinker/core-1
def make_secure_channel(credentials, user_agent, host, extra_options=()):
  if host == "pubsub.googleapis.com":
    host = os.environ['CLOUD_ROBOTICS_DOMAIN']
  MAX_MESSAGE_BYTES = 100 * 1024 * 1024
  options = (
      ('grpc.max_message_length', MAX_MESSAGE_BYTES),
      ('grpc.max_send_message_length', MAX_MESSAGE_BYTES),
      ('grpc.max_receive_message_length', MAX_MESSAGE_BYTES),
  ) + extra_options
  return _helpers.make_secure_channel(
      credentials, user_agent, host, extra_options)
コード例 #6
0
 def __init__(self, client=None):
     self._client = client
     credentials = self._client._connection.credentials
     channel = make_secure_channel(
         credentials, DEFAULT_USER_AGENT,
         SpeechClient.SERVICE_ADDRESS)
     self._gapic_api = SpeechClient(channel=channel)
     self._operations_stub = make_secure_stub(
         credentials,
         DEFAULT_USER_AGENT,
         operations_grpc.OperationsStub,
         OPERATIONS_API_HOST)
コード例 #7
0
ファイル: _gax.py プロジェクト: quasiben/google-cloud-python
def make_gax_sinks_api(client):
    """Create an instance of the GAX Sinks API.

    :type client: :class:`~google.cloud.logging.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`_SinksAPI`
    :returns: A metrics API instance with the proper credentials.
    """
    channel = make_secure_channel(client._credentials, DEFAULT_USER_AGENT,
                                  ConfigServiceV2Client.SERVICE_ADDRESS)
    generated = ConfigServiceV2Client(channel=channel)
    return _SinksAPI(generated, client)
コード例 #8
0
ファイル: _gax.py プロジェクト: Fkawala/gcloud-python
def make_gax_sinks_api(client):
    """Create an instance of the GAX Sinks API.

    :type client: :class:`~google.cloud.logging.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`_SinksAPI`
    :returns: A metrics API instance with the proper credentials.
    """
    channel = make_secure_channel(
        client._connection.credentials, DEFAULT_USER_AGENT,
        ConfigServiceV2Client.SERVICE_ADDRESS)
    generated = ConfigServiceV2Client(channel=channel)
    return _SinksAPI(generated, client)
コード例 #9
0
def make_gax_logging_api(client):
    """Create an instance of the GAX Logging API.

    :type client: :class:`~google.cloud.logging.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`_LoggingAPI`
    :returns: A metrics API instance with the proper credentials.
    """
    channel = make_secure_channel(client._credentials, DEFAULT_USER_AGENT,
                                  LoggingServiceV2Client.SERVICE_ADDRESS)
    generated = LoggingServiceV2Client(channel=channel,
                                       lib_name='gccl',
                                       lib_version=__version__)
    return _LoggingAPI(generated, client)
コード例 #10
0
def make_gax_trace_api(client):
    """Create an instance of the GAX Trace API.

    :type client: :class:`~google.cloud.trace.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`~google.cloud.trace._gax._TraceAPI`
    :returns: A Trace API instance with the proper configurations.
    """
    channel = make_secure_channel(
        client._credentials, DEFAULT_USER_AGENT,
        trace_service_client.TraceServiceClient.SERVICE_ADDRESS)
    generated = trace_service_client.TraceServiceClient(channel=channel,
                                                        lib_name='gccl')
    return _TraceAPI(generated, client)
コード例 #11
0
def make_report_error_api(client):
    """Create an instance of the GAX Logging API.

    :type client::class:`google.cloud.error_reporting.Client`
    :param client: Error Reporting client.

    :rtype: :class:_ErrorReportingGaxApi
    :returns: An Error Reporting API instance.
    """
    channel = make_secure_channel(
        client._credentials, DEFAULT_USER_AGENT,
        report_errors_service_client.ReportErrorsServiceClient.SERVICE_ADDRESS)
    gax_client = report_errors_service_client.ReportErrorsServiceClient(
        channel=channel, lib_name='gccl', lib_version=__version__)
    return _ErrorReportingGaxApi(gax_client, client.project)
コード例 #12
0
ファイル: _gax.py プロジェクト: FCtj/google-cloud-python
def make_datastore_api(client):
    """Create an instance of the GAPIC Datastore API.

    :type client: :class:`~google.cloud.datastore.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`.datastore.v1.datastore_client.DatastoreClient`
    :returns: A datastore API instance with the proper credentials.
    """
    channel = make_secure_channel(
        client._credentials, DEFAULT_USER_AGENT,
        datastore_client.DatastoreClient.SERVICE_ADDRESS)
    return GAPICDatastoreAPI(channel=channel,
                             lib_name='gccl',
                             lib_version=__version__)
コード例 #13
0
ファイル: _gax.py プロジェクト: screavic/google-cloud-python
 def __init__(self, client=None):
     self._client = client
     credentials = self._client._credentials
     channel = make_secure_channel(credentials, DEFAULT_USER_AGENT,
                                   SpeechClient.SERVICE_ADDRESS)
     self._gapic_api = SpeechClient(
         channel=channel,
         lib_name='gccl',
         lib_version=__version__,
     )
     self._operations_stub = make_secure_stub(
         credentials,
         DEFAULT_USER_AGENT,
         operations_grpc.OperationsStub,
         OPERATIONS_API_HOST,
     )
コード例 #14
0
def _make_firestore_api(client):
    """Create an instance of the GAPIC Firestore client.

    Args:
        client (~.firestore_v1beta1.client.Client): The client that holds
            configuration details.

    Returns:
        ~.gapic.firestore.v1beta1.firestore_client.FirestoreClient: A
        Firestore GAPIC client instance with the proper credentials.
    """
    host = firestore_client.FirestoreClient.SERVICE_ADDRESS
    channel = make_secure_channel(client._credentials, DEFAULT_USER_AGENT,
                                  host)
    return firestore_client.FirestoreClient(channel=channel,
                                            lib_name='gccl',
                                            lib_version=__version__)
コード例 #15
0
ファイル: _datastore_api.py プロジェクト: chmoder/python-ndb
def make_stub(client):
    """Create the stub for the `Google Datastore` API.

    Args:
        client (client.Client): The NDB client.

    Returns:
        :class:`~google.cloud.datastore_v1.proto.datastore_pb2_grpc.DatastoreStub`:
            The stub instance.
    """
    if client.secure:
        user_agent = client.client_info.to_user_agent()
        channel = _helpers.make_secure_channel(client._credentials, user_agent,
                                               client.host)
    else:
        channel = grpc.insecure_channel(client.host)

    return datastore_pb2_grpc.DatastoreStub(channel)
コード例 #16
0
ファイル: xmic.py プロジェクト: devming/Gaongilro
def main():
    credentials = get_credentials()
    credentials = google.auth.credentials.with_scopes_if_required(
            credentials, [SPEECH_SCOPE])
    service = cloud_speech.SpeechStub(make_secure_channel(credentials, user_agent="laptop", host='speech.googleapis.com'))
    print("start recording")
    with record_audio(RATE, CHUNK) as buffered_audio_data:
        requests = request_stream(buffered_audio_data, RATE)
        recognize_stream = service.StreamingRecognize(requests)
        signal.signal(signal.SIGINT, lambda *_: recognize_stream.cancel())
        try:
            print(recognize_stream)
            destination = listen_print_loop(recognize_stream)
            recognize_stream.cancel()
        except Exception as ex:
            print(str(ex))

        return destination
コード例 #17
0
def make_stub(client):
    """Create the stub for the `Google Datastore` API.

    Args:
        client (client.Client): The NDB client.

    Returns:
        :class:`~google.cloud.datastore_v1.proto.datastore_pb2_grpc.DatastoreStub`:
            The stub instance.
    """
    if client.secure:
        channel = _helpers.make_secure_channel(client._credentials,
                                               _http.DEFAULT_USER_AGENT,
                                               client.host)
    else:
        channel = grpc.insecure_channel(client.host)

    return datastore_pb2_grpc.DatastoreStub(channel)
コード例 #18
0
def make_datastore_api(client):
    """Create an instance of the GAPIC Datastore API.

    :type client: :class:`~google.cloud.datastore.client.Client`
    :param client: The client that holds configuration details.

    :rtype: :class:`.datastore.v1.datastore_client.DatastoreClient`
    :returns: A datastore API instance with the proper credentials.
    """
    parse_result = six.moves.urllib_parse.urlparse(client._base_url)
    host = parse_result.netloc
    if parse_result.scheme == "https":
        channel = make_secure_channel(client._credentials, DEFAULT_USER_AGENT,
                                      host)
    else:
        channel = insecure_channel(host)

    return datastore_client.DatastoreClient(channel=channel,
                                            client_info=client._client_info)
コード例 #19
0
ファイル: _gax.py プロジェクト: Fkawala/gcloud-python
def make_gax_subscriber_api(connection):
    """Create an instance of the GAX Subscriber 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:`.subscriber_client.SubscriberClient`
    :returns: A subscriber 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,
            SubscriberClient.SERVICE_ADDRESS)
    return SubscriberClient(channel=channel)
コード例 #20
0
def make_gax_subscriber_api(connection):
    """Create an instance of the GAX Subscriber 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:`.subscriber_client.SubscriberClient`
    :returns: A subscriber 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,
                                      SubscriberClient.SERVICE_ADDRESS)
    return SubscriberClient(channel=channel)
コード例 #21
0
ファイル: _gax.py プロジェクト: daspecster/gcloud-python
def make_gax_subscriber_api(credentials=None, host=None):
    """Create an instance of the GAX Subscriber 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:`.subscriber_client.SubscriberClient`
    :returns: A subscriber API instance with the proper channel.
    """
    if credentials is None:
        channel = insecure_channel(host)
    else:
        channel = make_secure_channel(
            credentials, DEFAULT_USER_AGENT,
            SubscriberClient.SERVICE_ADDRESS)
    return SubscriberClient(channel=channel)
コード例 #22
0
def stub():
    """Get the stub for the `Google Datastore` API.

    Gets the stub from the current context, creating one if there isn't one
    already.

    Returns:
        :class:`~google.cloud.datastore_v1.proto.datastore_pb2_grpc.DatastoreStub`:
            The stub instance.
    """
    state = _runstate.current()

    if state.stub is None:
        client = state.client
        if client.secure:
            channel = _helpers.make_secure_channel(client._credentials,
                                                   _http.DEFAULT_USER_AGENT,
                                                   client.host)
        else:
            channel = grpc.insecure_channel(client.host)

        state.stub = datastore_pb2_grpc.DatastoreStub(channel)

    return state.stub
コード例 #23
0
ファイル: test__helpers.py プロジェクト: arthrone/UncleBot
    def _call_fut(self, *args, **kwargs):
        from google.cloud._helpers import make_secure_channel

        return make_secure_channel(*args, **kwargs)
コード例 #24
0
    def _call_fut(self, *args, **kwargs):
        from google.cloud._helpers import make_secure_channel

        return make_secure_channel(*args, **kwargs)