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))
示例#2
0
def get_credentials(auth):
  global CREDENTIALS_USER_CACHE

  if auth == 'user':
    if CREDENTIALS_USER_CACHE is None:
      try:
        CREDENTIALS_USER_CACHE = CredentialsUserWrapper(
          project.recipe['setup']['auth']['user'],
          project.recipe['setup']['auth'].get('client')
        )
      except (KeyError, ValueError):
        print('')
        print(
            'ERROR: You are attempting to access an API endpoiont that requires Google OAuth USER authentication but have not provided credentials to make that possible.'
        )
        print('')
        print(
            'SOLUTION: Specify a -u [user credentials path] parameter on the command line.'
        )
        print(
            '          Alternaitvely specify a -u [user credentials path to be created] parameter and a -c [client credentials path] parameter on the command line.'
        )
        print(
            '          Alternaitvely if running a recipe, include { "setup":{ "auth":{ "user":"******" }}} in the JSON.'
        )
        print('')
        print(
            'INSTRUCTIONS: https://github.com/google/starthinker/blob/master/tutorials/cloud_client_installed.md'
        )
        print('')
        sys.exit(1)

    return CREDENTIALS_USER_CACHE

  elif auth == 'service':
    try:
      return CredentialsServiceWrapper(
        project.recipe['setup']['auth']['service']
      )
    except (KeyError, ValueError):
      print('')
      print(
          'ERROR: You are attempting to access an API endpoint that requires Google Cloud SERVICE authentication but have not provided credentials to make that possible.'
      )
      print('')
      print(
          'SOLUTION: Specify a -s [service credentials path] parameter on the command line.'
      )
      print(
          '          Alternaitvely if running a recipe, include { "setup":{ "auth":{ "service":"[JSON OR PATH]" }}} in the JSON.'
      )
      print('')
      print(
          'INSTRUCTIONS: https://github.com/google/starthinker/blob/master/tutorials/cloud_service.md'
      )
      print('')
      sys.exit(1)
示例#3
0
def get_credentials(auth):
    global CREDENTIALS_USER_CACHE

    if auth == 'user':
        if CREDENTIALS_USER_CACHE is None:
            try:
                CREDENTIALS_USER_CACHE = CredentialsUserWrapper(
                    project.recipe['setup']['auth']['user'],
                    project.recipe['setup']['auth'].get('client'))
            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."
                )
        return CREDENTIALS_USER_CACHE

    elif auth == 'service':
        try:
            return CredentialsServiceWrapper(
                project.recipe['setup']['auth']['service'])
        except (KeyError, ValueError):
            raise KeyError(
                "Either specify a -s [service credentials path] parameter on the command line or include setup->auth->service->[JSON OR PATH] in the recipe."
            )
示例#4
0
 def get_credentials(self):
   return CredentialsUserWrapper(self.get_credentials_path()) if self.identifier else None
示例#5
0
 def set_credentials(self, credentials):
   # check if refresh token exists before saving credentials ( only given when authenticating not refreshing )
   if self.identifier and credentials.refresh_token:
     buffer = CredentialsUserWrapper()
     buffer.from_credentials(credentials)
     buffer.save(self.get_credentials_path()) 
示例#6
0
 def set_credentials(self, credentials):
     # check if refresh token exists before saving credentials ( only given first time through auth )?
     if self.identifier:
         buffer = CredentialsUserWrapper()
         buffer.from_credentials(credentials)
         buffer.save(self.get_credentials_path())