-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(pkg/iac): Bring back some trivy-iac pkgs (#1499)
* refactor(pkg/iac): Bring back some trivy-iac pkgs * fix imports --------- Co-authored-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
34 changed files
with
10,906 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.