mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 18:04:02 -07:00
Bulk autopep8 (modules)
As agreed in 2017-12-07 Core meeting bulk fix pep8 issues Generated using: autopep8 1.3.3 (pycodestyle: 2.3.1) autopep8 -r --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules Manually fix issues that autopep8 has introduced
This commit is contained in:
parent
d13d7e9404
commit
c57a7f05e1
314 changed files with 3462 additions and 3383 deletions
|
@ -120,6 +120,7 @@ try:
|
|||
except ImportError:
|
||||
HAS_BOTO3 = False
|
||||
|
||||
|
||||
def get_arn_from_kms_alias(kms, aliasname):
|
||||
ret = kms.list_aliases()
|
||||
key_id = None
|
||||
|
@ -138,12 +139,14 @@ def get_arn_from_kms_alias(kms, aliasname):
|
|||
return k['KeyArn']
|
||||
raise Exception('could not find key from id: {}'.format(key_id))
|
||||
|
||||
|
||||
def get_arn_from_role_name(iam, rolename):
|
||||
ret = iam.get_role(RoleName=rolename)
|
||||
if ret.get('Role') and ret['Role'].get('Arn'):
|
||||
return ret['Role']['Arn']
|
||||
raise Exception('could not find arn for name {}.'.format(rolename))
|
||||
|
||||
|
||||
def do_grant(kms, keyarn, role_arn, granttypes, mode='grant', dry_run=True, clean_invalid_entries=True):
|
||||
ret = {}
|
||||
keyret = kms.get_key_policy(KeyId=keyarn, PolicyName='default')
|
||||
|
@ -179,10 +182,10 @@ def do_grant(kms, keyarn, role_arn, granttypes, mode='grant', dry_run=True, clea
|
|||
statement['Principal']['AWS'] = valid_entries
|
||||
had_invalid_entries = True
|
||||
|
||||
if not role_arn in statement['Principal']['AWS']: # needs to be added.
|
||||
if not role_arn in statement['Principal']['AWS']: # needs to be added.
|
||||
changes_needed[granttype] = 'add'
|
||||
statement['Principal']['AWS'].append(role_arn)
|
||||
elif role_arn in statement['Principal']['AWS']: # not one the places the role should be
|
||||
elif role_arn in statement['Principal']['AWS']: # not one the places the role should be
|
||||
changes_needed[granttype] = 'remove'
|
||||
statement['Principal']['AWS'].remove(role_arn)
|
||||
|
||||
|
@ -210,6 +213,7 @@ def do_grant(kms, keyarn, role_arn, granttypes, mode='grant', dry_run=True, clea
|
|||
|
||||
return ret
|
||||
|
||||
|
||||
def assert_policy_shape(policy):
|
||||
'''Since the policy seems a little, uh, fragile, make sure we know approximately what we're looking at.'''
|
||||
errors = []
|
||||
|
@ -218,7 +222,7 @@ def assert_policy_shape(policy):
|
|||
|
||||
found_statement_type = {}
|
||||
for statement in policy['Statement']:
|
||||
for label,sidlabel in statement_label.items():
|
||||
for label, sidlabel in statement_label.items():
|
||||
if statement['Sid'] == sidlabel:
|
||||
found_statement_type[label] = True
|
||||
|
||||
|
@ -230,16 +234,17 @@ def assert_policy_shape(policy):
|
|||
raise Exception('Problems asserting policy shape. Cowardly refusing to modify it: {}'.format(' '.join(errors)))
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = ansible.module_utils.ec2.ec2_argument_spec()
|
||||
argument_spec.update(dict(
|
||||
mode = dict(choices=['grant', 'deny'], default='grant'),
|
||||
key_alias = dict(required=False, type='str'),
|
||||
key_arn = dict(required=False, type='str'),
|
||||
role_name = dict(required=False, type='str'),
|
||||
role_arn = dict(required=False, type='str'),
|
||||
grant_types = dict(required=False, type='list'),
|
||||
clean_invalid_entries = dict(type='bool', default=True),
|
||||
mode=dict(choices=['grant', 'deny'], default='grant'),
|
||||
key_alias=dict(required=False, type='str'),
|
||||
key_arn=dict(required=False, type='str'),
|
||||
role_name=dict(required=False, type='str'),
|
||||
role_arn=dict(required=False, type='str'),
|
||||
grant_types=dict(required=False, type='list'),
|
||||
clean_invalid_entries=dict(type='bool', default=True),
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -255,7 +260,6 @@ def main():
|
|||
result = {}
|
||||
mode = module.params['mode']
|
||||
|
||||
|
||||
try:
|
||||
region, ec2_url, aws_connect_kwargs = ansible.module_utils.ec2.get_aws_connection_info(module, boto3=True)
|
||||
kms = ansible.module_utils.ec2.boto3_conn(module, conn_type='client', resource='kms', region=region, endpoint=ec2_url, **aws_connect_kwargs)
|
||||
|
@ -263,7 +267,6 @@ def main():
|
|||
except botocore.exceptions.NoCredentialsError as e:
|
||||
module.fail_json(msg='cannot connect to AWS', exception=traceback.format_exc())
|
||||
|
||||
|
||||
try:
|
||||
if module.params['key_alias'] and not module.params['key_arn']:
|
||||
module.params['key_arn'] = get_arn_from_kms_alias(kms, module.params['key_alias'])
|
||||
|
@ -282,9 +285,9 @@ def main():
|
|||
module.fail_json(msg='{} is an unknown grant type.'.format(g))
|
||||
|
||||
ret = do_grant(kms, module.params['key_arn'], module.params['role_arn'], module.params['grant_types'],
|
||||
mode=mode,
|
||||
dry_run=module.check_mode,
|
||||
clean_invalid_entries=module.params['clean_invalid_entries'])
|
||||
mode=mode,
|
||||
dry_run=module.check_mode,
|
||||
clean_invalid_entries=module.params['clean_invalid_entries'])
|
||||
result.update(ret)
|
||||
|
||||
except Exception as err:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue