How to use the tokendito.settings function in tokendito

To help you get started, we’ve selected a few tokendito 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 dowjones / tokendito / tokendito / okta_helpers.py View on Github external
except KeyError:
        logging.error("Okta auth failed: "
                      "Could not retrieve list of MFA methods")
        logging.debug("Error parsing response: {}".format(
            json.dumps(primary_auth)))
        sys.exit(1)

    mfa_setup_statuses = [
        d['status'] for d in mfa_options if 'status' in d and d['status'] != "ACTIVE"]

    if len(mfa_setup_statuses) == len(mfa_options):
        logging.error("MFA not configured. "
                      "Please enable MFA on your account and try again.")
        sys.exit(2)

    preset_mfa = settings.mfa_method
    available_mfas = [d['factorType'] for d in mfa_options]
    if preset_mfa is not None and preset_mfa in available_mfas:
        mfa_index = available_mfas.index(settings.mfa_method)
    else:
        logging.warning(
            "No MFA provided or provided MFA does not exist. [{}]".format(
                settings.mfa_method))
        mfa_index = helpers.select_preferred_mfa_index(mfa_options)

    # time to challenge the mfa option
    selected_mfa_option = mfa_options[mfa_index]
    logging.debug("Selected MFA is [{}]".format(selected_mfa_option))

    mfa_challenge_url = selected_mfa_option['_links']['verify']['href']

    payload = helpers.prepare_payload(stateToken=primary_auth['stateToken'],
github dowjones / tokendito / tokendito / helpers.py View on Github external
def process_arguments(args):
    """Process command-line arguments.

    :param args: argparse object
    :return: None
    """
    for (key, val) in vars(args).items():
        if hasattr(settings, key) and val is not None:
            logging.debug(
                'Set option {}={} from command line'.format(key, val))
            setattr(settings, key, val)
github dowjones / tokendito / tokendito / helpers.py View on Github external
"""
    cred_file = settings.aws_shared_credentials_file
    cred_dir = os.path.dirname(cred_file)
    logging.debug("Update AWS credentials in: [{}]".format(cred_file))

    create_directory(cred_dir)

    config = configparser.RawConfigParser()
    if os.path.isfile(cred_file):
        config.read(cred_file, encoding=settings.encoding)
    if not config.has_section(profile):
        config.add_section(profile)
    config.set(profile, 'aws_access_key_id', aws_access_key)
    config.set(profile, 'aws_secret_access_key', aws_secret_key)
    config.set(profile, 'aws_session_token', aws_session_token)
    with open(cred_file, 'w+', encoding=settings.encoding) as file:
        config.write(file)
github dowjones / tokendito / tokendito / helpers.py View on Github external
def update_aws_config(profile, output, region):
    """Update AWS config file in ~/.aws/config file.

    :param profile: tokendito profile
    :param output: aws output
    :param region: aws region
    :return:

    """
    config_file = settings.aws_config_file
    config_dir = os.path.dirname(config_file)
    logging.debug("Update AWS config to file: [{}]".format(config_file))

    create_directory(config_dir)

    # Prepend the word profile the the profile name
    profile = 'profile {}'.format(profile)
    config = configparser.RawConfigParser()
    if os.path.isfile(config_file):
        config.read(config_file, encoding=settings.encoding)
    if not config.has_section(profile):
        config.add_section(profile)
    config.set(profile, 'output', output)
    config.set(profile, 'region', region)

    with open(config_file, 'w+', encoding=settings.encoding) as file:
github dowjones / tokendito / tokendito / helpers.py View on Github external
def set_okta_username():
    """Set okta username in a constant settings variable.

    :return: okta_username

    """
    logging.debug("Set okta username in a constant settings variable.")

    if settings.okta_username == '':
        okta_username = input('Username: ')
        setattr(settings, 'okta_username', to_unicode(okta_username))
        logging.debug('username set to {} interactively'.format(
            settings.okta_username))

    return settings.okta_username