Skip to content

Commit

Permalink
fix(dev): get-resources handle schema error
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtkeller committed Nov 1, 2024
1 parent a8baa46 commit 9dd7bec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
10 changes: 8 additions & 2 deletions src/cmd/dev/get-resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ var getResourcesCmd = &cobra.Command{

collection, err := DevGetResources(ctx, validationBytes, spinner)

writeResources(collection, getResourcesOpts.OutputFile)
// do not perform the write if there is nothing to write (likely error)
if collection != nil {
writeResources(collection, getResourcesOpts.OutputFile)
}

if err != nil {
message.Fatalf(err, "error running dev get-resources: %v", err)
Expand Down Expand Up @@ -81,7 +84,10 @@ func DevGetResources(ctx context.Context, validationBytes []byte, spinner *messa
types.GetResourcesOnly(true),
)
if err != nil {
return *lulaValidation.DomainResources, err
if lulaValidation.DomainResources != nil {
return *lulaValidation.DomainResources, err
}
return nil, err
}

return *lulaValidation.DomainResources, nil
Expand Down
7 changes: 0 additions & 7 deletions test.json

This file was deleted.

47 changes: 22 additions & 25 deletions validation.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
metadata:
name: Validate pods with label foo=bar
uuid: 1234
domain:
type: file
file-spec:
filepaths:
- Name: config
path: config.json
type: kubernetes
kubernetes-spec:
resources:
- name: podsvt
resource-rule:
name: demo-pod
version: v1
resource: pods
namespaces: [validation-test]
- name: notFound
resource-rule:
version: v1
resource: notaresource
namespaces: [validation-test]
provider:
type: opa
opa-spec:
rego: |
package validate
import rego.v1
# Default values
default validate := false
default msg := "Not evaluated"
validate if {
check_server_protocol.result
import future.keywords.every
default msg = "test 2"
validate {
podLabel := input.podsvt.metadata.labels.foo
podLabel == "bar"
}
msg = check_server_protocol.msg
config := input["config"]
protocol := config.server.protocol
check_server_protocol = {"result": true, "msg": msg} if {
protocol == "https"
msg := "Server protocol is set to https"
} else = {"result": false, "msg": msg} if {
protocol == "http"
msg := "Server Protocol must be https - http is disallowed"
}
output:
validation: validate.validate
observations:
Expand Down

0 comments on commit 9dd7bec

Please sign in to comment.