How to use the keyring.errors.InitError function in keyring

To help you get started, we’ve selected a few keyring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
url = docs_entry.content.src
                url += '&exportFormat=txt'
                server_response = self.client.request('GET', url)
                if server_response.status != 200:
                    raise errors.InitError(
                        'Could not read existing Google Docs keyring')
                file_contents = server_response.read()
                if file_contents.startswith(codecs.BOM_UTF8):
                    file_contents = file_contents[len(codecs.BOM_UTF8):]
                keyring_dict = pickle.loads(base64.urlsafe_b64decode(
                    file_contents.decode('string-escape')))
            except pickle.UnpicklingError as ex:
                raise errors.InitError(
                    'Could not unpickle existing Google Docs keyring', ex)
            except TypeError as ex:
                raise errors.InitError(
                    'Could not decode existing Google Docs keyring', ex)

        return docs_entry, keyring_dict
github OpenReplyDE / bbbackup / bbbackup.py View on Github external
def oauth_config_reset():
    global OAUTH_CLIENT_NAME, OAUTH_CLIENT_KEY_OR_ID, OAUTH_CLIENT_SECRET
    printstyled( 'OAUTH: RESETTING...', 'cyan' )
    ring = None
    try:
        ring = keyring.get_keyring()
    except KeyringLocked:
        exit_with_code( 12 )
    except InitError:
        exit_with_code( 13 )
    try:
        ring.delete_password( CRED_KEY_SERVICE, CRED_KEY_OAUTH_NAME )
        ring.delete_password( CRED_KEY_SERVICE, CRED_KEY_OAUTH_KEY )
        ring.delete_password( CRED_KEY_SERVICE, CRED_KEY_OAUTH_SECRET )
        OAUTH_CLIENT_NAME = None
        OAUTH_CLIENT_KEY_OR_ID = None
        OAUTH_CLIENT_SECRET = None
        printstyled( 'OAUTH: REMOVED.', 'cyan' )
    except:
        printstyled( 'OAUTH: NO CREDENTIALS TO REMOVE.', 'red' )

    oauth_config_load()
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
if self.can_create:
                docs_entry = None
                keyring_dict = {}
            else:
                raise errors.InitError(
                    '%s not found in %s and create not permitted'
                    %(self._get_doc_title(), self.collection))
        else:
            docs_entry = docs.entry[0]
            file_contents = ''
            try:
                url = docs_entry.content.src
                url += '&exportFormat=txt'
                server_response = self.client.request('GET', url)
                if server_response.status != 200:
                    raise errors.InitError(
                        'Could not read existing Google Docs keyring')
                file_contents = server_response.read()
                if file_contents.startswith(codecs.BOM_UTF8):
                    file_contents = file_contents[len(codecs.BOM_UTF8):]
                keyring_dict = pickle.loads(base64.urlsafe_b64decode(
                    file_contents.decode('string-escape')))
            except pickle.UnpicklingError as ex:
                raise errors.InitError(
                    'Could not unpickle existing Google Docs keyring', ex)
            except TypeError as ex:
                raise errors.InitError(
                    'Could not decode existing Google Docs keyring', ex)

        return docs_entry, keyring_dict
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
def _read(self):
        from gdata.docs.service import DocumentQuery
        title_query = DocumentQuery(categories=[self.collection])
        title_query['title'] = self._get_doc_title()
        title_query['title-exact'] = 'true'
        docs = self.client.QueryDocumentListFeed(title_query.ToUri())

        if not docs.entry:
            if self.can_create:
                docs_entry = None
                keyring_dict = {}
            else:
                raise errors.InitError(
                    '%s not found in %s and create not permitted'
                    %(self._get_doc_title(), self.collection))
        else:
            docs_entry = docs.entry[0]
            file_contents = ''
            try:
                url = docs_entry.content.src
                url += '&exportFormat=txt'
                server_response = self.client.request('GET', url)
                if server_response.status != 200:
                    raise errors.InitError(
                        'Could not read existing Google Docs keyring')
                file_contents = server_response.read()
                if file_contents.startswith(codecs.BOM_UTF8):
                    file_contents = file_contents[len(codecs.BOM_UTF8):]
                keyring_dict = pickle.loads(base64.urlsafe_b64decode(
github XuShaohua / bcloud / bcloud / gutil.py View on Github external
return DEFAULT_PROFILE
    with open(path) as fh:
        profile = json.load(fh)

    for key in DEFAULT_PROFILE:
        if key not in profile:
            profile[key] = DEFAULT_PROFILE[key]

    global keyring_available
    if keyring_available:
        for i in range(RETRIES):
            try:
                profile['password'] = keyring.get_password(
                        Config.DBUS_APP_NAME, profile['username'])
                break
            except (keyring.errors.InitError, dbus.exceptions.DBusException):
                logger.error(traceback.format_exc())
        else:
            keyring_available = False
    if not profile['password']:
        profile['password'] = ''
    return profile
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
docs_entry = docs.entry[0]
            file_contents = ''
            try:
                url = docs_entry.content.src
                url += '&exportFormat=txt'
                server_response = self.client.request('GET', url)
                if server_response.status != 200:
                    raise errors.InitError(
                        'Could not read existing Google Docs keyring')
                file_contents = server_response.read()
                if file_contents.startswith(codecs.BOM_UTF8):
                    file_contents = file_contents[len(codecs.BOM_UTF8):]
                keyring_dict = pickle.loads(base64.urlsafe_b64decode(
                    file_contents.decode('string-escape')))
            except pickle.UnpicklingError as ex:
                raise errors.InitError(
                    'Could not unpickle existing Google Docs keyring', ex)
            except TypeError as ex:
                raise errors.InitError(
                    'Could not decode existing Google Docs keyring', ex)

        return docs_entry, keyring_dict
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
self._client.source)
            except gdata.service.CaptchaRequired:
                sys.stdout.write('Please visit ' + self._client.captcha_url)
                answer = self.input_getter('Answer to the challenge? ')
                self._client.email = self.credential.username
                self._client.password = self.credential.password
                self._client.ClientLogin(
                    self.credential.username,
                    self.credential.password,
                    self._client.source,
                    captcha_token=self._client.captcha_token,
                    captcha_response=answer)
            except gdata.service.BadAuthentication:
                raise errors.InitError('Users credential were unrecognized')
            except gdata.service.Error:
                raise errors.InitError('Login Error')

        return self._client
github nathan-v / aws_okta_keyman / aws_okta_keyman / keyman.py View on Github external
def user_password(self):
        """Wrap getpass to simplify testing."""
        password = None
        if self.config.password_cache:
            self.log.debug('Password cache enabled')
            try:
                keyring.get_keyring()
                password = keyring.get_password('aws_okta_keyman',
                                                self.config.username)
            except keyring.errors.InitError:
                msg = 'Password cache enabled but no keyring available.'
                self.log.warning(msg)
                password = getpass.getpass()

            if self.config.password_reset or password is None:
                self.log.debug('Password not in cache or reset requested')
                password = getpass.getpass()
                keyring.set_password('aws_okta_keyman', self.config.username,
                                     password)
        else:
            password = getpass.getpass()
        return password