From fa24c874b58fce4b2f4dab4568bbb83998501ffd Mon Sep 17 00:00:00 2001 From: Takumi Yanagawa Date: Wed, 6 Dec 2023 15:19:24 +0900 Subject: [PATCH] Move oscal2posture to subcommand 'tools' Signed-off-by: Takumi Yanagawa --- README.md | 2 +- cmd/c2pcli/subcommands/kyverno.go | 3 -- cmd/c2pcli/subcommands/ocm.go | 5 ++-- cmd/kyverno/tools/cmd/cmd.go | 3 ++ cmd/ocm/tools/cmd/cmd.go | 50 +++++++++++++++++++++++++++++++ cmd/ocm/tools/options/options.go | 39 ++++++++++++++++++++++++ docs/ocm/README.md | 8 ++--- 7 files changed, 99 insertions(+), 11 deletions(-) create mode 100644 cmd/ocm/tools/cmd/cmd.go create mode 100644 cmd/ocm/tools/options/options.go diff --git a/README.md b/README.md index 2279c27..5cabb44 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ $ tree /tmp/assessment-results #### Reformat in human-friendly format (markdown file) ``` -$ go run cmd/c2pcli/main.go kyverno oscal2posture -c ./pkg/testdata/kyverno/c2p-config.yaml --assessment-results /tmp/assessment-results/assessment-results.json -o /tmp/compliance-report.md +$ go run cmd/c2pcli/main.go kyverno tools oscal2posture -c ./pkg/testdata/kyverno/c2p-config.yaml --assessment-results /tmp/assessment-results/assessment-results.json -o /tmp/compliance-report.md ``` ``` diff --git a/cmd/c2pcli/subcommands/kyverno.go b/cmd/c2pcli/subcommands/kyverno.go index 3b0aa08..4f8761b 100644 --- a/cmd/c2pcli/subcommands/kyverno.go +++ b/cmd/c2pcli/subcommands/kyverno.go @@ -23,8 +23,6 @@ import ( oscal2policycmd "github.com/IBM/compliance-to-policy/cmd/kyverno/oscal2policy/cmd" result2oscalcmd "github.com/IBM/compliance-to-policy/cmd/kyverno/result2oscal/cmd" toolscmd "github.com/IBM/compliance-to-policy/cmd/kyverno/tools/cmd" - oscal2posturecmd "github.com/IBM/compliance-to-policy/cmd/pvpcommon/oscal2posture/cmd" - "github.com/IBM/compliance-to-policy/pkg" ) func NewKyvernoSubCommand() *cobra.Command { @@ -39,7 +37,6 @@ func NewKyvernoSubCommand() *cobra.Command { command.AddCommand(oscal2policycmd.New()) command.AddCommand(result2oscalcmd.New()) - command.AddCommand(oscal2posturecmd.New(pkg.GetLogger("kyverno/oscal2posture"))) command.AddCommand(toolscmd.New()) return command diff --git a/cmd/c2pcli/subcommands/ocm.go b/cmd/c2pcli/subcommands/ocm.go index 9b9659d..d3a7cec 100644 --- a/cmd/c2pcli/subcommands/ocm.go +++ b/cmd/c2pcli/subcommands/ocm.go @@ -22,8 +22,7 @@ import ( "github.com/IBM/compliance-to-policy/cmd/c2pcli/options" oscal2policycmd "github.com/IBM/compliance-to-policy/cmd/ocm/oscal2policy/cmd" result2oscalcmd "github.com/IBM/compliance-to-policy/cmd/ocm/result2oscal/cmd" - oscal2posturecmd "github.com/IBM/compliance-to-policy/cmd/pvpcommon/oscal2posture/cmd" - "github.com/IBM/compliance-to-policy/pkg" + toolscmd "github.com/IBM/compliance-to-policy/cmd/ocm/tools/cmd" ) func NewOcmSubCommand() *cobra.Command { @@ -38,7 +37,7 @@ func NewOcmSubCommand() *cobra.Command { command.AddCommand(oscal2policycmd.New()) command.AddCommand(result2oscalcmd.New()) - command.AddCommand(oscal2posturecmd.New(pkg.GetLogger("ocm/oscal2posture"))) + command.AddCommand(toolscmd.New()) return command } diff --git a/cmd/kyverno/tools/cmd/cmd.go b/cmd/kyverno/tools/cmd/cmd.go index 89adc9d..ab035d4 100644 --- a/cmd/kyverno/tools/cmd/cmd.go +++ b/cmd/kyverno/tools/cmd/cmd.go @@ -21,6 +21,8 @@ import ( "github.com/IBM/compliance-to-policy/cmd/c2pcli/options" kyvernocmd "github.com/IBM/compliance-to-policy/cmd/kyverno/tools/subcommands/kyverno" + oscal2posturecmd "github.com/IBM/compliance-to-policy/cmd/pvpcommon/oscal2posture/cmd" + "github.com/IBM/compliance-to-policy/pkg" ) func New() *cobra.Command { @@ -44,6 +46,7 @@ func New() *cobra.Command { opts.AddFlags(command.Flags()) command.AddCommand(kyvernocmd.New()) + command.AddCommand(oscal2posturecmd.New(pkg.GetLogger("kyverno/oscal2posture"))) return command } diff --git a/cmd/ocm/tools/cmd/cmd.go b/cmd/ocm/tools/cmd/cmd.go new file mode 100644 index 0000000..5b601a5 --- /dev/null +++ b/cmd/ocm/tools/cmd/cmd.go @@ -0,0 +1,50 @@ +/* +Copyright 2023 IBM Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cmd + +import ( + "github.com/spf13/cobra" + + "github.com/IBM/compliance-to-policy/cmd/c2pcli/options" + oscal2posturecmd "github.com/IBM/compliance-to-policy/cmd/pvpcommon/oscal2posture/cmd" + "github.com/IBM/compliance-to-policy/pkg" +) + +func New() *cobra.Command { + opts := options.NewOptions() + + command := &cobra.Command{ + Use: "tools", + Short: "Tools", + RunE: func(cmd *cobra.Command, args []string) error { + if err := opts.Complete(); err != nil { + return err + } + + if err := opts.Validate(); err != nil { + return err + } + return nil + }, + } + + opts.AddFlags(command.Flags()) + + command.AddCommand(oscal2posturecmd.New(pkg.GetLogger("ocm/oscal2posture"))) + + return command +} diff --git a/cmd/ocm/tools/options/options.go b/cmd/ocm/tools/options/options.go new file mode 100644 index 0000000..63ed570 --- /dev/null +++ b/cmd/ocm/tools/options/options.go @@ -0,0 +1,39 @@ +/* +Copyright 2023 IBM Corporation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package options + +import ( + "github.com/spf13/pflag" +) + +type Options struct { +} + +func NewOptions() *Options { + return &Options{} +} + +func (o *Options) AddFlags(fs *pflag.FlagSet) { +} + +func (o *Options) Complete() error { + return nil +} + +func (o *Options) Validate() error { + return nil +} diff --git a/docs/ocm/README.md b/docs/ocm/README.md index a48945e..edfbe7a 100644 --- a/docs/ocm/README.md +++ b/docs/ocm/README.md @@ -9,9 +9,9 @@ Usage: c2pcli ocm [command] Available Commands: - oscal2policy Compose deliverable OCM Policies from OSCAL - oscal2posture Generate Compliance Posture from OSCAL artifacts - result2oscal Generate OSCAL Assessment Results from OCM Policy statuses + oscal2policy Compose deliverable OCM Policies from OSCAL + result2oscal Generate OSCAL Assessment Results from OCM Policy statuses + tools Tools Flags: -h, --help help for ocm @@ -84,7 +84,7 @@ Use "c2pcli ocm [command] --help" for more information about a command. ``` 1. Prettify OSCAL Assessment Results in .md format ``` - c2pcli ocm oscal2posture -c ./docs/ocm/c2p-config.yaml --assessment-results /tmp/assessment-results.json -o /tmp/compliance-posture.md + c2pcli ocm tools oscal2posture -c ./docs/ocm/c2p-config.yaml --assessment-results /tmp/assessment-results.json -o /tmp/compliance-posture.md ``` - You can view the compliance posture like [./final-outputs/compliance-posture.md](./final-outputs/compliance-posture.md)