Beispiel #1
0
    def __init__(self, project=None, credentials=None,
                 read_only=False, admin=False, user_agent=DEFAULT_USER_AGENT):
        _ClientProjectMixin.__init__(self, project=project)
        if credentials is None:
            credentials = get_credentials()

        if read_only and admin:
            raise ValueError('A read-only client cannot also perform'
                             'administrative actions.')

        scopes = []
        if read_only:
            scopes.append(READ_ONLY_SCOPE)
        else:
            scopes.append(DATA_SCOPE)

        if admin:
            scopes.append(ADMIN_SCOPE)

        self._admin = bool(admin)
        try:
            credentials = credentials.create_scoped(scopes)
        except AttributeError:
            pass
        self._credentials = credentials
        self.user_agent = user_agent
        self.emulator_host = os.getenv(BIGTABLE_EMULATOR)

        # Create gRPC stubs for making requests.
        self._data_stub = _make_data_stub(self)
        if self._admin:
            self._instance_stub_internal = _make_instance_stub(self)
            self._operations_stub_internal = _make_operations_stub(self)
            self._table_stub_internal = _make_table_stub(self)
Beispiel #2
0
def get_client():
    """BigQuery-Client erzeugen."""
    credentials = google.auth.credentials.with_scopes_if_required(
        get_credentials(), bigquery.Client.SCOPE)
    return bigquery.Client(project=replication_config.BIGQUERY_PROJECT,
                           _http=google_auth_httplib2.AuthorizedHttp(
                               credentials, httplib2.Http(timeout=60)))
 def __init__(self, credentials=None, http=None):
     if (credentials is not None and not isinstance(
             credentials, google.auth.credentials.Credentials)):
         raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
     if credentials is None and http is None:
         credentials = get_credentials()
     self._credentials = credentials
     self._http = http
Beispiel #4
0
 def __init__(self, credentials=None, http=None):
     if (credentials is not None and
             not isinstance(
                 credentials, google.auth.credentials.Credentials)):
         raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
     if credentials is None and http is None:
         credentials = get_credentials()
     self._connection = self._connection_class(
         credentials=credentials, http=http)
Beispiel #5
0
 def __init__(self, credentials=None, _http=None):
     if (credentials is not None and not isinstance(
             credentials, google.auth.credentials.Credentials)):
         raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
     if credentials is None and _http is None:
         credentials = get_credentials()
     self._credentials = google.auth.credentials.with_scopes_if_required(
         credentials, self.SCOPE)
     self._http_internal = _http
 def __init__(self, credentials=None, _http=None):
     if (credentials is not None and
             not isinstance(
                 credentials, google.auth.credentials.Credentials)):
         raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
     if credentials is None and _http is None:
         credentials = get_credentials()
     self._credentials = google.auth.credentials.with_scopes_if_required(
         credentials, self.SCOPE)
     self._http_internal = _http
Beispiel #7
0
def connect(creds):
    """Construct a connection value to Google Storage API

    The credentials are retrieved using get_credentials that checks
    the environment for the correct values.

    """
    credentials = get_credentials()
    return storage.Client(credentials=credentials,
                          http=ThreadSafeHttp(credentials))
Beispiel #8
0
 def channel(self):
     ssl_channel = implementations.ssl_channel_credentials(None, None, None)
     creds = get_credentials().create_scoped([SPEECH_SCOPE])
     auth_header = ('Authorization',
                    'Bearer ' + creds.get_access_token().access_token)
     auth_plugin = implementations.metadata_call_credentials(
         lambda _, cb: cb([auth_header], None), name='google_creds')
     composite_channel = implementations.composite_channel_credentials(
         ssl_channel, auth_plugin)
     return implementations.secure_channel(SPEECH_API_HOST, SPEECH_API_PORT,
                                           composite_channel)
Beispiel #9
0
    def __init__(self, project=None, credentials=None,
                 user_agent=DEFAULT_USER_AGENT):

        _ClientProjectMixin.__init__(self, project=project)
        if credentials is None:
            credentials = get_credentials()

        scopes = [
            SPANNER_ADMIN_SCOPE,
        ]

        credentials = google.auth.credentials.with_scopes_if_required(
            credentials, scopes)

        self._credentials = credentials
        self.user_agent = user_agent
