-
Notifications
You must be signed in to change notification settings - Fork 104
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
Adding _remove_permissions_from_roles() and extracting parts of repo_role() into shared methods. #213
Conversation
repokid/cli/repokid_cli.py
Outdated
@@ -48,6 +49,7 @@ | |||
from cloudaux.aws.iam import (delete_role_policy, get_account_authorization_details, get_role_inline_policies, | |||
put_role_policy) | |||
from cloudaux.aws.sts import sts_conn | |||
from policyuniverse import ARN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep this in alphabetical order grouped by import type (stdlib, third party libs, module imports)
repokid/cli/repokid_cli.py
Outdated
|
||
|
||
def _check_inline_policies_size(policies): | ||
"""Validate the policies, when converted to JSON without whitespace, remain under the size limit.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says validate policies remain under the limit but you return True when the size exceeds the limit.
repokid/cli/repokid_cli.py
Outdated
role_name = arn.name.split('/')[-1] | ||
|
||
role_id = find_role_in_cache(dynamo_table, account_number, role_name) | ||
_remove_permissions_from_role(account_number, permissions, role_name, role_id, dynamo_table, config, hooks, commit=commit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer putting the hook calling here so it's easier to see that it's happening.
repokid/cli/repokid_cli.py
Outdated
|
||
|
||
def _remove_permissions_from_role(account_number, permissions, role_name, role_id, dynamo_table, config, hooks, commit=False): | ||
"""Remove the given permissions from the given role. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is permissions here a single permission? A list of permissions? It's called permissions but below you reference "the selected permission".
repokid/cli/repokid_cli.py
Outdated
@@ -1052,6 +1155,12 @@ def main(): | |||
if args.get('find_roles_with_permission'): | |||
return find_roles_with_permission(args.get('<permission>'), dynamo_table) | |||
|
|||
if args.get('remove_permissions_from_roles'): | |||
permissions = args.get('--permissions') | |||
roles = args.get('--role-filename') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
roles seems like a list of roles but it's a filename, make the variable name consistent.
repokid/cli/repokid_cli.py
Outdated
@@ -1052,6 +1155,12 @@ def main(): | |||
if args.get('find_roles_with_permission'): | |||
return find_roles_with_permission(args.get('<permission>'), dynamo_table) | |||
|
|||
if args.get('remove_permissions_from_roles'): | |||
permissions = args.get('--permissions') | |||
roles = args.get('--role-filename') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a user perspective, where is the file supposed to come from? Do we want to provide other options to find the roles since we have a database?
In line with #44 should all new functions be following a standard around docstrings? Is this a situation where development should start as it means to go on? |
repokid/cli/repokid_cli.py
Outdated
@@ -48,6 +49,7 @@ | |||
from cloudaux.aws.iam import (delete_role_policy, get_account_authorization_details, get_role_inline_policies, | |||
put_role_policy) | |||
from cloudaux.aws.sts import sts_conn | |||
from policyuniverse.arn import ARN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: alphabetise the imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably have flake8 enforce import order if it's something we care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yes, as @mcpeak pointed this out, I will fix.
repokid/cli/repokid_cli.py
Outdated
def _check_access_advisor_age(role, role_name, account_number, max_days_old): | ||
"""Ensure access advisor data has been recently refreshed.""" | ||
old_aa_data_services = [] | ||
for aa_service in role.aa_data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this block be cleaned up using some variables for the various times/periods so that the arithmetic is easier to understand from a first look.
ie:
last_updated_time = datetime.datetime.strptime(aa_service['lastUpdated'], '%a, %d %b %Y %H:%M:%S %Z')
current_time = datetime.datetime.now()
expiration_time = datetime.timedelta(days=max_days_old)
if( last_updated_time < current_time - expiration_time):
old_aa_data_services.append(aa_service['serviceName'])
Probably need to play with var names, I'm tired and not picking the correct words/context for the block, but you get the idea of what I'm trying to convey.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was originally inline for the repo_role()
method. I refactored it into it's own method thinking I would need this code for the main method that I am adding, but it turns out that I don't. I'll move this back into repo_role()
, but won't be otherwise fixing the naming.
Not in this PR, anyways.
Thank you @JohnVonNeumann and @mcpeak for the review. I'll work on many of these items for this PR. Others are broader concerns that I may follow up on in other PRs. Again, thanks. |
4f1b6c3
to
42d097c
Compare
Things I think I've completed:
Todo:
|
This PR has been put through it's paces in our test environment.
Seems to work as expected. Future work may be to have the |
Adding _remove_permissions_from_roles() and extracting parts of repo_role() into shared methods.
Also updates the policy size checking to correctly remove all whitespace before checking the size.
Need a code review with @mcpeak.