Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major Codebase Refactor for Easier Maintenance #38

Merged
merged 13 commits into from
Jan 17, 2018
Merged

Major Codebase Refactor for Easier Maintenance #38

merged 13 commits into from
Jan 17, 2018

Conversation

mide
Copy link
Contributor

@mide mide commented Jan 8, 2018

Breaking Changes

Under-the-hood Changes

  • Broke apart __init__.py into the following files (along with their purproses):
    • google.py is for all Google related functions. It includes the logic to perform the page scraping and SAML fetching.
    • amazon.py for AWS related fucntions. This performs the role extraction from the SAML and performs the AWS API call to get the access tokens.
    • configuration.py - This only maintains user options (anything the user specifies). Breaking this into it's own object allows us to perform much more robust testing and just pass around a single object instead of a handful of options.
    • util.py for common tooling

Added the following tests

  • Flake8 Python style testing. This is added into the TravisCI build script (.travis.yml).

  • test_configuration.py:

    • Test that invalid duration values get rejected.
    • Test that valid duration values are accepted.
    • Test that the default value of duration is max_duration
    • Test that invalid ask_role values get rejected.
    • Test that valid ask_role values are accepted.
    • Test that ask_role is an optional setting.
    • Test that invalid idp_id values get rejected.
    • Test that valid idp_id values are accepted.
    • Test that invalid sp_id values get rejected.
    • Test that valid username values are accepted.
    • Test that invalid username values get rejected.
    • Test that valid sp_id values are accepted.
    • Test that the default value of profile is sts
    • Test that invalid profile values get rejected.
    • Test that valid profile values are accepted.
    • Test all profile_defaults.
    • Test that invalid region values get rejected.
    • Test that valid region values are accepted.
    • Test that the default value of region is ap_southeast_2
    • Test that invalid role_arn values get rejected.
    • Test that role_arn_is is an optional setting.
    • Test that valid role_arn values are accepted.
    • Test that invalid u2f_disabled values get rejected.
    • Test that valid u2f_disabled values are accepted.
    • Test that u2f_disabled_is is an optional setting.
  • test_amazon.py

    • Test that the sts boto client properly returns an STS client object.
    • Test that role extraction happens correctly given a valid SAML response.
    • Test that role extraction happens correctly given a SAML response with too many commas (See Error in case of extra comma #12)

Needed Work

In order to get tests to pass, I had to ignore Flake8 rule E722. We should go back and determine what the correct exceptions are to catch and only catch those.

Note

Please don't feel you need to accept this, but do please let me know. If this breaks Cevo's workflows, I may just end up maintaining my own fork.

@coveralls
Copy link

coveralls commented Jan 8, 2018

Coverage Status

Coverage increased (+4.8%) to 37.26% when pulling 0535c37 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@mide
Copy link
Contributor Author

mide commented Jan 8, 2018

Wow, only 4.8% increase? That's disappointing.

@stevemac007
Copy link
Contributor

I can't see any reason to not accept this work - looks really good, and setup much better to improve the quality of the testing. Only 4.8% is a good start, and will hopefully allow future enhancements to only improve on that value.

I personally prefer storing the details in the config file, makes re-auth easier if you've done it from the input prompts, especially seeing as locating the IDP and SP value in the first place is tricky.

What effort is there for adding that back in?

@SamBarker
Copy link

+1 for maintaining AWS/config support. We have started using google auth with a read only profile and elevating to a rw role as needed, ala sudo. We use AWS-google-auth for the read only login, naming the profile, we then have additional profiles in the config file which are based off the ro one ( we use this between organisations as well)

@mide
Copy link
Contributor Author

mide commented Jan 9, 2018

Sounds good @stevemac007 and @SamBarker - I will add the ~/.aws/config persistence back in. It shouldn't be too much work.

I do want to clarify though (for @SamBarker) the feature that I did remove (and will put back) is not writing the STS (aws_access_key_id and aws_secret_access_key) tokens to ~/.aws/credentials. It's writing various user settings (like email and role_arn) to ~/.aws/config.

👍 Thanks for the quick feedback folks. I'll get right on that change.

- Changes configuration object to allow for empty creation, and added
  "raise_if_invalid()" function to determine if the config is good.
- Added the ability to read from ~/.aws/config cached values.
@coveralls
Copy link

coveralls commented Jan 10, 2018

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 31a4932 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 31a4932 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 31a4932 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 7f57028 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 7f57028 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 7f57028 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-5.3%) to 27.098% when pulling 7f57028 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@mide
Copy link
Contributor Author

