Skip to content

Commit

Permalink
🧹use slice filter to list frameworks (#1392)
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp authored Aug 6, 2024
1 parent f1a693a commit 99a4fa1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 3 additions & 4 deletions apps/cnspec/cmd/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"go.mondoo.com/cnspec/v11/policy"
cnspec_upstream "go.mondoo.com/cnspec/v11/upstream"
mondoogql "go.mondoo.com/mondoo-go"
"k8s.io/utils/ptr"
)

const (
Expand Down Expand Up @@ -90,12 +89,12 @@ var frameworkListCmd = &cobra.Command{
return err
}

state := ptr.To(mondoogql.ComplianceFrameworkStateActive)
states := []mondoogql.ComplianceFrameworkState{mondoogql.ComplianceFrameworkStateActive}
if viper.GetBool("all") {
state = nil
states = []mondoogql.ComplianceFrameworkState{}
}

frameworks, err = cnspec_upstream.ListFrameworks(context.Background(), mondooClient, opts.GetParentMrn(), state)
frameworks, err = cnspec_upstream.ListFrameworks(context.Background(), mondooClient, opts.GetParentMrn(), states)
if err != nil {
log.Error().Msgf("failed to list compliance frameworks: %s", err)
os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions upstream/framework.gql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"go.mondoo.com/cnspec/v11/policy"
mondoogql "go.mondoo.com/mondoo-go"
"k8s.io/utils/ptr"

"go.mondoo.com/cnquery/v11/providers-sdk/v1/upstream/gql"
)
Expand All @@ -20,7 +21,7 @@ type UpstreamFramework struct {
State mondoogql.ComplianceFrameworkState
}

func ListFrameworks(ctx context.Context, c *gql.MondooClient, scopeMrn string, state *mondoogql.ComplianceFrameworkState) ([]*UpstreamFramework, error) {
func ListFrameworks(ctx context.Context, c *gql.MondooClient, scopeMrn string, states []mondoogql.ComplianceFrameworkState) ([]*UpstreamFramework, error) {
var q struct {
Frameworks []struct {
Mrn string
Expand All @@ -32,7 +33,7 @@ func ListFrameworks(ctx context.Context, c *gql.MondooClient, scopeMrn string, s
err := c.Query(ctx, &q, map[string]any{
"input": mondoogql.ComplianceFrameworksInput{
ScopeMrn: mondoogql.String(scopeMrn),
State: state,
States: ptr.To(states),
},
})
if err != nil {
Expand Down

0 comments on commit 99a4fa1

Please sign in to comment.