(
            self, token_password: Optional[Text] = '')
return client.TimesketchApi(
            host_uri=self._config.get('host_uri'),
            username=username,
            password=password,
            verify=self._config.get('verify', True),
            client_id=self._config.get('client_id', ''),
            client_secret=self._config.get('client_secret', ''),
            auth_mode=auth_mode,
        )
Returns a Timesketch API client if possible.

        Args:
            token_password (str): an optional password to decrypt
                the credential token file.
Returns a Timesketch API client if possible.
Returns a Timesketch API client if possible .
def get_client(
            self, token_password: Optional[Text] = '') -> Optional[
                client.TimesketchApi]:
        """Returns a Timesketch API client if possible.

        Args:
            token_password (str): an optional password to decrypt
                the credential token file.
        """
        if self.missing:
            return None

        auth_mode = self._config.get('auth_mode', 'userpass')
        # TODO: Remove shortly, temporary due to change of
        # 'timesketch' to 'userpass'
        if auth_mode == 'timesketch':
            auth_mode = 'userpass'

        file_path = self._config.get('token_file_path', '')
        credential_storage = crypto.CredentialStorage(file_path=file_path)
        credentials = credential_storage.load_credentials(
            config_assistant=self, password=token_password)

        if auth_mode.startswith('oauth'):
            if not credentials:
                return client.TimesketchApi(
                    host_uri=self._config.get('host_uri'),
                    username=self._config.get('username'),
                    password=self._config.get('password', ''),
                    verify=self._config.get('verify', True),
                    client_id=self._config.get('client_id', ''),
                    client_secret=self._config.get('client_secret', ''),
                    auth_mode=auth_mode,
                )

            ts = client.TimesketchApi(
                host_uri=self._config.get('host_uri'),
                username=self._config.get('username'),
                auth_mode=auth_mode,
                create_session=False)
            ts.set_credentials(credentials)
            session = auth_requests.AuthorizedSession(credentials.credential)
            try:
                ts.refresh_oauth_token()
            except auth_requests.RefreshError as e:
                logger.error(
                    'Unable to refresh credentials, with error: %s', e)
                return None
            session = ts.authenticate_oauth_session(session)
            ts.set_session(session)
            return ts

        if credentials:
            username = credentials.credential.get(
                'username', self._config.get('username', ''))
            password = credentials.credential.get(
                'password', self._config.get('password', ''))
        else:
            username = self._config.get('username', '')
            password = self._config.get('password', '')

        return client.TimesketchApi(
            host_uri=self._config.get('host_uri'),
            username=username,
            password=password,
            verify=self._config.get('verify', True),
            client_id=self._config.get('client_id', ''),
            client_secret=self._config.get('client_secret', ''),
            auth_mode=auth_mode,
        )
def get_client ( self , token_password : Optional [ Text ] = '' ) -> Optional [ client . TimesketchApi ] : if self . missing : return None auth_mode = self . _config . get ( 'auth_mode' , 'userpass' ) # TODO: Remove shortly, temporary due to change of # 'timesketch' to 'userpass' if auth_mode == 'timesketch' : auth_mode = 'userpass' file_path = self . _config . get ( 'token_file_path' , '' ) credential_storage = crypto . CredentialStorage ( file_path = file_path ) credentials = credential_storage . load_credentials ( config_assistant = self , password = token_password ) if auth_mode . startswith ( 'oauth' ) : if not credentials : return client . TimesketchApi ( host_uri = self . _config . get ( 'host_uri' ) , username = self . _config . get ( 'username' ) , password = self . _config . get ( 'password' , '' ) , verify = self . _config . get ( 'verify' , True ) , client_id = self . _config . get ( 'client_id' , '' ) , client_secret = self . _config . get ( 'client_secret' , '' ) , auth_mode = auth_mode , ) ts = client . TimesketchApi ( host_uri = self . _config . get ( 'host_uri' ) , username = self . _config . get ( 'username' ) , auth_mode = auth_mode , create_session = False ) ts . set_credentials ( credentials ) session = auth_requests . AuthorizedSession ( credentials . credential ) try : ts . refresh_oauth_token ( ) except auth_requests . RefreshError as e : logger . error ( 'Unable to refresh credentials, with error: %s' , e ) return None session = ts . authenticate_oauth_session ( session ) ts . set_session ( session ) return ts if credentials : username = credentials . credential . get ( 'username' , self . _config . get ( 'username' , '' ) ) password = credentials . credential . get ( 'password' , self . _config . get ( 'password' , '' ) ) else : username = self . _config . get ( 'username' , '' ) password = self . _config . get ( 'password' , '' ) return client . TimesketchApi ( host_uri = self . _config . get ( 'host_uri' ) , username = username , password = password , verify = self . _config . get ( 'verify' , True ) , client_id = self . _config . get ( 'client_id' , '' ) , client_secret = self . _config . get ( 'client_secret' , '' ) , auth_mode = auth_mode , )