Skip to content

Commit

Permalink
FLEX-5397 - Modify Meta Parent Compiler to Conditionally Include `hid…
Browse files Browse the repository at this point in the history
…e_skip_approvals` (#2813)

* removed manual updates from meta parent policies

* updated meta parent compiler & Rakefile

* updated comments

* Update hide_skip_approvals to boolean with false default

* roll back local testing changes
  • Loading branch information
ramyadmz authored Nov 8, 2024
1 parent 82c4ec3 commit 86ff027
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ task :generate_policy_list do
recommendation_type = pp.parsed_info[:recommendation_type]
publish = pp.parsed_info[:publish]
deprecated = pp.parsed_info[:deprecated]
hide_skip_approvals = pp.parsed_info[:hide_skip_approvals]


# 'publish' defaults to true unless explicitly set to false
# 'deprecated' defaults to false unless explicitly set to true
publish = !(publish == 'false' || publish == false)
deprecated = deprecated == 'true' || deprecated == true
# 'hide_skip_approvals' defaults to false unless explicitly set to true
hide_skip_approvals = hide_skip_approvals == 'true' || hide_skip_approvals == true
end

# Get version from long description
Expand Down Expand Up @@ -86,7 +90,8 @@ task :generate_policy_list do
"recommendation_type": recommendation_type,
"updated_at": updated_at,
"generally_recommended": generally_recommended,
"deprecated": deprecated
"deprecated": deprecated,
"hide_skip_approvals": hide_skip_approvals
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ info(
provider: "AWS",
version: "__PLACEHOLDER_FOR_CHILD_POLICY_VERSION__", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "__PLACEHOLDER_FOR_CHILD_POLICY_PUBLISH__",
deprecated: "__PLACEHOLDER_FOR_CHILD_POLICY_DEPRECATED__"
deprecated: "__PLACEHOLDER_FOR_CHILD_POLICY_DEPRECATED__",
hide_skip_approvals: "__PLACEHOLDER_FOR_CHILD_POLICY_HIDE_SKIP_APPROVALS__"
)

##############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ info(
provider: "Azure",
version: "__PLACEHOLDER_FOR_CHILD_POLICY_VERSION__", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "__PLACEHOLDER_FOR_CHILD_POLICY_PUBLISH__",
deprecated: "__PLACEHOLDER_FOR_CHILD_POLICY_DEPRECATED__"
deprecated: "__PLACEHOLDER_FOR_CHILD_POLICY_DEPRECATED__",
hide_skip_approvals: "__PLACEHOLDER_FOR_CHILD_POLICY_HIDE_SKIP_APPROVALS__"
)

##############################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ info(
version: "__PLACEHOLDER_FOR_CHILD_POLICY_VERSION__", # This version of the Meta Parent Policy Template should match the version of the Child Policy Template as it appears in the Catalog for best reliability
publish: "__PLACEHOLDER_FOR_CHILD_POLICY_PUBLISH__",
deprecated: "__PLACEHOLDER_FOR_CHILD_POLICY_DEPRECATED__"
hide_skip_approvals: "__PLACEHOLDER_FOR_CHILD_POLICY_HIDE_SKIP_APPROVALS__"
)

##############################################################################
Expand Down
11 changes: 11 additions & 0 deletions tools/meta_parent_policy_compiler/meta_parent_policy_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def compile_meta_parent_policy(file_path)
deprecated_scan = pt.scan(/deprecated: "(.*?)"/)
deprecated = "false"
deprecated = deprecated_scan[0][0] if !deprecated_scan.empty?
# get the hide_skip_approvals string if it exists, defaulting to false if not present
hide_skip_approvals_scan = pt.scan(/hide_skip_approvals: "(.*?)"/)
hide_skip_approvals = ""
hide_skip_approvals = hide_skip_approvals_scan[0][0] if !hide_skip_approvals_scan.empty?
# print("Name: #{name}\n")
# print("Description: #{description}\n")
# print("\n###########################\n")
Expand Down Expand Up @@ -425,6 +429,13 @@ def compile_meta_parent_policy(file_path)
output_pt = output_pt.gsub("__PLACEHOLDER_FOR_CHILD_POLICY_VERSION__", version)
output_pt = output_pt.gsub("__PLACEHOLDER_FOR_CHILD_POLICY_PUBLISH__", publish)
output_pt = output_pt.gsub("__PLACEHOLDER_FOR_CHILD_POLICY_DEPRECATED__", deprecated)
if !hide_skip_approvals.empty?
output_pt = output_pt.gsub("__PLACEHOLDER_FOR_CHILD_POLICY_HIDE_SKIP_APPROVALS__", hide_skip_approvals)
else
# Remove the entire line containing hide_skip_approvals
output_pt = output_pt.gsub(/^\s*,?\s*hide_skip_approvals: "__PLACEHOLDER_FOR_CHILD_POLICY_HIDE_SKIP_APPROVALS__",?\s*\n/, "")
output_pt = output_pt.gsub(/,\s*\)/, "\n)")
end
# Attempt to identify the URL to the child policy template file on github using the file_path provided
# This would only work if the pt file is located under the `policy_templates` repo directory
# If it is not, then the URL will be incorrect
Expand Down

0 comments on commit 86ff027

Please sign in to comment.