Beispiel #10
0
def make_channel(host, port):
    """Creates an SSL channel with auth credentials from the environment."""
    # In order to make an https call, use an ssl channel with defaults
    ssl_channel = implementations.ssl_channel_credentials(None, None, None)

    # Grab application default credentials from the environment
    creds = credentials.get_credentials().create_scoped([SPEECH_SCOPE])
    # Add a plugin to inject the creds into the header
    auth_header = ('Authorization',
                   'Bearer ' + creds.get_access_token().access_token)
    auth_plugin = implementations.metadata_call_credentials(
        lambda _, cb: cb([auth_header], None), name='google_creds')

    # compose the two together for both ssl and google auth
    composite_channel = implementations.composite_channel_credentials(
        ssl_channel, auth_plugin)

    return implementations.secure_channel(host, port, composite_channel)
Beispiel #11
0
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
def make_channel(host, port):
    """Creates an SSL channel with auth credentials from the environment."""
    # In order to make an https call, use an ssl channel with defaults
    ssl_channel = implementations.ssl_channel_credentials(None, None, None)

    # Grab application default credentials from the environment
    creds = credentials.get_credentials().create_scoped([SPEECH_SCOPE])
    # Add a plugin to inject the creds into the header
    auth_header = (
        'Authorization',
        'Bearer ' + creds.get_access_token().access_token)
    auth_plugin = implementations.metadata_call_credentials(
        lambda _, cb: cb([auth_header], None),
        name='google_creds')

    # compose the two together for both ssl and google auth
    composite_channel = implementations.composite_channel_credentials(
        ssl_channel, auth_plugin)

    return implementations.secure_channel(host, port, composite_channel)
    def __init__(self,
                 project=None,
                 credentials=None,
                 read_only=False,
                 admin=False,
                 user_agent=DEFAULT_USER_AGENT):
        _ClientProjectMixin.__init__(self, project=project)
        if credentials is None:
            credentials = get_credentials()

        if read_only and admin:
            raise ValueError('A read-only client cannot also perform'
                             'administrative actions.')

        scopes = []
        if read_only:
            scopes.append(READ_ONLY_SCOPE)
        else:
            scopes.append(DATA_SCOPE)

        self._read_only = bool(read_only)

        if admin:
            scopes.append(ADMIN_SCOPE)

        self._admin = bool(admin)

        credentials = google.auth.credentials.with_scopes_if_required(
            credentials, scopes)

        self._credentials = credentials
        self.user_agent = user_agent
        self.emulator_host = os.getenv(BIGTABLE_EMULATOR)

        # Create gRPC stubs for making requests.
        self._data_stub = _make_data_stub(self)
        if self._admin:
            self._instance_stub_internal = _make_instance_stub(self)
            self._operations_stub_internal = _make_operations_stub(self)
            self._table_stub_internal = _make_table_stub(self)
Beispiel #14
0
    def __init__(self,
                 project=None,
                 credentials=None,
                 read_only=False,
                 admin=False,
                 user_agent=DEFAULT_USER_AGENT):
        _ClientProjectMixin.__init__(self, project=project)
        if credentials is None:
            credentials = get_credentials()

        if read_only and admin:
            raise ValueError('A read-only client cannot also perform'
                             'administrative actions.')

        scopes = []
        if read_only:
            scopes.append(READ_ONLY_SCOPE)
        else:
            scopes.append(DATA_SCOPE)

        if admin:
            scopes.append(ADMIN_SCOPE)

        self._admin = bool(admin)
        try:
            credentials = credentials.create_scoped(scopes)
        except AttributeError:
            pass
        self._credentials = credentials
        self.user_agent = user_agent

        # Create gRPC stubs for making requests.
        self._data_stub = _make_data_stub(self)
        if self._admin:
            self._instance_stub_internal = _make_instance_stub(self)
            self._operations_stub_internal = _make_operations_stub(self)
            self._table_stub_internal = _make_table_stub(self)
Beispiel #15
0
# -*- coding: utf-8 -*-

from google.cloud.credentials import get_credentials
creds = get_credentials()
print creds.get_access_token().access_token
Beispiel #16
0
 def __init__(self, credentials=None, http=None):
     if credentials is None and http is None:
         credentials = get_credentials()
     self.connection = self._connection_class(
         credentials=credentials, http=http)
 def __init__(self, credentials=None, http=None):
     if credentials is None and http is None:
         credentials = get_credentials()
     self.connection = self._connection_class(credentials=credentials,
                                              http=http)
Beispiel #18
0
 def _callFUT(self):
     from google.cloud import credentials
     return credentials.get_credentials()
 def _callFUT(self):
     from google.cloud import credentials
     return credentials.get_credentials()