Skip to content

Commit

Permalink
POL-1378 Linting Updates: Automation Policies (#2729)
Browse files Browse the repository at this point in the history
* update

* fix

* update

* fix

* update

* fix

* update

* update

* update

* update

* update

* update

* update
  • Loading branch information
XOmniverse authored Oct 14, 2024
1 parent f0b2822 commit 8b02b24
Show file tree
Hide file tree
Showing 24 changed files with 114 additions and 38 deletions.
35 changes: 29 additions & 6 deletions .dangerfile/policy_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,29 @@ def policy_sections_out_of_order?(file, file_lines)
policy_fail = false
escalations_fail = false

# Record whether certain policy blocks exist at all
metadata_exists = false
parameters_exists = false
credentials_exists = false
pagination_exists = false
datasources_exists = false
policy_exists = false
escalations_exists = false
cwf_exists = false

file_lines.each_with_index do |line, index|
metadata_exists = true if line.start_with?('name ')
parameters_exists = true if line.strip.start_with?('parameter ') && line.strip.end_with?('do')
credentials_exists = true if line.strip.start_with?('credentials ') && line.strip.end_with?('do')
pagination_exists = true if line.strip.start_with?('pagination ') && line.strip.end_with?('do')
datasources_exists = true if line.strip.start_with?('datasource ') && line.strip.end_with?('do')
policy_exists = true if line.strip.start_with?('policy ') && line.strip.end_with?('do')
escalations_exists = true if line.strip.start_with?('escalation ') && line.strip.end_with?('do')
cwf_exists = true if line.strip.start_with?('define ') && line.strip.end_with?('do')

break if line.strip.start_with?('# Meta Policy [alpha]')
end

# Failsafe for meta policy code which won't be in the correct order by design
found_meta = false

Expand All @@ -637,32 +660,32 @@ def policy_sections_out_of_order?(file, file_lines)
found_escalations = true if line.strip.start_with?('escalation ') && line.strip.end_with?('do')
found_cwf = true if line.strip.start_with?('define ') && line.strip.end_with?('do')

if !metadata_fail && !found_metadata && (found_parameters || found_credentials || found_pagination || found_datasources || found_policy || found_escalations || found_cwf)
if metadata_exists && !metadata_fail && !found_metadata && (found_parameters || found_credentials || found_pagination || found_datasources || found_policy || found_escalations || found_cwf)
fail_message += "Line #{line_number.to_s}: Invalid blocks found before metadata\n\n"
metadata_fail = true
end

if !parameters_fail && !found_parameters && (found_credentials || found_pagination || found_datasources || found_policy || found_escalations || found_cwf)
if parameters_exists && !parameters_fail && !found_parameters && (found_credentials || found_pagination || found_datasources || found_policy || found_escalations || found_cwf)
fail_message += "Line #{line_number.to_s}: Invalid blocks found before parameter\n\n"
parameters_fail = true
end

if !credentials_fail && !found_credentials && (found_pagination || found_datasources || found_policy || found_escalations || found_cwf)
if credentials_exists && !credentials_fail && !found_credentials && (found_pagination || found_datasources || found_policy || found_escalations || found_cwf)
fail_message += "Line #{line_number.to_s}: Invalid blocks found before credentials\n\n"
credentials_fail = true
end

if !datasources_fail && !found_datasources && (found_policy || found_escalations || found_cwf)
if datasources_exists && !datasources_fail && !found_datasources && (found_policy || found_escalations || found_cwf)
fail_message += "Line #{line_number.to_s}: Invalid blocks found before datasources\n\n"
datasources_fail = true
end

if !policy_fail && !found_policy && (found_escalations || found_cwf)
if policy_exists && !policy_fail && !found_policy && (found_escalations || found_cwf)
fail_message += "Line #{line_number.to_s}: Invalid blocks found before policy block\n\n"
policy_fail = true
end

if !escalations_fail && !found_escalations && (found_cwf)
if escalations_exists && !escalations_fail && !found_escalations && (found_cwf)
fail_message += "Line #{line_number.to_s}: Invalid blocks found before escalations\n\n"
escalations_fail = true
end
Expand Down
31 changes: 30 additions & 1 deletion .spellignore
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,36 @@ ByteCount
PacketCount
balancers
backfill
FNMS
CBI
workspace
workspaces
Workspace
Workspaces
OCID
OAuth
oauth
BYOL
GCP
TLS
SSL
Balancer
balancer
LUN
Unmanaged
unmanaged
Oversized
oversized
AMI
actioning
actioned
VPN
VPNs
Dataset
dataset
Datasets
datasets
failsafe
MSP
msp
onboarding
Expand All @@ -596,5 +626,4 @@ Customizations
customizations
ElastiCache
elasticache
oversized
freeable
4 changes: 4 additions & 0 deletions automation/aws/aws_account_credentials/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.1.1

- Minor code improvements to conform with current standards. Functionality unchanged.

## v0.1.0

- Initial release
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Cost"
severity "low"
default_frequency "daily"
info(
version: "0.1.0",
version: "0.1.1",
provider: "AWS",
service: "IAM",
policy_set: "Authentication",
Expand Down Expand Up @@ -120,7 +120,6 @@ end
datasource "ds_get_caller_identity" do
request do
auth $auth_aws
verb "GET"
host "sts.amazonaws.com"
path "/"
query "Action", "GetCallerIdentity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "AWS",
version: "0.1.0", # 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
version: "0.1.1", # 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: "false",
deprecated: "false"
)
Expand Down
4 changes: 4 additions & 0 deletions automation/aws/aws_missing_regions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.1

- Minor code improvements to conform with current standards. Functionality unchanged.

## v0.2.0

- Fixed issue with meta policy not working due to missing `Account Number` parameter
Expand Down
2 changes: 1 addition & 1 deletion automation/aws/aws_missing_regions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not incur any cloud costs.
This policy template does not incur any cloud costs.
4 changes: 1 addition & 3 deletions automation/aws/aws_missing_regions/aws_missing_regions.pt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ severity "low"
category "Cost"
default_frequency "weekly"
info(
version: "0.2.0",
version: "0.2.1",
provider: "Flexera",
service: "Optima",
policy_set: "Automation",
Expand Down Expand Up @@ -124,7 +124,6 @@ end
datasource "ds_get_caller_identity" do
request do
auth $auth_aws
verb "GET"
host "sts.amazonaws.com"
path "/"
query "Action", "GetCallerIdentity"
Expand Down Expand Up @@ -165,7 +164,6 @@ end
datasource "ds_regions" do
request do
auth $auth_aws
verb "GET"
host "ec2.amazonaws.com"
path "/"
query "Action", "DescribeRegions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category "Meta"
default_frequency "15 minutes"
info(
provider: "AWS",
version: "0.2.0", # 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
version: "0.2.1", # 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: "false",
deprecated: "false"
)
Expand Down
2 changes: 1 addition & 1 deletion automation/aws/aws_rbd_from_tag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not launch any instances, and so does not incur any cloud costs.
This policy template does not incur any cloud costs.
4 changes: 4 additions & 0 deletions automation/azure/azure_missing_subscriptions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.1.1

- Minor code improvements to conform with current standards. Functionality unchanged.

## v0.1

- initial release
2 changes: 1 addition & 1 deletion automation/azure/azure_missing_subscriptions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not incur any cloud costs.
This policy template does not incur any cloud costs.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ severity "low"
category "Cost"
default_frequency "weekly"
info(
version: "0.1",
version: "0.1.1",
provider: "Flexera",
service: "Optima",
policy_set: "Automation",
Expand Down Expand Up @@ -102,9 +102,9 @@ datasource "ds_billing_centers" do
auth $auth_flexera
host rs_optima_host
path join(["/analytics/orgs/", rs_org_id, "/billing_centers"])
query "view", "allocation_table"
header "Api-Version", "1.0"
header "User-Agent", "RS Policies"
query "view", "allocation_table"
ignore_status [403]
end
result do
Expand Down
2 changes: 1 addition & 1 deletion automation/azure/azure_rbd_from_rg_tag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not launch any instances, and so does not incur any cloud costs.
This policy template does not incur any cloud costs.
2 changes: 1 addition & 1 deletion automation/azure/azure_rbd_from_tag/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not launch any instances, and so does not incur any cloud costs.
This policy template does not incur any cloud costs.
4 changes: 4 additions & 0 deletions automation/flexera/delete_all_billing_centers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.1.1

- Minor code improvements to conform with current standards. Functionality unchanged.

## v1.1

- Updated policy metadata to make it more clear what Flexera service the policy is for
Expand Down
10 changes: 9 additions & 1 deletion automation/flexera/delete_all_billing_centers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ This policy deletes all Billing Centers in the Flexera organization it is execut
- If this is the policy's second time executing, but for some reason the policy has failed to self-terminate, no action will be taken.
- If this is the policy's first time executing, all of the Billing Centers in the Flexera organization are deleted.

## Input Parameters

This policy template has no input parameters.

## Policy Actions

- Delete all Billing Centers

## Prerequisites

This Policy Template uses [Credentials](https://docs.flexera.com/flexera/EN/Automation/ManagingCredentialsExternal.htm) for authenticating to datasources -- in order to apply this policy you must have a Credential registered in the system that is compatible with this policy. If there are no Credentials listed when you apply the policy, please contact your Flexera Org Admin and ask them to register a Credential that is compatible with this policy. The information below should be consulted when creating the credential(s).
Expand All @@ -31,4 +39,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not incur any cloud costs.
This policy template does not incur any cloud costs.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ severity "high"
category "Cost"
default_frequency "15 minutes"
info(
version: "1.1",
version: "1.1.1",
provider: "Flexera",
service: "Cloud Cost Optimization",
policy_set: "Automation",
Expand Down Expand Up @@ -78,8 +78,8 @@ datasource "ds_self_terminate" do
iterate $ds_self_terminate_boolean
request do
auth $auth_flexera
host rs_governance_host
verb "DELETE"
host rs_governance_host
path val(iter_item, 'id')
header "Api-Version", "1.0"
end
Expand Down
4 changes: 4 additions & 0 deletions automation/flexera/outdated_applied_policies/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.1

- Minor code improvements to conform with current standards. Functionality unchanged.

## v0.2.0

- Policy template now reports both outdated and deprecated policy templates with a parameter to choose which
Expand Down
2 changes: 1 addition & 1 deletion automation/flexera/outdated_applied_policies/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not incur any cloud costs. Cloud costs may be incurred by the applied policies that this policy reports on and updates. Please consult the README of each policy for more information.
This policy template does not incur any cloud costs. Cloud costs may be incurred by the applied policies that this policy reports on and updates. Please consult the README of each policy for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ severity "low"
category "Operational"
default_frequency "weekly"
info(
version: "0.2.0",
version: "0.2.1",
provider: "Flexera",
service: "Automation",
policy_set: "Automation"
Expand Down Expand Up @@ -149,7 +149,6 @@ end

datasource "ds_catalog_policies" do
request do
verb "GET"
host "raw.githubusercontent.com"
path "/flexera-public/policy_templates/master/data/active_policy_list/active_policy_list.json"
header "User-Agent", "RS Policies"
Expand Down
2 changes: 1 addition & 1 deletion automation/google/google_rbd_from_label/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ The [Provider-Specific Credentials](https://docs.flexera.com/flexera/EN/Automati

## Cost

This Policy Template does not launch any instances, and so does not incur any cloud costs.
This policy template does not incur any cloud costs.
10 changes: 5 additions & 5 deletions data/policy_permissions_list/master_policy_permissions_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"id": "./automation/aws/aws_account_credentials/aws_account_credentials.pt",
"name": "AWS Account Credentials",
"version": "0.1.0",
"version": "0.1.1",
"providers": [
{
"name": "aws",
Expand All @@ -30,7 +30,7 @@
{
"id": "./automation/aws/aws_missing_regions/aws_missing_regions.pt",
"name": "AWS Missing Regions",
"version": "0.2.0",
"version": "0.2.1",
"providers": [
{
"name": "aws",
Expand Down Expand Up @@ -121,7 +121,7 @@
{
"id": "./automation/azure/azure_missing_subscriptions/azure_missing_subscriptions.pt",
"name": "Azure Missing Subscriptions",
"version": "0.1",
"version": "0.1.1",
"providers": [
{
"name": "azure_rm",
Expand Down Expand Up @@ -242,7 +242,7 @@
{
"id": "./automation/flexera/delete_all_billing_centers/delete_all_billing_centers.pt",
"name": "Flexera CCO Delete All Billing Centers",
"version": "1.1",
"version": "1.1.1",
"providers": [
{
"name": "flexera",
Expand All @@ -264,7 +264,7 @@
{
"id": "./automation/flexera/outdated_applied_policies/outdated_applied_policies.pt",
"name": "Flexera Automation Outdated Applied Policies",
"version": "0.2.0",
"version": "0.2.1",
"providers": [
{
"name": "flexera",
Expand Down
Loading

0 comments on commit 8b02b24

Please sign in to comment.