Skip to content

Commit

Permalink
Clean up ini parsing, initial logging
Browse files Browse the repository at this point in the history
TODO:
  - clean up process_okta_org_url / process_okta_app_url logic
  - add getenv() calls to early_logging setup
  - add unit tests
  - add tests for original request
  • Loading branch information
pcmxgti committed Sep 20, 2022
1 parent 9f13046 commit 701f4c3
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 112 deletions.
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
black>=22.1.0
coveragepy-lcov; python_version >= '3.8'
docutils
flake8
flake8>=5.0.0
flake8-black
flake8-colors
flake8-docstrings
flake8-import-order
pep8-naming
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_set_okta_password(mocker):
("https://acme.okta.org/app/UserHome", False),
("http://login.acme.org/home/amazon_aws/0123456789abcdef0123/456", False),
("https://login.acme.org/?abc=def", False),
("acme.okta.org", True),
("acme.okta.org", False),
("https://acme.okta.org/", True),
],
)
Expand Down
5 changes: 3 additions & 2 deletions tokendito/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def handle_assume_role(role_arn, provider_arn, encoded_xml, duration, default_er
return assume_role_response


def ensure_keys_work(assume_role_response):
def assert_credentials(assume_role_response):
"""Validate the temporary AWS credentials.
:param aws_access_key: AWS access key
Expand All @@ -174,7 +174,8 @@ def ensure_keys_work(assume_role_response):
aws_secret_access_key=aws_secret_key,
aws_session_token=aws_session_token,
)
client.get_caller_identity()
identity = client.get_caller_identity()
logger.debug(f"Logged on with role ARN: {identity['Arn']}")
except Exception as auth_error:
logger.error(f"There was an error authenticating your keys with AWS: {auth_error}")
sys.exit(1)
Expand Down
3 changes: 1 addition & 2 deletions tokendito/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def cli(args):
"""Tokendito retrieves AWS credentials after authenticating with Okta."""
# Set some required initial values
user.process_options(args)
user.setup_logging(config.user)
logger.debug(f"Final configuration is {config}")

user.process_okta_org_url(config)
Expand Down Expand Up @@ -55,7 +54,7 @@ def cli(args):

assume_role_response, role_name = aws.select_assumeable_role(auth_apps)

aws.ensure_keys_work(assume_role_response)
aws.assert_credentials(assume_role_response)

user.set_local_credentials(
assume_role_response, role_name, config.aws["region"], config.aws["output"]
Expand Down
Loading

0 comments on commit 701f4c3

Please sign in to comment.