Skip to content

Commit

Permalink
Use jsonpatch to fixup spec files before generating code
Browse files Browse the repository at this point in the history
  • Loading branch information
markpeek committed Jul 24, 2021
1 parent 8735a84 commit 2a02203
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
cfn_flip>=1.0.2
awacs>=2.0.0

# ---- Use jsonpatch to fixup spec files
jsonpatch

# ---- Documentation Libraries
Sphinx>=1.8
sphinx_rtd_theme>=0.4.2
Expand Down
9 changes: 9 additions & 0 deletions scripts/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

import argparse
import json
import os
import sys

import jsonpatch
import yaml

# Python code generator to create new troposphere classes from the
Expand Down Expand Up @@ -516,6 +518,13 @@ def process_file(filename, stub=False):
f = open(args.filename[0])
j = json.load(f)

# Apply json patches
patch_dir = "scripts/patches"
for patch_file in os.listdir(patch_dir):
if patch_file.endswith(".json"):
patch = json.loads(open(os.path.join(patch_dir, patch_file)).read())
j = jsonpatch.apply_patch(j, patch)

spec_version = j["ResourceSpecificationVersion"]

r = Resources()
Expand Down
1 change: 1 addition & 0 deletions scripts/patches/DataBrew.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"op": "add", "path": "/PropertyTypes/AWS::DataBrew::Recipe.Action/Properties/Parameters/Type", "value": "RecipeParameters"}]
4 changes: 4 additions & 0 deletions scripts/patches/IoTSiteWise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{"op": "move", "from": "/PropertyTypes/AWS::IoTSiteWise::AccessPolicy.Portal", "path": "/PropertyTypes/AWS::IoTSiteWise::AccessPolicy.PortalProperty"},
{"op": "replace", "path": "/PropertyTypes/AWS::IoTSiteWise::AccessPolicy.AccessPolicyResource/Properties/Portal/Type", "value": "PortalProperty"}
]
6 changes: 6 additions & 0 deletions scripts/patches/NetworkFirewall.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{"op": "move", "from": "/PropertyTypes/AWS::NetworkFirewall::RuleGroup.RuleGroup", "path": "/PropertyTypes/AWS::NetworkFirewall::RuleGroup.RuleGroupProperty"},
{"op": "replace", "path": "/ResourceTypes/AWS::NetworkFirewall::RuleGroup/Properties/RuleGroup/Type", "value": "RuleGroupProperty"},
{"op": "move", "from": "/PropertyTypes/AWS::NetworkFirewall::FirewallPolicy.FirewallPolicy", "path": "/PropertyTypes/AWS::NetworkFirewall::FirewallPolicy.FirewallPolicyProperty"},
{"op": "replace", "path": "/ResourceTypes/AWS::NetworkFirewall::FirewallPolicy/Properties/FirewallPolicy/Type", "value": "FirewallPolicyProperty"}
]

0 comments on commit 2a02203

Please sign in to comment.