Skip to content

Commit

Permalink
refactor(pkg/iac): Bring back some trivy-iac pkgs (#1499)
Browse files Browse the repository at this point in the history
* refactor(pkg/iac): Bring back some trivy-iac pkgs

* fix imports

---------

Co-authored-by: Nikita Pivkin <[email protected]>
  • Loading branch information
simar7 and nikpivkin authored Nov 21, 2023
1 parent 6818261 commit 9b3cc25
Show file tree
Hide file tree
Showing 34 changed files with 10,906 additions and 73 deletions.
78 changes: 78 additions & 0 deletions cmd/schema/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package main

import (
"encoding/json"
"fmt"
"os"

"github.com/aquasecurity/defsec/pkg/rego/schemas"
"github.com/spf13/cobra"
)

// generate a json schema document for cloud rego input (state.State)

const schemaPath = "pkg/rego/schemas/cloud.json"

func main() {
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

var rootCmd = &cobra.Command{
Use: "schema",
}

func init() {
rootCmd.AddCommand(generateCmd)
rootCmd.AddCommand(verifyCmd)
}

var generateCmd = &cobra.Command{
Use: "generate",
Short: "generate a json schema document for cloud rego input (state.State)",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceErrors = true
cmd.SilenceUsage = true
schema, err := schemas.Build()
if err != nil {
return err
}
data, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return err
}
if err := os.WriteFile(schemaPath, data, 0600); err != nil {
return err
}
fmt.Println("done")
return nil
},
}

var verifyCmd = &cobra.Command{
Use: "verify",
Short: "verify that the schema is up to date",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceErrors = true
cmd.SilenceUsage = true
schema, err := schemas.Build()
if err != nil {
return err
}
data, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return err
}
existing, err := os.ReadFile(schemaPath)
if err != nil {
return err
}
if string(data) != string(existing) {
return fmt.Errorf("schema is out of date:\n\nplease run 'make schema' and commit the changes")
}
fmt.Println("schema is valid")
return nil
},
}
66 changes: 48 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,81 @@ go 1.20

require (
github.com/alecthomas/chroma v0.10.0
github.com/aquasecurity/trivy-policies v0.6.1-0.20231120231532-f6f2330bf842
github.com/google/uuid v1.3.1
github.com/hashicorp/hcl/v2 v2.17.0
github.com/hashicorp/hcl/v2 v2.18.1
github.com/liamg/iamgo v0.0.9
github.com/liamg/memoryfs v1.6.0
github.com/owenrumney/squealer v1.1.1
github.com/mitchellh/mapstructure v1.5.0
github.com/open-policy-agent/opa v0.58.0
github.com/owenrumney/squealer v1.2.1
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
github.com/zclconf/go-cty v1.13.0
golang.org/x/text v0.13.0

gopkg.in/yaml.v3 v3.0.1
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.0 // indirect
github.com/go-git/go-git/v5 v5.5.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.4.1 // indirect
github.com/go-git/go-git/v5 v5.8.1 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/liamg/jfather v0.0.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/pjbgf/sha1cd v0.2.3 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.11.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.2.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.8.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 9b3cc25

Please sign in to comment.