Skip to content

Commit

Permalink
Move oscal2posture to subcommand 'tools'
Browse files Browse the repository at this point in the history
Signed-off-by: Takumi Yanagawa <yana@jp.ibm.com>
  • Loading branch information
yana1205 committed Dec 7, 2023
1 parent 01d215e commit fa24c87
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

```
Expand Down
3 changes: 0 additions & 3 deletions cmd/c2pcli/subcommands/kyverno.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions cmd/c2pcli/subcommands/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions cmd/kyverno/tools/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
50 changes: 50 additions & 0 deletions cmd/ocm/tools/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -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
}
39 changes: 39 additions & 0 deletions cmd/ocm/tools/options/options.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions docs/ocm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit fa24c87

Please sign in to comment.