def handle(self, *args, **kwargs): # loop through accounts for account in Account.objects.all(): print('CONVERTING', account.email) try: # load legacy credentials credentials = legacy_credentails_get( legacy_credentials_path(account.identifier)) # convert to new format new_credentials = CredentialsUserWrapper(credentials) # save new credentials account.set_credentials(new_credentials) if kwargs['test']: project.initialize(_user=account.get_credentials_path()) profile = get_profile() print(profile) exit() except Exception as e: print(str(e))
def handle(self, *args, **kwargs): if kwargs.get('write'): # create or update master account credentials from installed user credentials project.initialize(_user=kwargs['user']) # if password not given on command line, ask for it inline if not kwargs.get('password'): print( 'Enter password for UI account access ( DO NOT USE YOUR GSUITE PASSWORD ):' ) kwargs['password'] = getpass.getpass() account = Account.objects.get_or_create_user( get_profile(), get_credentials('user'), kwargs['password']) print('ACCOUNT SET UP:', account.email) else: print( '\nDANGER: Use only with the Data Scientist Setup. This will...' ) print(' - Overwrite the users credentials with local credentials.') print('')
def handle(self, *args, **kwargs): if kwargs.get('write'): # create or update master account credentials from installed user credentials project.initialize(_user=kwargs['user']) # if password not given on command line, ask for it inline if not kwargs.get('password'): print( 'Enter password for UI account access ( DO NOT USE YOUR GSUITE PASSWORD ):' ) kwargs['password'] = getpass.getpass() account = Account.objects.get_or_create_user( get_profile(), get_credentials(), kwargs['password']) # move all recipes to this account and remove all other accounts ( there can be ONLY one ) #Project.objects.exclude(account=account).update(account=account) #Recipe.objects.exclude(account=account).update(account=account) #Account.objects.exclude(pk=account.pk).delete() print 'ACCOUNT SET UP:', account.email else: print '\nDANGER: Use only with the Data Scientist Setup. This will...' print ' - Overwrite the users credentials with local credentials.' print ''
def account_create(): project.initialize(_client=UI_CLIENT, _service=UI_SERVICE, _user=UI_USER) credentials = get_credentials('user') profile = get_profile() account = Account.objects.get_or_create_user(profile, credentials, 'password') return account
def test_remote_credentials_user(self): project.initialize(_user=self.user_file) credentials = get_credentials('user') profile = get_profile() account = Account.objects.get_or_create_user(profile, credentials, 'password') clear_credentials_cache() project.initialize(_user=account.get_credentials_path()) self.assertEqual(project.recipe['setup']['auth']['user'], account.get_credentials_path()) service = get_service('oauth2', 'v2', 'user') response = service.userinfo().get().execute() self.assertIn('email', response) self.helper_refresh()
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=textwrap.dedent("""\ Creates USER credentials from Google Cloud Project CLIENT Credentials and displays profile information if it worked. CLIENT credentials are required to run this script, to obtain the JSON file... Step 1: Configure Authentication Consent Screen ( do only once ) ---------------------------------------- A. Visit: https://console.developers.google.com/apis/credentials/consent B. Choose Internal if you have GSuite, otherwise choose External. C. For Application Name enter: StarThinker D. All other fields are optional, click Save. Step 2: Create CLIENT Credentials ( do only once ) ---------------------------------------- A. Visit: https://console.developers.google.com/apis/credentials/oauthclient B. Choose Desktop. C. For Name enter: StarThinker. D. Click Create and ignore the confirmation pop-up. Step 3: Download CLIENT Credentials File ( do only once )" ----------------------------------------" A. Visit: https://console.developers.google.com/apis/credentials" B. Find your newly created key under OAuth 2.0 Client IDs and click download arrow on the right." C. The downloaded file is the CLIENT credentials, use its path for the --client -c parameter. Step 4: Generate USER Credentials File ( do only once )" ----------------------------------------" A. Run this command with parameters -c [CLIENT file path] and -u [USER file path]. B. The USER file will be created and can be used to access Google APIs. C. The user profile will be printed to the screen Example: python helper.py -u [CLIENT file path] -c [USER file path] """)) # initialize project parser = commandline_parser(parser, arguments=('-c', '-u')) args = parser.parse_args() config = Configuration( user=args.user, client=args.client ) # get profile to verify everything worked print('Profile:', json.dumps(get_profile(config), indent=2, sort_keys=True))
See APPLICATION_SCOPES in starthinker/config.py or review util/auth/README.md Arguments --client / -c - path to client credentials file used to authenticate --user / -u - path to user credentials file to be created if it does not exist. Example python auth/helper.py -u [user credentials path] -c [client credentials path] """ import json import argparse from starthinker.util.project import project from starthinker.util.auth import get_profile if __name__ == "__main__": # all parameters come from project ( forces ignore of json file ) parser = argparse.ArgumentParser() # initialize project project.from_commandline(parser=parser) # get profile print('Profile:', json.dumps(get_profile(), indent=2, sort_keys=True))