(
        config_assistant: ConfigAssistant,
        token_password: Optional[Text] = '',
        confirm_choices: Optional[bool] = False,
        config_section: Optional[Text] = 'timesketch')
return None
Fill in missing configuration for a config assistant.

    This function will take in a configuration assistant object and check
    whether it is not fully configured. If it isn't it will ask the user
    to fill in the missing details.

    It will also check to see whether a password has been set if the auth
    is username/password and ask for a password to store credentials.

    Args:
        config_assistant (ConfigAssistant): a config assistant that might
            not be fully configured.
        token_password (str): an optional password to decrypt
            the credential token file.
        confirm_choices (bool): an optional bool. if set to the user is given
            a choice to change the value for all already configured parameters.
            This defaults to False.
        config_section (str): The configuration section to read from. This
            is optional and defaults to timesketch. This can be
            useful if you have multiple Timesketch servers to connect to,
            with each one of them having a separate section in the config
            file.
Fill in missing configuration for a config assistant.
Fill in missing configuration for a config assistant .
def configure_missing_parameters(
        config_assistant: ConfigAssistant,
        token_password: Optional[Text] = '',
        confirm_choices: Optional[bool] = False,
        config_section: Optional[Text] = 'timesketch'):
    """Fill in missing configuration for a config assistant.

    This function will take in a configuration assistant object and check
    whether it is not fully configured. If it isn't it will ask the user
    to fill in the missing details.

    It will also check to see whether a password has been set if the auth
    is username/password and ask for a password to store credentials.

    Args:
        config_assistant (ConfigAssistant): a config assistant that might
            not be fully configured.
        token_password (str): an optional password to decrypt
            the credential token file.
        confirm_choices (bool): an optional bool. if set to the user is given
            a choice to change the value for all already configured parameters.
            This defaults to False.
        config_section (str): The configuration section to read from. This
            is optional and defaults to timesketch. This can be
            useful if you have multiple Timesketch servers to connect to,
            with each one of them having a separate section in the config
            file.
    """
    just_configured = []

    for field in config_assistant.missing:
        hint = config_assistant.CONFIG_HINTS.get(field, '')
        value = cli_input.ask_question(
            f'What is the value for <{field}> ({hint})', input_type=str)
        if value:
            config_assistant.set_config(field, value)
            just_configured.append(field)

    if config_assistant.missing:
        # We still have unanswered questions.
        return configure_missing_parameters(
            config_assistant=config_assistant,
            token_password=token_password,
            confirm_choices=confirm_choices,
            config_section=config_section)

    if confirm_choices:
        # Go through prior answered parameters.
        for field in config_assistant.parameters:
            if field in ('cred_key', 'verify', 'username'):
                continue
            # We don't want to re-ask the user about the field they just
            # configured.
            if field in just_configured:
                continue

            answer = config_assistant.get_config(field)
            change = cli_input.confirm_choice(
                f'Want to change the value for "{field}" [{answer}]',
                default=False, abort=False)
            if not change:
                continue
            hint = config_assistant.CONFIG_HINTS.get(field, '')
            value = cli_input.ask_question(
                f'What is the value for <{field}> ({hint})', input_type=str)
            if value:
                config_assistant.set_config(field, value)

    try:
        file_path = config_assistant.get_config('token_file_path')
    except KeyError:
        file_path = ''
    config_assistant.save_config(
        section=config_section, token_file_path=file_path)
    credential_storage = crypto.CredentialStorage(file_path=file_path)
    credentials = credential_storage.load_credentials(
        config_assistant=config_assistant, password=token_password)

    # Check if we are using username/password and we don't have credentials
    # saved.
    auth_mode = config_assistant.get_config('auth_mode')
    if auth_mode != 'userpass':
        return None

    choice = False
    if credentials and confirm_choices:
        choice = cli_input.confirm_choice(
            'Want to change credentials?',
            default=False, abort=False)

    if not choice and credentials:
        return None

    username = config_assistant.get_config('username')
    if choice:
        value = cli_input.ask_question(
            'What is the username?',
            input_type=str, default=username)
        if value:
            username = value
            config_assistant.set_config('username', value)

    password = cli_input.ask_question(
        'Password for user {0:s}'.format(username), input_type=str,
        hide_input=True, default='***')
    credentials = ts_credentials.TimesketchPwdCredentials()
    credentials.credential = {
        'username': username,
        'password': password
    }
    cred_storage = crypto.CredentialStorage(file_path=file_path)
    cred_storage.save_credentials(
        credentials, password=token_password,
        config_assistant=config_assistant)
    config_assistant.save_config(
        section=config_section, token_file_path=file_path)
    return None
def configure_missing_parameters ( config_assistant : ConfigAssistant , token_password : Optional [ Text ] = '' , confirm_choices : Optional [ bool ] = False , config_section : Optional [ Text ] = 'timesketch' ) : just_configured = [ ] for field in config_assistant . missing : hint = config_assistant . CONFIG_HINTS . get ( field , '' ) value = cli_input . ask_question ( f'What is the value for <{field}> ({hint})' , input_type = str ) if value : config_assistant . set_config ( field , value ) just_configured . append ( field ) if config_assistant . missing : # We still have unanswered questions. return configure_missing_parameters ( config_assistant = config_assistant , token_password = token_password , confirm_choices = confirm_choices , config_section = config_section ) if confirm_choices : # Go through prior answered parameters. for field in config_assistant . parameters : if field in ( 'cred_key' , 'verify' , 'username' ) : continue # We don't want to re-ask the user about the field they just # configured. if field in just_configured : continue answer = config_assistant . get_config ( field ) change = cli_input . confirm_choice ( f'Want to change the value for "{field}" [{answer}]' , default = False , abort = False ) if not change : continue hint = config_assistant . CONFIG_HINTS . get ( field , '' ) value = cli_input . ask_question ( f'What is the value for <{field}> ({hint})' , input_type = str ) if value : config_assistant . set_config ( field , value ) try : file_path = config_assistant . get_config ( 'token_file_path' ) except KeyError : file_path = '' config_assistant . save_config ( section = config_section , token_file_path = file_path ) credential_storage = crypto . CredentialStorage ( file_path = file_path ) credentials = credential_storage . load_credentials ( config_assistant = config_assistant , password = token_password ) # Check if we are using username/password and we don't have credentials # saved. auth_mode = config_assistant . get_config ( 'auth_mode' ) if auth_mode != 'userpass' : return None choice = False if credentials and confirm_choices : choice = cli_input . confirm_choice ( 'Want to change credentials?' , default = False , abort = False ) if not choice and credentials : return None username = config_assistant . get_config ( 'username' ) if choice : value = cli_input . ask_question ( 'What is the username?' , input_type = str , default = username ) if value : username = value config_assistant . set_config ( 'username' , value ) password = cli_input . ask_question ( 'Password for user {0:s}' . format ( username ) , input_type = str , hide_input = True , default = '***' ) credentials = ts_credentials . TimesketchPwdCredentials ( ) credentials . credential = { 'username' : username , 'password' : password } cred_storage = crypto . CredentialStorage ( file_path = file_path ) cred_storage . save_credentials ( credentials , password = token_password , config_assistant = config_assistant ) config_assistant . save_config ( section = config_section , token_file_path = file_path ) return None