diff --git a/apps/cnspec/cmd/bundle.go b/apps/cnspec/cmd/bundle.go index f80736c84..b56c91fce 100644 --- a/apps/cnspec/cmd/bundle.go +++ b/apps/cnspec/cmd/bundle.go @@ -20,32 +20,32 @@ import ( "go.mondoo.com/cnspec/v9/policy" ) -func init() { - // policy init - policyBundlesCmd.AddCommand(policyInitCmd) - - // validate - policyLintCmd.Flags().StringP("output", "o", "cli", "Set output format: compact, sarif") - policyLintCmd.Flags().String("output-file", "", "Set output file") - policyBundlesCmd.AddCommand(policyLintCmd) - - // fmt - policyFmtCmd.Flags().Bool("sort", false, "sort the bundle.") - policyBundlesCmd.AddCommand(policyFmtCmd) - - // docs - policyDocsCmd.Flags().Bool("no-code", false, "enable/disable code blocks inside of docs") - policyDocsCmd.Flags().Bool("no-ids", false, "enable/disable the printing of ID fields") - policyBundlesCmd.AddCommand(policyDocsCmd) - - // publish - policyPublishCmd.Flags().Bool("no-lint", false, "Disable linting of the bundle before publishing.") - policyPublishCmd.Flags().String("policy-version", "", "Override the version of each policy in the bundle.") - policyBundlesCmd.AddCommand(policyPublishCmd) - - rootCmd.AddCommand(policyBundlesCmd) -} - +// func init() { +// // policy init +// policyBundlesCmd.AddCommand(policyInitCmd) +// +// // validate +// policyLintCmd.Flags().StringP("output", "o", "cli", "Set output format: compact, sarif") +// policyLintCmd.Flags().String("output-file", "", "Set output file") +// policyBundlesCmd.AddCommand(policyLintCmd) +// +// // fmt +// policyFmtCmd.Flags().Bool("sort", false, "sort the bundle.") +// policyBundlesCmd.AddCommand(policyFmtCmd) +// +// // docs +// policyDocsCmd.Flags().Bool("no-code", false, "enable/disable code blocks inside of docs") +// policyDocsCmd.Flags().Bool("no-ids", false, "enable/disable the printing of ID fields") +// policyBundlesCmd.AddCommand(policyDocsCmd) +// +// // publish +// policyPublishCmd.Flags().Bool("no-lint", false, "Disable linting of the bundle before publishing.") +// policyPublishCmd.Flags().String("policy-version", "", "Override the version of each policy in the bundle.") +// policyBundlesCmd.AddCommand(policyPublishCmd) +// +// rootCmd.AddCommand(policyBundlesCmd) +// } +// // ensureProviders ensures that all providers are locally installed func ensureProviders() error { for _, v := range providers.DefaultProviders { diff --git a/apps/cnspec/cmd/policy.go b/apps/cnspec/cmd/policy.go index f42d436ab..87f471c9e 100644 --- a/apps/cnspec/cmd/policy.go +++ b/apps/cnspec/cmd/policy.go @@ -32,6 +32,9 @@ func init() { // policy list policyCmd.AddCommand(policyListCmd) + // policy show + policyCmd.AddCommand(policyShowCmd) + // validate policyLintCmd.Flags().StringP("output", "o", "cli", "Set output format: compact, sarif") policyLintCmd.Flags().String("output-file", "", "Set output file") @@ -54,24 +57,11 @@ func init() { rootCmd.AddCommand(policyCmd) } -// ensureProviders ensures that all providers are locally installed -func ensureProviders() error { - for _, v := range providers.DefaultProviders { - if _, err := providers.EnsureProvider(providers.ProviderLookup{ID: v.ID}, true, nil); err != nil { - return err - } - } - return nil -} - var policyCmd = &cobra.Command{ Use: "policy", Short: "Manage policies.", } -//go:embed policy-example.mql.yaml -var embedPolicyTemplate []byte - var policyListCmd = &cobra.Command{ Use: "list", Short: "list currently active policies in the connected space", @@ -104,6 +94,44 @@ var policyListCmd = &cobra.Command{ }, } +var policyShowCmd = &cobra.Command{ + Use: "show [UID/MRN]", + Short: "show more info about policies, including: summary, docs, etc.", + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + registryEndpoint := os.Getenv("REGISTRY_URL") + if registryEndpoint == "" { + registryEndpoint = defaultRegistryUrl + } + + // Note, this does not use the proxy config override from the mondoo.yml since we only get here when + // it is used without upstream config + client, err := policy.NewPolicyHubClient(registryEndpoint, ranger.DefaultHttpClient()) + if err != nil { + log.Fatal().Err(err) + } + + policyMrn := &policy.Mrn{ + Mrn: args[0], + } + fmt.Println(policyMrn) + policy, err := client.GetPolicy(context.Background(), policyMrn) + if err != nil { + log.Fatal().Err(err) + } + if policy == nil { + fmt.Println("Schade aber auch") + } + fmt.Println(policy) + fmt.Println(policy.Mrn) + fmt.Println("→ Name: ", policy.Name) + fmt.Println("→ Version: ", policy.Version) + fmt.Println("→ UID: ", policy.Uid) + fmt.Println("→ MRN: ", policy.Mrn) + + }, +} + var policyUploadCmd = &cobra.Command{ Use: "upload", Short: "upload a policy to the connected space", @@ -142,7 +170,7 @@ var policyUploadCmd = &cobra.Command{ }, } -var policyInitCmd = &cobra.Command{ +var newPolicyInitCmd = &cobra.Command{ Use: "init [path]", Short: "Create an example policy that you can use as a starting point. If you don't provide a filename, cnspec uses `example-policy.mql.yml`.", Args: cobra.MaximumNArgs(1), @@ -165,7 +193,7 @@ var policyInitCmd = &cobra.Command{ }, } -var policyLintCmd = &cobra.Command{ +var newPolicyLintCmd = &cobra.Command{ Use: "lint [path]", Aliases: []string{"validate"}, Short: "Lint a policy.", @@ -219,7 +247,7 @@ var policyLintCmd = &cobra.Command{ }, } -var policyFmtCmd = &cobra.Command{ +var newPolicyFmtCmd = &cobra.Command{ Use: "format [path]", Aliases: []string{"fmt"}, Short: "Apply style formatting to one or more policy bundles.", @@ -238,7 +266,7 @@ var policyFmtCmd = &cobra.Command{ }, } -var policyPublishCmd = &cobra.Command{ +var newPolicyPublishCmd = &cobra.Command{ Use: "publish [path]", Aliases: []string{"upload"}, Short: "Add a user-owned policy to the Mondoo Security Registry.", @@ -339,7 +367,7 @@ var policyPublishCmd = &cobra.Command{ }, } -var policyDocsCmd = &cobra.Command{ +var newPolicyDocsCmd = &cobra.Command{ Use: "docs [path]", Aliases: []string{}, Short: "Retrieve only the docs for a bundle.",