Skip to content

Commit

Permalink
Merge branch 'master' into batch-limit
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksanders committed Jul 29, 2020
2 parents 5d61221 + c233f4d commit d2a69b2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- Repokid Maintainers <repokid-maintainers@netflix.com>
- Patrick Kelley <pkelley@netflix.com>
- Travis McPeak <tmcpeak@netflix.com>
- Patrick Sanders <psanders@netflix.com>
11 changes: 7 additions & 4 deletions repokid/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def _repo_role(
LOGGER.error(
"AAData older than threshold for these services: {} (role: {}, account {})".format(
old_aa_data_services, role_name, account_number
)
),
exc_info=True,
)
continuing = False

Expand Down Expand Up @@ -319,7 +320,7 @@ def _rollback_role(
message = "Unable to push policy {}. Error: {} (role: {} account {})".format(
policy_name, e.message, role.role_name, account_number
)
LOGGER.error(message)
LOGGER.error(message, exc_info=True)
errors.append(message)

else:
Expand All @@ -343,7 +344,7 @@ def _rollback_role(
message = "Unable to delete policy {}. Error: {} (role: {} account {})".format(
policy_name, e.message, role.role_name, account_number
)
LOGGER.error(message)
LOGGER.error(message, exc_info=True)
errors.append(message)

partial_update_role_data(
Expand Down Expand Up @@ -508,6 +509,8 @@ def _repo_stats(output_file, dynamo_table, account_number=None):
for row in rows:
csv_writer.writerow(row)
except IOError as e:
LOGGER.error("Unable to write file {}: {}".format(output_file, e))
LOGGER.error(
"Unable to write file {}: {}".format(output_file, e), exc_info=True
)
else:
LOGGER.info("Successfully wrote stats to {}".format(output_file))
33 changes: 26 additions & 7 deletions repokid/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def display_role(account_number: str, role_name: str):
return _display_role(account_number, role_name, dynamo_table, CONFIG, hooks)


def repo_role(account_number: str, role_name: str, commit: bool = False):
def repo_role(
account_number: str, role_name: str, commit: bool = False, update: bool = True
):
"""
Library wrapper to calculate what repoing can be done for a role and then actually do it if commit is set.
Expand All @@ -141,6 +143,7 @@ def repo_role(account_number: str, role_name: str, commit: bool = False):
account_number (string): The current account number Repokid is being run against
role_name (string)
commit (bool)
update (bool)
Returns:
None
Expand Down Expand Up @@ -196,7 +199,9 @@ def schedule_repo(account_number: str):
return _schedule_repo(account_number, dynamo_table, CONFIG, hooks)


def repo_all_roles(account_number: str, commit: bool = False, limit: int = 0):
def repo_all_roles(
account_number: str, commit: bool = False, update: bool = True, limit: int = 0
):
"""
Convenience wrapper for repo_roles() with scheduled=False.
Expand All @@ -205,15 +210,20 @@ def repo_all_roles(account_number: str, commit: bool = False, limit: int = 0):
Args:
account_number (string): The current account number Repokid is being run against
commit (bool): actually make the changes
update (bool): if True run update_role_cache before repoing
limit (int): limit number of roles to be repoed per run (0 is unlimited)
Returns:
None
"""
return repo_roles(account_number, commit=commit, scheduled=False, limit=limit)
return repo_roles(
account_number, commit=commit, scheduled=False, update=update, limit=limit
)


def repo_scheduled_roles(account_number: str, commit: bool = False, limit: int = 0):
def repo_scheduled_roles(
account_number: str, commit: bool = False, update: bool = True, limit: int = 0
):
"""
Convenience wrapper for repo_roles() with scheduled=True.
Expand All @@ -222,16 +232,23 @@ def repo_scheduled_roles(account_number: str, commit: bool = False, limit: int =
Args:
account_number (string): The current account number Repokid is being run against
commit (bool): actually make the changes
update (bool): if True run update_role_cache before repoing
limit (int): limit number of roles to be repoed per run (0 is unlimited)
Returns:
None
"""
return repo_roles(account_number, commit=commit, scheduled=True, limit=limit)
return repo_roles(
account_number, commit=commit, scheduled=True, update=update, limit=limit
)


def repo_roles(
account_number: str, commit: bool = False, scheduled: bool = False, limit: int = 0
account_number: str,
commit: bool = False,
scheduled: bool = False,
update: bool = True,
limit: int = 0,
):
"""
Library wrapper to repo all scheduled or eligible roles in an account. Collect any errors and display them at the
Expand All @@ -243,12 +260,14 @@ def repo_roles(
account_number (string): The current account number Repokid is being run against
commit (bool): actually make the changes
scheduled (bool): if True only repo the scheduled roles, if False repo all the (eligible) roles
update (bool): if True run update_role_cache before repoing
limit (int): limit number of roles to be repoed per run (0 is unlimited)
Returns:
None
"""
_update_role_cache(account_number, dynamo_table, CONFIG, hooks)
if update:
_update_role_cache(account_number, dynamo_table, CONFIG, hooks)
return _repo_all_roles(
account_number,
dynamo_table,
Expand Down
2 changes: 1 addition & 1 deletion repokid/utils/dynamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def dynamo_get_or_create_table(**dynamo_config):
)

except BotoClientError as e:
LOGGER.error(e)
LOGGER.error(e, exc_info=True)
return table


Expand Down

0 comments on commit d2a69b2

Please sign in to comment.