How to use the tokendito.settings.aws_shared_credentials_file 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 / helpers.py View on Github external
def update_aws_credentials(profile, aws_access_key, aws_secret_key, aws_session_token):
    """Update AWS credentials in ~/.aws/credentials default file.

    :param profile: AWS profile name
    :param aws_access_key: AWS access key
    :param aws_secret_key: AWS secret access key
    :param aws_session_token: Session token
    """
    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 print_selected_role(profile_name, expiration_time):
    """Print details about how to assume role.

    :param profile_name: AWS profile name
    :param expiration_time: Credentials expiration time
    :return:

    """
    msg = (
        '\nGenerated profile \'{}\' in {}.\n'
        '\nUse profile to authenticate to AWS:\n\t'
        'aws --profile \'{}\' sts get-caller-identity'
        '\nOR\n\t'
        'export AWS_PROFILE=\'{}\'\n\n'
        'Credentials are valid until {}.'
    ).format(profile_name, settings.aws_shared_credentials_file,
             profile_name, profile_name, expiration_time)

    return print(msg)