(
            self, file_path='', password='', config_assistant=None)
Load credentials from a file and return a credential object.

        Args:
            file_path (str): Full path to the file storing the saved
                credentials.
            password (str): optional password to encrypt the
                credential file with. If not supplied a password
                will be generated.
            config_assistant (ConfigAssistant): optional configuration
                assistant object. Can be used to store the password to the
                credential file.

        Raises:
            IOError: If not able to decrypt the data.

        Returns:
            Credential object (oauth2.credentials.Credentials) read from
            the file.
Load credentials from a file and return a credential object.
Load credentials from a file and return a credential object .
def load_credentials(
            self, file_path='', password='', config_assistant=None):
        """Load credentials from a file and return a credential object.

        Args:
            file_path (str): Full path to the file storing the saved
                credentials.
            password (str): optional password to encrypt the
                credential file with. If not supplied a password
                will be generated.
            config_assistant (ConfigAssistant): optional configuration
                assistant object. Can be used to store the password to the
                credential file.

        Raises:
            IOError: If not able to decrypt the data.

        Returns:
            Credential object (oauth2.credentials.Credentials) read from
            the file.
        """
        if not file_path:
            file_path = self._filepath

        if not os.path.isfile(file_path):
            return None

        if password:
            password = bytes(password, 'utf-8')
        elif config_assistant:
            try:
                password = config_assistant.get_config('cred_key')
                if not isinstance(password, bytes):
                    password = bytes(password, 'utf-8')
            except KeyError as exc:
                raise IOError(
                    'Not able to determine encryption key from '
                    'config.') from exc
        else:
            raise IOError(
                'Neither password nor a configuration assistant passed to '
                'tool, unable to determine password.')

        with open(file_path, 'rb') as fh:
            salt = fh.read(self.SALT_LENGTH)
            key = self._get_key(salt, password)
            data = fh.read()
            crypto = fernet.Fernet(key)
            try:
                data_string = crypto.decrypt(data)
            except fernet.InvalidSignature as e:
                raise IOError(
                    'Unable to decrypt data, signature is not correct: '
                    '{0!s}'.format(e)) from e
            except fernet.InvalidToken as e:
                raise IOError(
                    'Unable to decrypt data, password wrong? (error '
                    '{0!s})'.format(e)) from e

            # TODO: Implement a manager.
            cred_obj = credentials.TimesketchPwdCredentials()
            try:
                cred_obj.deserialize(data_string)

                return cred_obj
            except TypeError:
                logger.debug('Credential object is not "timesketch" auth.')

            cred_obj = credentials.TimesketchOAuthCredentials()
            cred_obj.deserialize(data_string)
            return cred_obj
def load_credentials ( self , file_path = '' , password = '' , config_assistant = None ) : if not file_path : file_path = self . _filepath if not os . path . isfile ( file_path ) : return None if password : password = bytes ( password , 'utf-8' ) elif config_assistant : try : password = config_assistant . get_config ( 'cred_key' ) if not isinstance ( password , bytes ) : password = bytes ( password , 'utf-8' ) except KeyError as exc : raise IOError ( 'Not able to determine encryption key from ' 'config.' ) from exc else : raise IOError ( 'Neither password nor a configuration assistant passed to ' 'tool, unable to determine password.' ) with open ( file_path , 'rb' ) as fh : salt = fh . read ( self . SALT_LENGTH ) key = self . _get_key ( salt , password ) data = fh . read ( ) crypto = fernet . Fernet ( key ) try : data_string = crypto . decrypt ( data ) except fernet . InvalidSignature as e : raise IOError ( 'Unable to decrypt data, signature is not correct: ' '{0!s}' . format ( e ) ) from e except fernet . InvalidToken as e : raise IOError ( 'Unable to decrypt data, password wrong? (error ' '{0!s})' . format ( e ) ) from e # TODO: Implement a manager. cred_obj = credentials . TimesketchPwdCredentials ( ) try : cred_obj . deserialize ( data_string ) return cred_obj except TypeError : logger . debug ( 'Credential object is not "timesketch" auth.' ) cred_obj = credentials . TimesketchOAuthCredentials ( ) cred_obj . deserialize ( data_string ) return cred_obj