def __init__(self, project=None, credentials=None, read_only=False, admin=False, user_agent=DEFAULT_USER_AGENT, timeout_seconds=DEFAULT_TIMEOUT_SECONDS): _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) self._credentials = credentials.create_scoped(scopes) self.user_agent = user_agent self.timeout_seconds = timeout_seconds
def __init__(self, project=None, credentials=None, read_only=False, admin=False, user_agent=DEFAULT_USER_AGENT, timeout_seconds=DEFAULT_TIMEOUT_SECONDS): _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.timeout_seconds = timeout_seconds # These will be set in start(). self._data_stub_internal = None self._cluster_stub_internal = None self._operations_stub_internal = None self._table_stub_internal = None
def make_channel(host, port): ssl_channel = implementations.ssl_channel_credentials(None, None, None) creds = get_credentials().create_scoped(args.speech_scope) auth_header = ("authorization", "Bearer " + creds.get_access_token().access_token) auth_plugin = implementations.metadata_call_credentials(lambda _, func: func([auth_header], None), name="google_creds") 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) 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)
def __init__(self, project=None, credentials=None, read_only=False, admin=False, user_agent=DEFAULT_USER_AGENT, timeout_seconds=DEFAULT_TIMEOUT_SECONDS): _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.timeout_seconds = timeout_seconds # These will be set in start(). self._data_stub_internal = None self._instance_stub_internal = None self._operations_stub_internal = None self._table_stub_internal = None
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))
def make_channel(self, host, port): 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(host, port, composite_channel)
def __init__(self, project=None, credentials=None, http=None): if project is None: project = _get_production_project() if project is None: raise ValueError('Project was not passed and could not be ' 'determined from the environment.') self.project = project if credentials is None and http is None: credentials = get_credentials() self.connection = Connection(credentials=credentials, http=http)
def from_environment(cls, *args, **kwargs): """Factory to retrieve implicit credentials while creating connection. :rtype: :class:`gcloud.connection.Connection` :returns: The connection created with the retrieved implicit credentials. """ credentials = get_credentials() if 'credentials' in kwargs: raise TypeError('credentials must not be in keyword arguments') kwargs['credentials'] = credentials return cls(*args, **kwargs)
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 = 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 get_scoped_connection(klass, scopes): """Create a scoped connection to GCloud. :type klass: subclass of :class:`gcloud.connection.Connection` :param klass: the specific ``Connection`` class to instantiate. :type scopes: list of URLs :param scopes: the effective service auth scopes for the connection. :rtype: instance of ``klass`` :returns: A connection defined with the proper credentials. """ implicit_credentials = get_credentials() scoped_credentials = implicit_credentials.create_scoped(scopes) return klass(credentials=scoped_credentials)
def get_connection(): """Shortcut method to establish a connection to the Cloud Datastore. Use this if you are going to access several datasets with the same set of credentials (unlikely): >>> from gcloud import datastore >>> connection = datastore.get_connection() >>> dataset1 = connection.dataset('dataset1') >>> dataset2 = connection.dataset('dataset2') :rtype: :class:`gcloud.datastore.connection.Connection` :returns: A connection defined with the proper credentials. """ implicit_credentials = credentials.get_credentials() scoped_credentials = implicit_credentials.create_scoped(SCOPE) return Connection(credentials=scoped_credentials)
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 = 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 get_connection(project): """Shortcut method to establish a connection to Cloud Storage. Use this if you are going to access several buckets with the same set of credentials: >>> from gcloud import storage >>> connection = storage.get_connection(project) >>> bucket1 = connection.get_bucket('bucket1') >>> bucket2 = connection.get_bucket('bucket2') :type project: string :param project: The name of the project to connect to. :rtype: :class:`gcloud.storage.connection.Connection` :returns: A connection defined with the proper credentials. """ implicit_credentials = credentials.get_credentials() scoped_credentials = implicit_credentials.create_scoped(SCOPE) return Connection(project=project, credentials=scoped_credentials)
def from_environment(cls, *args, **kwargs): """Factory to retrieve implicit credentials while creating connection. :type args: tuple :param args: Remaining positional arguments to pass to constructor. :type kwargs: dictionary :param kwargs: Remaining keyword arguments to pass to constructor. :rtype: :class:`gcloud.connection.Connection` :returns: The connection created with the retrieved implicit credentials. :raises: class:`TypeError` if there is a conflict with the kwargs and the credentials created by the factory. """ if 'credentials' in kwargs: raise TypeError('credentials must not be in keyword arguments') credentials = get_credentials() kwargs['credentials'] = credentials return cls(*args, **kwargs)
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 _callFUT(self): from gcloud import credentials return credentials.get_credentials()
def init_colab(): """ Setting the configurations in Colab (Google) """ # Login the user from google.colab import auth from google.colab import drive auth.authenticate_user() import requests from gcloud import credentials logging.basicConfig(level=logging.DEBUG) access_token = credentials.get_credentials().get_access_token( ).access_token gcloud_tokeninfo = requests.get( 'https://www.googleapis.com/oauth2/v3/userinfo?access_token=' + access_token).json() email = gcloud_tokeninfo['email'] last_name = '' first_name = email.split('@')[0] # Mount the drive drive.mount('/content/drive') # Configure the database home = '/content/drive/My Drive/.norm/' if not os.path.exists(home): os.mkdir(home) logging.info("Directory " + home + " created ") else: logging.info("Directory " + home + " already exists") from norm.config import Session from norm import config, security config.NORM_HOME = home config.DATA_STORAGE_ROOT = os.path.join(home, 'data') if not os.path.exists(config.DATA_STORAGE_ROOT): os.mkdir(config.DATA_STORAGE_ROOT) logging.info("Directory " + config.DATA_STORAGE_ROOT + " created ") else: logging.info("Directory " + config.DATA_STORAGE_ROOT + " already exists") db_path = os.path.join(home, 'db') if not os.path.exists(db_path): os.mkdir(db_path) logging.info("Directory " + db_path + " created ") else: logging.info("Directory " + db_path + " already exists") config.DB_PATH = os.path.join(home, 'db/norm.db') if not os.path.exists(config.DB_PATH): orig_db_file = os.path.join(os.path.dirname(__file__), 'db/norm.db') from shutil import copyfile copyfile(orig_db_file, config.DB_PATH) logging.info("File " + config.DB_PATH + " copied") else: logging.info("File " + config.DB_PATH + " already exists") config.engine = create_engine('sqlite:///{}'.format(config.DB_PATH), poolclass=StaticPool) Session.configure(bind=config.engine) config.session = Session() config.context_id = str(datetime.utcnow().strftime('%m%d%Y.%H%M%S')) from norm.security import login user = login({ 'first_name': first_name, 'last_name': last_name, 'username': email, 'email': email }) logging.info(user.username + ' logged in') global context from norm.engine import NormCompiler, NormError context = NormCompiler(config.context_id, user, config.session)