Exemple #1
0
    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 helper_refresh(self):
        credentials = get_credentials('user')
        token = credentials.token
        expiry = credentials.expiry

        # wait a bit before refreshing token, multiple tests go too fast and same token is returned
        sleep(1)

        # test refresh ( not expired cache, not expired file )
        credentials.refresh()
        self.assertEqual(token, credentials.token)
        self.assertEqual(expiry, credentials.expiry)

        # wait a bit before refreshing token, multiple tests go too fast and same token is returned
        sleep(1)

        # test refresh ( expired cache, not expired file )
        credentials.expiry = (datetime.now() - timedelta(days=5))
        credentials.refresh()
        self.assertEqual(token, credentials.token)
        self.assertEqual(expiry, credentials.expiry)

        # wait a bit before refreshing token, multiple tests go too fast and same token is returned
        sleep(1)

        # test refresh ( expired cache, expired file )
        credentials.expiry = (datetime.now() - timedelta(days=5))
        credentials.save()
        credentials.refresh()
        self.assertNotEqual(token, credentials.token)
        self.assertNotEqual(expiry, credentials.expiry)
Exemple #3
0
    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 ''
Exemple #4
0
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
Exemple #5
0
def account_create():

    accounts = Account.objects.all()
    if len(accounts) > 0:
        account = accounts[0]
    else:
        config = Configuration(client=UI_CLIENT, user=UI_USER)
        credentials = get_credentials(config, 'user')
        account = Account.objects.get_or_create_user(credentials, 'password')

    return account
def account_create():

    accounts = Account.objects.all()
    if len(accounts) > 0:
        account = accounts[0]
    else:
        project.initialize(_client=UI_CLIENT,
                           _service=UI_SERVICE,
                           _user=UI_USER)
        credentials = get_credentials('user')
        account = Account.objects.get_or_create_user(credentials, 'password')

    return account
    def test_remote_credentials_user(self):
        project.initialize(_user=self.user_file)
        credentials = get_credentials('user')
        account = Account.objects.get_or_create_user(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()