From 6ffa570555c0bf900619f317d9ff052287eac365 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Wed, 16 Aug 2023 11:35:37 +0100 Subject: [PATCH] opa fmt new policy Signed-off-by: Charlie Egan --- .github/workflows/pull-request.yaml | 2 +- build/policy/integrations.rego | 106 ++++++++++++++-------------- build/policy/integrations_test.rego | 48 ++++--------- 3 files changed, 66 insertions(+), 90 deletions(-) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index c0f48b93af0..c9fff69e1ed 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -325,12 +325,12 @@ jobs: run: opa eval --input files.json --format pretty input if: ${{ failure() }} - - name: Setup Hugo uses: peaceiris/actions-hugo@v2 with: # keep this version in sync with the version in netlify.toml hugo-version: '0.113.0' + extended: true - name: Build docs site and test integrations data run: | diff --git a/build/policy/integrations.rego b/build/policy/integrations.rego index e238dcc0e59..e341db200e0 100644 --- a/build/policy/integrations.rego +++ b/build/policy/integrations.rego @@ -10,7 +10,7 @@ allowed_image_extensions := ["png", "svg"] deny contains result if { some id, integration in input.integrations - # some integrations are allowed to have a missing image as no suitable image is available + # some integrations are allowed to have a missing image as no suitable image is available not integration.allow_missing_image == true some _, ext in allowed_image_extensions @@ -22,7 +22,7 @@ deny contains result if { e := sprintf("%s.%s", [id, ext]) } - possible_filenames - {i| i := input.images[_] } == possible_filenames + possible_filenames - {i | i := input.images[_]} == possible_filenames result := { "key": "integration_image", @@ -46,102 +46,102 @@ deny contains result if { # check that all integrations have the required fields deny contains result if { - some id, integration in input.integrations + some id, integration in input.integrations - missing_fields := {"title", "layout"} - object.keys(integration) + missing_fields := {"title", "layout"} - object.keys(integration) - count(missing_fields) > 0 + count(missing_fields) > 0 - result := { - "key": "fields", - "message": sprintf("integration %s missing required fields: %v", [id, concat(", ", sort(missing_fields))]), - } + result := { + "key": "fields", + "message": sprintf("integration %s missing required fields: %v", [id, concat(", ", sort(missing_fields))]), + } } # check that all integrations have content deny contains result if { - some id, integration in input.integrations + some id, integration in input.integrations - content := trim_space(object.get(integration, "content", "")) + content := trim_space(object.get(integration, "content", "")) - content == "" + content == "" - result := { - "key": "content", - "message": sprintf("integration %s has no content", [id]), - } + result := { + "key": "content", + "message": sprintf("integration %s has no content", [id]), + } } # check that all integrations have a layout set to integration-single deny contains result if { - some id, integration in input.integrations + some id, integration in input.integrations - layout := object.get(integration, "layout", "") + layout := object.get(integration, "layout", "") - layout != "integration-single" + layout != "integration-single" - result := { - "key": "layout", - "message": sprintf("integration %s does not have layout set to: integration-single", [id]), - } + result := { + "key": "layout", + "message": sprintf("integration %s does not have layout set to: integration-single", [id]), + } } # check that all integrations reference an existing organization deny contains result if { - some id, integration in input.integrations + some id, integration in input.integrations - inventors := object.get(integration, "inventors", []) + inventors := object.get(integration, "inventors", []) - some _, inventor in inventors + some _, inventor in inventors - not inventor in object.keys(input.organizations) + not inventor in object.keys(input.organizations) - result := { - "key": "inventors", - "message": sprintf("integration %s references organization %s which does not exist", [id, inventor]), - } + result := { + "key": "inventors", + "message": sprintf("integration %s references organization %s which does not exist", [id, inventor]), + } } # check that all integrations reference existing software deny contains result if { - some id, integration in input.integrations + some id, integration in input.integrations - softwares := object.get(integration, "software", []) + softwares := object.get(integration, "software", []) - some _, software in softwares + some _, software in softwares - not software in object.keys(input.softwares) + not software in object.keys(input.softwares) - result := { - "key": "software", - "message": sprintf("integration %s references software %s which does not exist", [id, software]), - } + result := { + "key": "software", + "message": sprintf("integration %s references software %s which does not exist", [id, software]), + } } # check that softwares have required fields deny contains result if { - some id, software in input.softwares + some id, software in input.softwares - missing_fields := {"title", "layout", "link"} - object.keys(software) + missing_fields := {"title", "layout", "link"} - object.keys(software) - count(missing_fields) > 0 + count(missing_fields) > 0 - result := { - "key": "fields", - "message": sprintf("software %s missing required fields: %v", [id, concat(", ", sort(missing_fields))]), - } + result := { + "key": "fields", + "message": sprintf("software %s missing required fields: %v", [id, concat(", ", sort(missing_fields))]), + } } # check that organizations have required fields deny contains result if { - some id, organization in input.organizations + some id, organization in input.organizations - missing_fields := {"title", "layout", "link"} - object.keys(organization) + missing_fields := {"title", "layout", "link"} - object.keys(organization) - count(missing_fields) > 0 + count(missing_fields) > 0 - result := { - "key": "fields", - "message": sprintf("organization %s missing required fields: %v", [id, concat(", ", sort(missing_fields))]), - } + result := { + "key": "fields", + "message": sprintf("organization %s missing required fields: %v", [id, concat(", ", sort(missing_fields))]), + } } diff --git a/build/policy/integrations_test.rego b/build/policy/integrations_test.rego index ee690a155cf..0d5ff41a495 100644 --- a/build/policy/integrations_test.rego +++ b/build/policy/integrations_test.rego @@ -27,9 +27,7 @@ print_if(false, key, expected, output) := false { } test_integration_has_required_fields_missing { - output := data.integrations.deny with input as { - "integrations": {"regal": {}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {}}} key := "fields" message := "integration regal missing required fields: layout, title" @@ -42,9 +40,7 @@ test_integration_has_required_fields_missing { } test_integration_has_required_fields_present { - output := data.integrations.deny with input as { - "integrations": {"regal": {"title": "Regal", "layout": "integration"}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {"title": "Regal", "layout": "integration"}}} key := "fields" message := "integration regal missing required fields: layout, title" @@ -57,9 +53,7 @@ test_integration_has_required_fields_present { } test_integration_has_layout_missing { - output := data.integrations.deny with input as { - "integrations": {"regal": {}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {}}} key := "layout" message := "integration regal does not have layout set to: integration-single" @@ -72,9 +66,7 @@ test_integration_has_layout_missing { } test_integration_has_layout_missing { - output := data.integrations.deny with input as { - "integrations": {"regal": {"layout": "wrong"}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {"layout": "wrong"}}} key := "layout" message := "integration regal does not have layout set to: integration-single" @@ -87,9 +79,7 @@ test_integration_has_layout_missing { } test_integration_has_layout_present { - output := data.integrations.deny with input as { - "integrations": {"regal": {"layout": "integration-single"}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {"layout": "integration-single"}}} key := "layout" @@ -101,9 +91,7 @@ test_integration_has_layout_present { } test_integration_has_content_missing { - output := data.integrations.deny with input as { - "integrations": {"regal": {}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {}}} key := "content" message := "integration regal has no content" @@ -116,9 +104,7 @@ test_integration_has_content_missing { } test_integration_has_content_blank { - output := data.integrations.deny with input as { - "integrations": {"regal": {"content": "\t\t\n "}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {"content": "\t\t\n "}}} key := "content" message := "integration regal has no content" @@ -131,9 +117,7 @@ test_integration_has_content_blank { } test_integration_has_content_present { - output := data.integrations.deny with input as { - "integrations": {"regal": {"content": "foobar"}}, - } + output := data.integrations.deny with input as {"integrations": {"regal": {"content": "foobar"}}} key := "content" got := messages_for_key(key, output) @@ -279,9 +263,7 @@ test_integration_softwares_present { } test_software_has_required_fields_missing { - output := data.integrations.deny with input as { - "softwares": {"terraform": {}}, - } + output := data.integrations.deny with input as {"softwares": {"terraform": {}}} key := "fields" message := "software terraform missing required fields: layout, link, title" @@ -294,9 +276,7 @@ test_software_has_required_fields_missing { } test_software_has_required_fields_present { - output := data.integrations.deny with input as { - "softwares": {"terraform": {"layout": "software-single", "link": "https://www.terraform.io/", "title": "Terraform"}}, - } + output := data.integrations.deny with input as {"softwares": {"terraform": {"layout": "software-single", "link": "https://www.terraform.io/", "title": "Terraform"}}} key := "fields" @@ -308,9 +288,7 @@ test_software_has_required_fields_present { } test_organization_has_required_labels { - output := data.integrations.deny with input as { - "organizations": {"styra": {}}, - } + output := data.integrations.deny with input as {"organizations": {"styra": {}}} key := "fields" message := "organization styra missing required fields: layout, link, title" @@ -323,9 +301,7 @@ test_organization_has_required_labels { } test_organization_has_required_fields_present { - output := data.integrations.deny with input as { - "organizations": {"styra": {"layout": "organization-single", "link": "https://styra.com/", "title": "Styra"}}, - } + output := data.integrations.deny with input as {"organizations": {"styra": {"layout": "organization-single", "link": "https://styra.com/", "title": "Styra"}}} key := "fields"