def main(self): if self.args["recursive"] or self.args["pretend"]: # Figure out what we'd have to delete req = GetGroup( config=self.config, service=self.service, GroupName=self.args["GroupName"], DelegateAccount=self.params["DelegateAccount"], ) members = req.main().get("Users", []) req = ListGroupPolicies( config=self.config, service=self.service, GroupName=self.args["GroupName"], DelegateAccount=self.params["DelegateAccount"], ) policies = req.main().get("PolicyNames", []) else: # Just in case members = [] policies = [] if self.args["pretend"]: return {"members": [member["Arn"] for member in members], "policies": policies} else: if self.args["recursive"]: member_names = [member["UserName"] for member in members] req = RemoveUserFromGroup( config=self.config, service=self.service, GroupName=self.args["GroupName"], user_names=member_names, DelegateAccount=self.params["DelegateAccount"], ) req.main() for policy in policies: req = DeleteGroupPolicy( config=self.config, service=self.service, GroupName=self.args["GroupName"], PolicyName=policy, DelegateAccount=self.params["DelegateAccount"], ) req.main() return self.send()
def main(self): if self.args['recursive'] or self.args['pretend']: # Figure out what we'd have to delete req = GetGroup(config=self.config, service=self.service, GroupName=self.args['GroupName'], DelegateAccount=self.params['DelegateAccount']) members = req.main().get('Users', []) req = ListGroupPolicies( config=self.config, service=self.service, GroupName=self.args['GroupName'], DelegateAccount=self.params['DelegateAccount']) policies = req.main().get('PolicyNames', []) else: # Just in case members = [] policies = [] if self.args['pretend']: return { 'members': [member['Arn'] for member in members], 'policies': policies } else: if self.args['recursive']: member_names = [member['UserName'] for member in members] req = RemoveUserFromGroup( config=self.config, service=self.service, GroupName=self.args['GroupName'], user_names=member_names, DelegateAccount=self.params['DelegateAccount']) req.main() for policy in policies: req = DeleteGroupPolicy( config=self.config, service=self.service, GroupName=self.args['GroupName'], PolicyName=policy, DelegateAccount=self.params['DelegateAccount']) req.main() return self.send()