def Create(email_address=None, private_key_path=None, oauth_url=None):
        if email_address:
            from google.appengine.api.app_identity import app_identity_keybased_stub

            logging.debug('Using the KeyBasedAppIdentityServiceStub.')
            return app_identity_keybased_stub.KeyBasedAppIdentityServiceStub(
                email_address=email_address,
                private_key_path=private_key_path,
                oauth_url=oauth_url)
        elif sys.version_info >= (2, 6):
            from oauth2client import client
            from google.appengine.api.app_identity import app_identity_defaultcredentialsbased_stub as ai_stub
            try:
                dc = ai_stub.DefaultCredentialsBasedAppIdentityServiceStub()
                logging.debug(
                    'Successfully loaded Application Default Credentials.')
                return dc
            except client.ApplicationDefaultCredentialsError, error:
                if not str(error).startswith(
                        'The Application Default Credentials '
                        'are not available.'):
                    logging.warning(
                        'An exception has been encountered when attempting '
                        'to use Application Default Credentials: %s'
                        '. Falling back on dummy AppIdentityServiceStub.',
                        str(error))
                return AppIdentityServiceStub()
Exemple #2
0
    def Create(email_address=None, private_key_path=None, oauth_url=None):
        if email_address:
            logging.debug('Using the KeyBasedAppIdentityServiceStub.')
            return app_identity_keybased_stub.KeyBasedAppIdentityServiceStub(
                email_address=email_address,
                private_key_path=private_key_path,
                oauth_url=oauth_url)
        else:
            try:
                dc = ai_default_stub.DefaultCredentialsBasedAppIdentityServiceStub(
                )
                logging.debug(
                    'Successfully loaded Application Default Credentials.')
                return dc
            except exceptions.DefaultCredentialsError as error:
                if not str(error).startswith(
                        'Could not automatically determine credentials.'):

                    logging.warning(
                        'An exception has been encountered when attempting '
                        'to use Application Default Credentials: %s'
                        '. Falling back on dummy AppIdentityServiceStub.',
                        str(error))
                return AppIdentityServiceStub()