Skip to content

Commit

Permalink
docs: Validate ecosystem keys (#6522)
Browse files Browse the repository at this point in the history
At the moment we have some entries with . chars in their ids, this makes
the hugo page look up break, so now these are validated to be
sausage-case-values.

Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 authored Jan 11, 2024
1 parent 63e1877 commit 35da787
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 5 deletions.
42 changes: 42 additions & 0 deletions build/policy/integrations.rego
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ import future.keywords.in

allowed_image_extensions := ["png", "svg"]

# check that each integration key is valid
deny contains result if {
some path, _ in input.integrations

id := split(path, "/")[2]

not regex.match("^([a-z0-9-]+)$", id)

result := {
"key": "key",
"message": sprintf("integration %s has an invalid key characters, change filename to lowercase and replace spaces with dashes", [id]),
}
}

# check that all integrations have an image
deny contains result if {
some path, integration in input.integrations
Expand Down Expand Up @@ -161,6 +175,34 @@ deny contains result if {
}
}

# check that each organization key is valid
deny contains result if {
some path, _ in input.organizations

id := split(path, "/")[2]

not regex.match("^([a-z0-9-]+)$", id)

result := {
"key": "key",
"message": sprintf("organization %s has an invalid key characters, change filename to lowercase and replace spaces with dashes", [id]),
}
}

# check that each software key is valid
deny contains result if {
some path, _ in input.softwares

id := split(path, "/")[2]

not regex.match("^([a-z0-9-]+)$", id)

result := {
"key": "key",
"message": sprintf("software %s has an invalid key characters, change filename to lowercase and replace spaces with dashes", [id]),
}
}

# check that each software has at least one integration
deny contains result if {
some path, software in input.softwares
Expand Down
42 changes: 42 additions & 0 deletions build/policy/integrations_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ print_if(false, key, expected, output) := false {
print("Got:", messages_for_key(key, output))
}

test_integration_has_valid_key {
output := data.integrations.deny with input as {"integrations": {"/integrations/in.valid/": {"link": "https://example.com/", "title": "Example"}}}

key := "key"

got := messages_for_key(key, output)

message := "integration in.valid has an invalid key characters, change filename to lowercase and replace spaces with dashes"

result := message in got

print_if(result, key, message, output)
}

test_integration_has_required_fields_missing {
output := data.integrations.deny with input as {"integrations": {"/integrations/regal/": {}}}

Expand Down Expand Up @@ -274,6 +288,20 @@ test_organization_has_required_fields_present {
print_if(result, key, false, output)
}

test_organization_has_valid_key {
output := data.integrations.deny with input as {"organizations": {"/organizations/sty.ra/": {"link": "https://styra.com/", "title": "Styra"}}}

key := "key"

got := messages_for_key(key, output)

message := "organization sty.ra has an invalid key characters, change filename to lowercase and replace spaces with dashes"

result := message in got

print_if(result, key, message, output)
}

test_organization_has_one_or_more_integrations_none {
output := data.integrations.deny with input as {"organizations": {"/organizations/foobar/": {}}, "integrations": {}}

Expand Down Expand Up @@ -332,3 +360,17 @@ test_software_has_one_or_more_integrations_one {

print_if(result, key, false, output)
}

test_software_has_valid_key {
output := data.integrations.deny with input as {"softwares": {"/softwares/in.valid/": {"link": "https://example.com/", "title": "Example"}}}

key := "key"

got := messages_for_key(key, output)

message := "software in.valid has an invalid key characters, change filename to lowercase and replace spaces with dashes"

result := message in got

print_if(result, key, message, output)
}
2 changes: 1 addition & 1 deletion docs/website/content/integrations/asp-dotnet-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ labels:
code:
- https://github.com/build-security/OPA-AspDotNetCore-Middleware
inventors:
- build.security
- build-security
---
Use ASP.NET Core to create web apps and services that are fast, secure, cross-platform, and cloud-based.
OPA can be used to implement authorization policies for APIs used in the ASP.NET Core framework.
Expand Down
3 changes: 1 addition & 2 deletions docs/website/content/integrations/nodejs-express.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ labels:
code:
- https://github.com/build-security/opa-express-middleware
inventors:
- build.security
- build-security
software:
- nodejsexpress
docs_features:
Expand All @@ -19,4 +19,3 @@ docs_features:
---
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
OPA can be used to implement authorization policies for APIs used in the express framework.

2 changes: 1 addition & 1 deletion docs/website/content/integrations/php-authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ code:
- https://github.com/segrax/openpolicyagent
- https://github.com/build-security/opa-symfony-middleware
inventors:
- build.security
- build-security
docs_features:
rest-api-integration:
note: |
Expand Down
2 changes: 1 addition & 1 deletion docs/website/content/integrations/springsecurity-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tutorials:
- https://www.baeldung.com/spring-security-authorization-opa
inventors:
- styra
- build.security
- build-security
- bisnode
- alertavert
docs_features:
Expand Down

0 comments on commit 35da787

Please sign in to comment.