diff --git a/src/cmd/dev/get-resources.go b/src/cmd/dev/get-resources.go index 262789d8..ea8f4ccd 100644 --- a/src/cmd/dev/get-resources.go +++ b/src/cmd/dev/get-resources.go @@ -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) @@ -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 diff --git a/test.json b/test.json deleted file mode 100644 index b344a2f2..00000000 --- a/test.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "config": { - "server": { - "protocol": "https" - } - } -} \ No newline at end of file diff --git a/validation.yaml b/validation.yaml index fbc5924a..8fe3d46e 100644 --- a/validation.yaml +++ b/validation.yaml @@ -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: