Exemple #1
0
def _get_google_provider(project_id, auth_token, provider_type):
    if not project_id:
        raise BadRequest('Missing required field `extensions.projectId`.')
    if not auth_token:
        if _requires_auth():
            raise BadRequest('Missing required field `authToken`.')
        return google.GoogleJobProvider(False, False, project_id)

    resp = requests.post('https://www.googleapis.com/oauth2/v2/tokeninfo',
                         params={
                             'access_token': auth_token,
                         })
    if resp.status_code != 200:
        raise Unauthorized('failed to validate auth token')
    current_app.logger.info('user "%s" signed in', resp.json().get('email'))

    try:
        credentials = AccessTokenCredentials(auth_token, 'user-agent')
        if provider_type == ProviderType.GOOGLE:
            return google.GoogleJobProvider(False,
                                            False,
                                            project_id,
                                            credentials=credentials)
        else:
            return google_v2.GoogleV2JobProvider(False,
                                                 False,
                                                 project_id,
                                                 credentials=credentials)
    except AccessTokenCredentialsError as e:
        raise Unauthorized('Invalid authentication token:{}.'.format(e))
Exemple #2
0
def get_dsub_provider():
    if test.DSUB_PROVIDER == 'local':
        return local.LocalJobProvider(resources)
    elif test.DSUB_PROVIDER == 'google':
        return google.GoogleJobProvider(False, False, test.PROJECT_ID)
    elif test.DSUB_PROVIDER == 'google-v2':
        return google_v2.GoogleV2JobProvider(False, False, test.PROJECT_ID)
    else:
        print('Invalid provider specified.', file=sys.stderr)
        sys.exit(1)
Exemple #3
0
def get_dsub_provider():
    """Return the appropriate google_base.JobProvider instance."""
    if test.DSUB_PROVIDER == 'local':
        return local.LocalJobProvider(resources)
    elif test.DSUB_PROVIDER == 'google-cls-v2':
        return google_cls_v2.GoogleCLSV2JobProvider(False, test.PROJECT_ID,
                                                    'us-central1')
    elif test.DSUB_PROVIDER == 'google-v2':
        return google_v2.GoogleV2JobProvider(False, test.PROJECT_ID)
    else:
        print('Invalid provider specified.', file=sys.stderr)
        sys.exit(1)