mide commented Jan 10, 2018

Implemented feedback; coverage is looking sad, which is a reminder to write tests for the new persistence logic.

@coveralls
Copy link

coveralls commented Jan 10, 2018

Coverage Status

Coverage increased (+5.6%) to 38.038% when pulling 0008520 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+5.6%) to 38.038% when pulling 0008520 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+6.1%) to 38.534% when pulling 0388b28 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+6.6%) to 39.007% when pulling 55d91fd on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+6.6%) to 39.007% when pulling 55d91fd on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+6.6%) to 39.007% when pulling 55d91fd on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+6.6%) to 39.007% when pulling 55d91fd on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@mide
Copy link
Contributor Author

mide commented Jan 10, 2018

Okay, this should be ready for another set of feedback. Please let me know your thoughts.

@nonspecialist
Copy link
Contributor

Dropping 2.6 is fine so long as we can make sure that people running 2.6 get a Helpful Message which lets them know why the tool stopped working, and what to do about it.

Otherwise, this PR looks shmick (which is a Good Thing)

@mide
Copy link
Contributor Author

mide commented Jan 11, 2018

Okay, good feedback @nonspecialist - I will have it display a note if the user is on Python 2.6.

@nonspecialist
Copy link
Contributor

I think my description is confusing, so I'll adjust it.

Missing any default value for the profile argument results in a NoneType being used to load, and re-load the profile, instead of using the profile "default"

@mide
Copy link
Contributor Author

mide commented Jan 16, 2018

Hmmm, okay. That's an interesting case. I'll take a look at that in the morning @nonspecialist. (I'm in the US - New York time zone)

@coveralls
Copy link

coveralls commented Jan 16, 2018

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 6226626 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@mide
Copy link
Contributor Author

mide commented Jan 16, 2018

@nonspecialist I was able to reproduce the problem and I feel that 2a53e49 should solve your problem. That being said, I don't think we want the default to be None and instead be sts. So now when you don't specify a profile, it should use sts.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.7%) to 41.136% when pulling 6bcc759 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

When no profile was specified, the code would take "None" as the
default, instead of "sts", which caused issues as None is not a string.

See #38 (comment)
@coveralls
Copy link

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+8.8%) to 41.23% when pulling 2a53e49 on mide:code-cleanup into 50bcd11 on cevoaustralia:master.

@SamBarker
Copy link

@mide sorry for the slow reply.

Being back in front of the computer again I've just outlined our cross account usage a bit more on #42 (comment) hopefully that makes our current use case a bit clearer.

@mide
Copy link
Contributor Author

mide commented Jan 16, 2018

@SamBarker - I think I'm a little lost, is that just for context, or do you expect changes from that comment?

@SamBarker
Copy link

SamBarker commented Jan 16, 2018 via email

@mide
Copy link
Contributor Author

mide commented Jan 16, 2018

Great! Thank you!

@nonspecialist
Copy link
Contributor

Excellent! Works for my bizarre-o ~/.aws/config with and without specifying a profile. I like the coalesce cleanup too.

👍

@nonspecialist nonspecialist self-requested a review January 16, 2018 22:22
Copy link
Contributor

@nonspecialist nonspecialist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. This should make it much easier to work on too.

@mide
Copy link
Contributor Author

mide commented Jan 16, 2018

Thanks!

@stevemac007
Copy link
Contributor

Looks great @mide - I've confirmed that my existing config works well.
Lets get this merged and then we can look at updating the remaining open PR's.

@stevemac007 stevemac007 merged commit 6f3357a into cevoaustralia:master Jan 17, 2018
@mide mide deleted the code-cleanup branch January 17, 2018 15:06
@cliveza
Copy link

cliveza commented Jan 17, 2018

@stevemac007 Could we get a new python package please?

@nonspecialist
Copy link
Contributor

@cliveza the travis build should publish a new package automatically, but TravisCI has had some problems over the past 24 hours. I'll check the build and kick it manually if need be

@nonspecialist
Copy link
Contributor

@cliveza pypi and Docker tags have been updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants