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

iam-user - add ability to pick what parts of the iam-user to delete #2454

Merged
merged 5 commits into from
Jun 12, 2018

Conversation

thisisshi
Copy link
Member

@thisisshi thisisshi commented May 29, 2018

related to: #2450

New Functionality:

  • Specify parts of an iam-user to delete using options
    • console-access
    • access-keys
    • user-policies
    • mfa-devices
    • groups
    • ssh-keys
    • signing-certificates
    • service-specific-credentials
policies:
  - name: delete-user-console-access
    resource: iam-user
    filters:
      - UserName: test_user
    actions:
      - type: delete
        options:
          - console-access
  • To delete the user itself, use delete with no options (previous implementation):
policies:
  - name: delete-user
    resource: iam-user
    filters:
      - UserName: test_user
    actions:
      - type: delete

client.delete_user(UserName=r['UserName'])

OPTIONS = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you move the class vars above the methods in the class def

Copy link
Member Author

Choose a reason for hiding this comment

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

I originally had them above but the reference to OPTIONS.keys in schema required it to be below the method definitions. I'm thinking of moving the delete_* outside of the class itself, as delete_access_keys could actually be reused in the remove-keys

Copy link
Member Author

Choose a reason for hiding this comment

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

ended up switching to use getattr and using a dict of {str:str} to be able to move the class vars to the top while keeping the methods inside of the class for encapsulation

'ssh-keys': delete_ssh_keys,
'signing-certificates': delete_signing_certificates,
'services-specific-credentials': delete_service_specific_credentials,
'user': delete_user,
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should omit delete user as a config option doing it in isolation is error prone without its deps and its the default action.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was in between including/removing user as an option as the order of ops requires it to be last, I'll remove and change to an ordered dict and include special handling for when options is None

Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't include user in options then supplying options means that we should not delete the user?

def process(self, resources):
client = local_session(self.manager.session_factory).client('iam')
for r in resources:
self.log.debug('Deleting user %s options: %s' %
Copy link
Collaborator

Choose a reason for hiding this comment

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

per resource logging on the happy path, is a bit verbose even at the debug level

self.process_user(client, r)

def process_user(self, client, r):
options = self.data.get('options', list(self.OPTIONS.keys()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

in python2 dictionary ordering is random, so you could get the remove user first which would error out due to dependencies, the options dict needs to be an ordered dict to handle the order. it looks like your already handling this by hardcoding the 'user' option and then removing it separately, but using an ordered dict would resolve this more simply.

@@ -1129,61 +1258,18 @@ class UserDelete(BaseAction):
def process(self, resources):
client = local_session(self.manager.session_factory).client('iam')
for r in resources:
self.log.debug('Deleting user %s' % r['UserName'])
self.log.debug('Deleting user %s options: %s' %
Copy link
Collaborator

@kapilt kapilt May 31, 2018

Choose a reason for hiding this comment

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

can you pull this up out of the loop to say deleting n users with x options. the per resource logging even at the verbose level is a bit much.

@thisisshi thisisshi force-pushed the iam-user-delete-extend branch from 43e2ea0 to 0978c40 Compare June 1, 2018 15:22
Copy link
Collaborator

@kapilt kapilt left a comment

Choose a reason for hiding this comment

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

lgtm, thanks

@kapilt kapilt merged commit f0edc9a into cloud-custodian:master Jun 12, 2018
lamyanba pushed a commit to lamyanba/cloud-custodian that referenced this pull request Apr 23, 2019
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.

2 participants