|
|
@ -327,7 +327,6 @@ def camel_dict_to_snake_dict(camel_dict):
|
|
|
|
|
|
|
|
|
|
|
|
return all_cap_re.sub(r'\1_\2', s1).lower()
|
|
|
|
return all_cap_re.sub(r'\1_\2', s1).lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def value_is_list(camel_list):
|
|
|
|
def value_is_list(camel_list):
|
|
|
|
|
|
|
|
|
|
|
|
checked_list = []
|
|
|
|
checked_list = []
|
|
|
@ -341,7 +340,6 @@ def camel_dict_to_snake_dict(camel_dict):
|
|
|
|
|
|
|
|
|
|
|
|
return checked_list
|
|
|
|
return checked_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snake_dict = {}
|
|
|
|
snake_dict = {}
|
|
|
|
for k, v in camel_dict.items():
|
|
|
|
for k, v in camel_dict.items():
|
|
|
|
if isinstance(v, dict):
|
|
|
|
if isinstance(v, dict):
|
|
|
@ -464,7 +462,6 @@ def get_ec2_security_group_ids_from_names(sec_group_list, ec2_connection, vpc_id
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return sg.name
|
|
|
|
return sg.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_sg_id(sg, boto3):
|
|
|
|
def get_sg_id(sg, boto3):
|
|
|
|
|
|
|
|
|
|
|
|
if boto3:
|
|
|
|
if boto3:
|
|
|
@ -472,7 +469,6 @@ def get_ec2_security_group_ids_from_names(sec_group_list, ec2_connection, vpc_id
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return sg.id
|
|
|
|
return sg.id
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sec_group_id_list = []
|
|
|
|
sec_group_id_list = []
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(sec_group_list, string_types):
|
|
|
|
if isinstance(sec_group_list, string_types):
|
|
|
@ -514,3 +510,46 @@ def get_ec2_security_group_ids_from_names(sec_group_list, ec2_connection, vpc_id
|
|
|
|
|
|
|
|
|
|
|
|
return sec_group_id_list
|
|
|
|
return sec_group_id_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sort_json_policy_dict(policy_dict):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" Sort any lists in an IAM JSON policy so that comparison of two policies with identical values but
|
|
|
|
|
|
|
|
different orders will return true
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
policy_dict (dict): Dict representing IAM JSON policy.
|
|
|
|
|
|
|
|
Basic Usage:
|
|
|
|
|
|
|
|
>>> my_iam_policy = {'Principle': {'AWS':["31","7","14","101"]}
|
|
|
|
|
|
|
|
>>> sort_json_policy_dict(my_iam_policy)
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
Dict: Will return a copy of the policy as a Dict but any List will be sorted
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
'Principle': {
|
|
|
|
|
|
|
|
'AWS': [ '7', '14', '31', '101' ]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def value_is_list(my_list):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checked_list = []
|
|
|
|
|
|
|
|
for item in my_list:
|
|
|
|
|
|
|
|
if isinstance(item, dict):
|
|
|
|
|
|
|
|
checked_list.append(sort_json_policy_dict(item))
|
|
|
|
|
|
|
|
elif isinstance(item, list):
|
|
|
|
|
|
|
|
checked_list.append(value_is_list(item))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
checked_list.append(item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checked_list.sort()
|
|
|
|
|
|
|
|
return checked_list
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ordered_policy_dict = {}
|
|
|
|
|
|
|
|
for key, value in policy_dict.items():
|
|
|
|
|
|
|
|
if isinstance(value, dict):
|
|
|
|
|
|
|
|
ordered_policy_dict[key] = sort_json_policy_dict(value)
|
|
|
|
|
|
|
|
elif isinstance(value, list):
|
|
|
|
|
|
|
|
ordered_policy_dict[key] = value_is_list(value)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
ordered_policy_dict[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ordered_policy_dict
|
|
|
|