# vim: set filetype=python ts=4 sw=4
# -*- coding: utf-8 -*-
"""This module retrieves AWS credentials after authenticating with Okta."""
from __future__ import absolute_import, division, print_function, unicode_literals

import logging

from future import standard_library
from tokendito import aws_helpers
from tokendito import helpers
from tokendito import okta_helpers
from tokendito import settings

standard_library.install_aliases()


def cli(args):
    """Tokendito retrieves AWS credentials after authenticating with Okta."""
    # Set some required initial values
    args = helpers.setup(args)

    logging.debug("tokendito retrieves AWS credentials after authenticating with Okta.")

    # Collect and organize user specific information
    helpers.process_options(args)

    # Authenticate okta and AWS also use assumerole to assign the role
    logging.debug("Authenticate user with Okta and AWS.")

    secret_session_token = okta_helpers.authenticate_user(
        settings.okta_org, settings.okta_username, settings.okta_password
    )

    saml_response_string, saml_xml = aws_helpers.authenticate_to_roles(
        secret_session_token, settings.okta_aws_app_url
    )

    assume_role_response, role_name = aws_helpers.select_assumeable_role(
        saml_response_string, saml_xml
    )

    aws_helpers.ensure_keys_work(assume_role_response)

    helpers.set_local_credentials(
        assume_role_response, role_name, settings.aws_region, settings.aws_output
    )

[((14, 0, 14, 34), 'future.standard_library.install_aliases', 'standard_library.install_aliases', ({}, {}), '()', False, 'from future import standard_library\n'), ((20, 11, 20, 30), 'tokendito.helpers.setup', 'helpers.setup', ({(20, 25, 20, 29): 'args'}, {}), '(args)', False, 'from tokendito import helpers\n'), ((22, 4, 22, 88), 'logging.debug', 'logging.debug', ({(22, 18, 22, 87): '"""tokendito retrieves AWS credentials after authenticating with Okta."""'}, {}), "(\n    'tokendito retrieves AWS credentials after authenticating with Okta.')", False, 'import logging\n'), ((25, 4, 25, 33), 'tokendito.helpers.process_options', 'helpers.process_options', ({(25, 28, 25, 32): 'args'}, {}), '(args)', False, 'from tokendito import helpers\n'), ((28, 4, 28, 57), 'logging.debug', 'logging.debug', ({(28, 18, 28, 56): '"""Authenticate user with Okta and AWS."""'}, {}), "('Authenticate user with Okta and AWS.')", False, 'import logging\n'), ((30, 27, 32, 5), 'tokendito.okta_helpers.authenticate_user', 'okta_helpers.authenticate_user', ({(31, 8, 31, 25): 'settings.okta_org', (31, 27, 31, 49): 'settings.okta_username', (31, 51, 31, 73): 'settings.okta_password'}, {}), '(settings.okta_org, settings.okta_username,\n    settings.okta_password)', False, 'from tokendito import okta_helpers\n'), ((34, 37, 36, 5), 'tokendito.aws_helpers.authenticate_to_roles', 'aws_helpers.authenticate_to_roles', ({(35, 8, 35, 28): 'secret_session_token', (35, 30, 35, 55): 'settings.okta_aws_app_url'}, {}), '(secret_session_token, settings.\n    okta_aws_app_url)', False, 'from tokendito import aws_helpers\n'), ((38, 38, 40, 5), 'tokendito.aws_helpers.select_assumeable_role', 'aws_helpers.select_assumeable_role', ({(39, 8, 39, 28): 'saml_response_string', (39, 30, 39, 38): 'saml_xml'}, {}), '(saml_response_string, saml_xml)', False, 'from tokendito import aws_helpers\n'), ((42, 4, 42, 54), 'tokendito.aws_helpers.ensure_keys_work', 'aws_helpers.ensure_keys_work', ({(42, 33, 42, 53): 'assume_role_response'}, {}), '(assume_role_response)', False, 'from tokendito import aws_helpers\n'), ((44, 4, 46, 5), 'tokendito.helpers.set_local_credentials', 'helpers.set_local_credentials', ({(45, 8, 45, 28): 'assume_role_response', (45, 30, 45, 39): 'role_name', (45, 41, 45, 60): 'settings.aws_region', (45, 62, 45, 81): 'settings.aws_output'}, {}), '(assume_role_response, role_name, settings.\n    aws_region, settings.aws_output)', False, 'from tokendito import helpers\n')]