Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Deploy pypi (#32)
Browse files Browse the repository at this point in the history
* Deploy to pypi

* replace flake8 with black

* remove pep8
  • Loading branch information
stlava authored Dec 16, 2021
1 parent a658049 commit fe3e5ea
Show file tree
Hide file tree
Showing 24 changed files with 1,017 additions and 991 deletions.
34 changes: 23 additions & 11 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ workflows:
- test-3.9
- test-3.8
- test-3.7
- test-3.6
- upload:
requires: [test-3.7, test-3.8, test-3.9]
filters:
tags:
only: /[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/

jobs:
test-3.9: &test-template
docker:
Expand All @@ -27,15 +34,10 @@ jobs:
. venv/bin/activate
nosetests -vv --with-coverage --cover-erase --cover-package=nd_okta_auth
- run:
name: pep8
command: |
. venv/bin/activate
python setup.py pep8
- run:
name: flake8
name: black
command: |
. venv/bin/activate
python setup.py flake8
black nd_okta_auth
test-3.8:
<<: *test-template
Expand All @@ -47,7 +49,17 @@ jobs:
docker:
- image: circleci/python:3.7

test-3.6:
<<: *test-template
upload:
docker:
- image: circleci/python:3.6
- image: circleci/python:3.9
steps:
- checkout
- run:
name: build package
command: |
pip install twine
python setup.py sdist
- run:
name: upload package
command: |
twine upload dist/*
44 changes: 23 additions & 21 deletions nd_okta_auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@


def user_input(text):
'''Wraps input() making testing support of py2 and py3 easier'''
"""Wraps input() making testing support of py2 and py3 easier"""
return input(text)


def setup_logging():
'''Returns back a pretty color-coded logger'''
"""Returns back a pretty color-coded logger"""
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = rainbow_logging_handler.RainbowLoggingHandler(sys.stdout)
fmt = '%(asctime)-10s (%(levelname)s) %(message)s'
fmt = "%(asctime)-10s (%(levelname)s) %(message)s"
formatter = logging.Formatter(fmt)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger


def login(aws_profile: str,
okta_appid: str,
okta_org: str,
username: str,
reup: bool,
debug: bool = False):
def login(
aws_profile: str,
okta_appid: str,
okta_org: str,
username: str,
reup: bool,
debug: bool = False,
):
# Generate our logger first, and write out our app name and version
log = setup_logging()
log.info('%s v%s' % (__desc__, __version__))
log.info("%s v%s" % (__desc__, __version__))

if debug:
log.setLevel(logging.DEBUG)
Expand All @@ -53,15 +55,14 @@ def login(aws_profile: str,
try:
okta_client = okta.OktaSaml(okta_org, username, password)
except okta.EmptyInput:
log.error('Cannot enter a blank string for any input')
log.error("Cannot enter a blank string for any input")
raise

# Authenticate the Okta client. If necessary, we will ask for MFA input.
try:
okta_client.auth()
except okta.InvalidPassword:
log.error('Invalid Username ({user}) or Password'.format(
user=username))
log.error("Invalid Username ({user}) or Password".format(user=username))
raise
except okta.ExhaustedFactors as e:
log.error(e)
Expand All @@ -77,15 +78,16 @@ def login(aws_profile: str,
# still valid. If it is, sleep a bit and skip to the next execution of
# the loop.
if session and session.is_valid:
log.debug('Credentials are still valid, sleeping')
log.debug("Credentials are still valid, sleeping")
time.sleep(15)
continue

log.info('Getting SAML Assertion from {org}'.format(org=okta_org))
log.info("Getting SAML Assertion from {org}".format(org=okta_org))

try:
assertion = okta_client.get_assertion(appid=okta_appid,
apptype='amazon_aws')
assertion = okta_client.get_assertion(
appid=okta_appid, apptype="amazon_aws"
)
session = aws.Session(assertion, profile=aws_profile)

# If role_selection is set we're in a reup loop. Re-set the role on
Expand All @@ -97,15 +99,15 @@ def login(aws_profile: str,
session.assume_role()

except aws.MultipleRoles:
log.warning('Multiple AWS roles found; please select one')
log.warning("Multiple AWS roles found; please select one")
roles = session.available_roles()
for role_index, role in enumerate(roles):
print("[{}] Role: {}".format(role_index, role["role"]))
role_selection = user_input('Select a role from above: ')
role_selection = user_input("Select a role from above: ")
session.set_role(role_selection)
session.assume_role()
except requests.exceptions.ConnectionError:
log.warning('Connection error... will retry')
log.warning("Connection error... will retry")
time.sleep(5)
continue

Expand All @@ -114,5 +116,5 @@ def login(aws_profile: str,
if not reup:
break

log.info('Reup enabled, sleeping...')
log.info("Reup enabled, sleeping...")
time.sleep(5)
Loading

0 comments on commit fe3e5ea

Please sign in to comment.