def _create_params(params, **kwargs): attributes = [ "AccessPolicies", "AdvancedOptions", "CognitoOptions", "DomainName", "EBSOptions", "ElasticsearchClusterConfig", "ElasticsearchVersion", "EncryptionAtRestOptions", "LogPublishingOptions", "NodeToNodeEncryptionOptions", "SnapshotOptions", "VPCOptions", ] result = select_attributes(params, attributes) result = remove_none_values(result) cluster_config = result.get("ElasticsearchClusterConfig") if isinstance(cluster_config, dict): # set defaults required for boto3 calls cluster_config.setdefault("DedicatedMasterType", "m3.medium.elasticsearch") cluster_config.setdefault("WarmType", "ultrawarm1.medium.elasticsearch") return result
def _create(resource_id, resources, resource_type, func, stack_name, *args, **kwargs): iam = aws_stack.connect_to_service('iam') props = resources[resource_id]['Properties'] cls.resolve_refs_recursively(stack_name, props, resources) policy_doc = json.dumps(remove_none_values(props['PolicyDocument'])) policy_name = props['PolicyName'] for role in props.get('Roles', []): iam.put_role_policy(RoleName=role, PolicyName=policy_name, PolicyDocument=policy_doc) for user in props.get('Users', []): iam.put_user_policy(UserName=user, PolicyName=policy_name, PolicyDocument=policy_doc) for group in props.get('Groups', []): iam.put_group_policy(GroupName=group, PolicyName=policy_name, PolicyDocument=policy_doc) return {}
def test_remove_none_values(): template = { "Properties": { "prop1": 123, "nested": { "test1": PLACEHOLDER_AWS_NO_VALUE, "test2": None }, "list": [1, 2, PLACEHOLDER_AWS_NO_VALUE, 3, None], } } result = remove_none_values(template) assert result == { "Properties": { "prop1": 123, "nested": {}, "list": [1, 2, 3] } }
def _create_params(params, **kwargs): # Tags handled outside of creation attributes = [ attribute for attribute in CreateDomainRequest.__annotations__.keys() if "Tag" not in attribute ] result = select_attributes(params, attributes) result = remove_none_values(result) cluster_config = result.get("ClusterConfig") if isinstance(cluster_config, dict): # set defaults required for boto3 calls cluster_config.setdefault( "DedicatedMasterType", OpenSearchPartitionInstanceType.m3_medium_search) cluster_config.setdefault( "WarmType", OpenSearchWarmPartitionInstanceType. ultrawarm1_medium_search) return result