Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹use slice filter to list frameworks #1392

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading