Skip to content

Commit

Permalink
Fix resolve on booleans (#89)
Browse files Browse the repository at this point in the history
* Add Id field to Policy Document model to allow for supporting AWS KMS Keys

* Add update to CLOUDFORMATION_ACTIONS to CHANGELOG

* add case for booleans on resolve

* update actions

* update changelog

* update changelog and setup.py

Co-authored-by: Oliver Crawford <[email protected]>
  • Loading branch information
oscarbc96 and Oliver Crawford authored Feb 18, 2022
1 parent 429869c commit f9179f6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change Log
All notable changes to this project will be documented in this file.

## 0.16.2 - [2022-02-16]
### Fixes
- `resolve` was converting to string booleans, this is incompatible since 0.14.0 because bool were converted to StrictBooleans.

### Updates
- Update `CLOUDFORMATION_ACTIONS`.

## 0.16.1 - [2022-02-16]
### Fixes
- AWS KMS Key policies can contain an `Id` field in a `PolicyDocument`. The model for `PolicyDocument` has been updated accordingly to support this.
Expand Down
31 changes: 31 additions & 0 deletions pycfmodel/cloudformation_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2560,10 +2560,12 @@
"connect:SearchVocabularies",
"connect:StartChatContact",
"connect:StartContactRecording",
"connect:StartContactStreaming",
"connect:StartOutboundVoiceContact",
"connect:StartTaskContact",
"connect:StopContact",
"connect:StopContactRecording",
"connect:StopContactStreaming",
"connect:SuspendContactRecording",
"connect:TagResource",
"connect:UntagResource",
Expand Down Expand Up @@ -4546,10 +4548,13 @@
"evidently:ListFeatures",
"evidently:ListLaunches",
"evidently:ListProjects",
"evidently:ListTagsForResource",
"evidently:StartExperiment",
"evidently:StartLaunch",
"evidently:StopExperiment",
"evidently:StopLaunch",
"evidently:TagResource",
"evidently:UntagResource",
"evidently:UpdateExperiment",
"evidently:UpdateFeature",
"evidently:UpdateLaunch",
Expand Down Expand Up @@ -5112,6 +5117,7 @@
"glue:GetMLTransforms",
"glue:GetMapping",
"glue:GetPartition",
"glue:GetPartitionIndexes",
"glue:GetPartitions",
"glue:GetPlan",
"glue:GetRegistry",
Expand Down Expand Up @@ -5449,6 +5455,7 @@
"honeycode:BatchUpsertTableRows",
"honeycode:CreateTeam",
"honeycode:CreateTenant",
"honeycode:DeleteDomains",
"honeycode:DeregisterGroups",
"honeycode:DescribeTableDataImportJob",
"honeycode:DescribeTeam",
Expand All @@ -5459,6 +5466,7 @@
"honeycode:ListTableColumns",
"honeycode:ListTableRows",
"honeycode:ListTables",
"honeycode:ListTagsForResource",
"honeycode:ListTeamAssociations",
"honeycode:ListTenants",
"honeycode:QueryTableRows",
Expand All @@ -5467,6 +5475,8 @@
"honeycode:RejectTeamAssociation",
"honeycode:RestartDomainVerification",
"honeycode:StartTableDataImportJob",
"honeycode:TagResource",
"honeycode:UntagResource",
"honeycode:UpdateTeam",
"iam:AddClientIDToOpenIDConnectProvider",
"iam:AddRoleToInstanceProfile",
Expand Down Expand Up @@ -7609,13 +7619,16 @@
"mediastore:StopAccessLogging",
"mediastore:TagResource",
"mediastore:UntagResource",
"mediatailor:ConfigureLogsForPlaybackConfiguration",
"mediatailor:CreateChannel",
"mediatailor:CreatePrefetchSchedule",
"mediatailor:CreateProgram",
"mediatailor:CreateSourceLocation",
"mediatailor:CreateVodSource",
"mediatailor:DeleteChannel",
"mediatailor:DeleteChannelPolicy",
"mediatailor:DeletePlaybackConfiguration",
"mediatailor:DeletePrefetchSchedule",
"mediatailor:DeleteProgram",
"mediatailor:DeleteSourceLocation",
"mediatailor:DeleteVodSource",
Expand All @@ -7626,9 +7639,11 @@
"mediatailor:GetChannelPolicy",
"mediatailor:GetChannelSchedule",
"mediatailor:GetPlaybackConfiguration",
"mediatailor:GetPrefetchSchedule",
"mediatailor:ListAlerts",
"mediatailor:ListChannels",
"mediatailor:ListPlaybackConfigurations",
"mediatailor:ListPrefetchSchedules",
"mediatailor:ListSourceLocations",
"mediatailor:ListTagsForResource",
"mediatailor:ListVodSources",
Expand Down Expand Up @@ -8530,6 +8545,7 @@
"proton:ListServiceTemplates",
"proton:ListServices",
"proton:ListTagsForResource",
"proton:NotifyResourceDeploymentStatusChange",
"proton:RejectEnvironmentAccountConnection",
"proton:TagResource",
"proton:UntagResource",
Expand Down Expand Up @@ -8923,9 +8939,11 @@
"redshift-data:ListStatements",
"redshift-data:ListTables",
"redshift:AcceptReservedNodeExchange",
"redshift:AddPartner",
"redshift:AssociateDataShareConsumer",
"redshift:AuthorizeClusterSecurityGroupIngress",
"redshift:AuthorizeDataShare",
"redshift:AuthorizeEndpointAccess",
"redshift:AuthorizeSnapshotAccess",
"redshift:BatchDeleteClusterSnapshots",
"redshift:BatchModifyClusterSnapshots",
Expand All @@ -8940,6 +8958,7 @@
"redshift:CreateClusterSnapshot",
"redshift:CreateClusterSubnetGroup",
"redshift:CreateClusterUser",
"redshift:CreateEndpointAccess",
"redshift:CreateEventSubscription",
"redshift:CreateHsmClientCertificate",
"redshift:CreateHsmConfiguration",
Expand All @@ -8956,9 +8975,11 @@
"redshift:DeleteClusterSecurityGroup",
"redshift:DeleteClusterSnapshot",
"redshift:DeleteClusterSubnetGroup",
"redshift:DeleteEndpointAccess",
"redshift:DeleteEventSubscription",
"redshift:DeleteHsmClientCertificate",
"redshift:DeleteHsmConfiguration",
"redshift:DeletePartner",
"redshift:DeleteSavedQueries",
"redshift:DeleteScheduledAction",
"redshift:DeleteSnapshotCopyGrant",
Expand All @@ -8980,6 +9001,8 @@
"redshift:DescribeDataSharesForConsumer",
"redshift:DescribeDataSharesForProducer",
"redshift:DescribeDefaultClusterParameters",
"redshift:DescribeEndpointAccess",
"redshift:DescribeEndpointAuthorization",
"redshift:DescribeEventCategories",
"redshift:DescribeEventSubscriptions",
"redshift:DescribeEvents",
Expand All @@ -8988,6 +9011,7 @@
"redshift:DescribeLoggingStatus",
"redshift:DescribeNodeConfigurationOptions",
"redshift:DescribeOrderableClusterOptions",
"redshift:DescribePartners",
"redshift:DescribeQuery",
"redshift:DescribeReservedNodeOfferings",
"redshift:DescribeReservedNodes",
Expand Down Expand Up @@ -9025,6 +9049,7 @@
"redshift:ModifyClusterSnapshot",
"redshift:ModifyClusterSnapshotSchedule",
"redshift:ModifyClusterSubnetGroup",
"redshift:ModifyEndpointAccess",
"redshift:ModifyEventSubscription",
"redshift:ModifySavedQuery",
"redshift:ModifyScheduledAction",
Expand All @@ -9041,8 +9066,10 @@
"redshift:RestoreTableFromClusterSnapshot",
"redshift:ResumeCluster",
"redshift:RevokeClusterSecurityGroupIngress",
"redshift:RevokeEndpointAccess",
"redshift:RevokeSnapshotAccess",
"redshift:RotateEncryptionKey",
"redshift:UpdatePartnerStatus",
"redshift:ViewQueriesFromConsole",
"redshift:ViewQueriesInConsole",
"refactor-spaces:CreateApplication",
Expand Down Expand Up @@ -11855,12 +11882,14 @@
"workspaces:AssociateIpGroups",
"workspaces:AuthorizeIpRules",
"workspaces:CopyWorkspaceImage",
"workspaces:CreateConnectClientAddIn",
"workspaces:CreateConnectionAlias",
"workspaces:CreateIpGroup",
"workspaces:CreateTags",
"workspaces:CreateUpdatedWorkspaceImage",
"workspaces:CreateWorkspaceBundle",
"workspaces:CreateWorkspaces",
"workspaces:DeleteConnectClientAddIn",
"workspaces:DeleteConnectionAlias",
"workspaces:DeleteIpGroup",
"workspaces:DeleteTags",
Expand All @@ -11870,6 +11899,7 @@
"workspaces:DescribeAccount",
"workspaces:DescribeAccountModifications",
"workspaces:DescribeClientProperties",
"workspaces:DescribeConnectClientAddIns",
"workspaces:DescribeConnectionAliasPermissions",
"workspaces:DescribeConnectionAliases",
"workspaces:DescribeIpGroups",
Expand Down Expand Up @@ -11901,6 +11931,7 @@
"workspaces:StartWorkspaces",
"workspaces:StopWorkspaces",
"workspaces:TerminateWorkspaces",
"workspaces:UpdateConnectClientAddIn",
"workspaces:UpdateConnectionAliasPermission",
"workspaces:UpdateRulesOfIpGroup",
"workspaces:UpdateWorkspaceBundle",
Expand Down
5 changes: 4 additions & 1 deletion pycfmodel/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def resolve(function: ValidResolvers, params: Dict, mappings: Dict[str, Dict], c
return resolve_ssm(ssm_parameter_key, params)
return function

if isinstance(function, (int, float, date, bool, IPv4Network, IPv6Network)):
if isinstance(function, bool):
return function

if isinstance(function, (int, float, date, IPv4Network, IPv6Network)):
return str(function)

if isinstance(function, list):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setup(
name="pycfmodel",
version="0.16.1",
version="0.16.2",
description="A python model for CloudFormation scripts",
author="Skyscanner Product Security",
author_email="[email protected]",
Expand Down
26 changes: 26 additions & 0 deletions tests/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

from pycfmodel import parse
from pycfmodel.model.resources.kms_key import KMSKey
from pycfmodel.resolver import resolve


Expand Down Expand Up @@ -188,6 +189,10 @@ def test_not(function, expected_output):
({"Fn::Equals": ["1123456789", 1123456789]}, True),
({"Fn::Equals": ["2019-12-10", date(2019, 12, 10)]}, True),
({"Fn::Equals": ["0.3", 0.3]}, True),
({"Fn::Equals": [True, True]}, True),
({"Fn::Equals": [False, False]}, True),
({"Fn::Equals": [False, True]}, False),
({"Fn::Equals": [True, False]}, False),
],
)
def test_equals(function, expected_output):
Expand Down Expand Up @@ -566,3 +571,24 @@ def test_resolve_ssm():
"Cluster": "UNDEFINED_PARAM_main-k8s-cluster-arn:3",
"ServiceArn": "vpc-123-abc",
}


def test_resolve_booleans():
template = {
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"KMSKey": {
"Type": "AWS::KMS::Key",
"Properties": {
"Enabled": True,
"EnableKeyRotation": True,
"KeyPolicy": {
"Version": "2012-10-17",
"Statement": [],
},
},
}
},
}
model = parse(template).resolve(extra_params={"some-service-arn:1": "vpc-123-abc"})
assert isinstance(model.Resources["KMSKey"], KMSKey)

0 comments on commit f9179f6

Please sign in to comment.