Esempio n. 1
0
def get_credentials():

    try:
        auth = project.recipe['setup']['auth']['user']

        # if credentials are stored in a bucket
        if RE_CREDENTIALS_BUCKET.match(auth):
            credentials = BucketCredentials.from_bucket(auth)

        # if credentials are embeded as JSON
        elif RE_CREDENTIALS_JSON.match(auth):
            return Credentials.from_json_keyfile_dict(json.loads(auth), scopes
                                                      or SCOPES)

        # if credentials are local path ( remember this runs as command line )
        else:
            store = Storage(auth)
            credentials = store.get()

            if not credentials or credentials.invalid:
                flow = get_flow(project.recipe['setup']['auth']['client'])
                flow.user_agent = APPLICATION_NAME
                flags = tools.argparser.parse_args(
                    args=['--noauth_local_webserver'])
                credentials = tools.run_flow(flow, store, flags)
                print('Storing credentials to ' + auth)

        return credentials

    except (KeyError, ValueError):
        raise KeyError(
            "Either specify a -u [user credentials path] parameter on the command line or include setup->auth->user->[JSON OR PATH] in the recipe."
        )
Esempio n. 2
0
def get_credentials():

    auth = project.recipe['setup']['auth']['user']

    # if credentials are stored in a bucket
    if RE_CREDENTIALS_BUCKET.match(auth):
        credentials = BucketCredentials.from_bucket(auth)

    # if credentials are embeded as JSON
    elif RE_CREDENTIALS_JSON.match(auth):
        return Credentials.from_json_keyfile_dict(json.loads(auth), scopes
                                                  or SCOPES)

    # if credentials are local path ( remember this runs as command line )
    else:
        store = Storage(auth)
        credentials = store.get()

        if not credentials or credentials.invalid:
            flow = client.flow_from_clientsecrets(
                project.recipe['setup']['auth']['client'], SCOPES)
            flow.user_agent = APPLICATION_NAME
            flags = tools.argparser.parse_args(
                args=['--noauth_local_webserver'])
            credentials = tools.run_flow(flow, store, flags)
            print('Storing credentials to ' + auth)

    return credentials
Esempio n. 3
0
 def get_credentials(self):
     return BucketCredentials.from_bucket(
         self.get_credentials_path()) if self.identifier else None
Esempio n. 4
0
 def set_credentials(self, credentials):
     # check if refresh token exists before saving credentials ( only given first time through auth )?
     if self.identifier:
         BucketCredentials.from_oauth(self.get_credentials_path(),
                                      credentials).to_bucket()