Skip to content

Commit

Permalink
Merge pull request #5 from ADorigi/fix/update-get-benchmarks
Browse files Browse the repository at this point in the history
fix: updated get benchmarks response structure
fix: added new flags for get benchmarks
  • Loading branch information
ADorigi authored Sep 16, 2024
2 parents 8e35162 + b1cdce0 commit 44e4b69
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
22 changes: 15 additions & 7 deletions cmd/get/benchmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ to quickly create a Cobra application.`,
outputFormat = configuration.OutputFormat
}

requestPayload := types.RequestPayload{
Cursor: 1,
PerPage: int(utils.ReadIntFlag(cmd, "page-size")),
requestPayload := types.GetBenchmarkPayload{
Cursor: 1,
PerPage: int(utils.ReadIntFlag(cmd, "page_size")),
OnlyRootBenchmark: utils.ReadBoolFlag(cmd, "show_only_root"),
IncludeFindingsSummary: utils.ReadBoolFlag(cmd, "include_findings_summary"),
}

payload, err := json.Marshal(requestPayload)
Expand Down Expand Up @@ -72,18 +74,18 @@ to quickly create a Cobra application.`,
return err
}

var benchmarks []types.BenchMark
err = json.Unmarshal(body, &benchmarks)
var getBenchmarksResponse types.GetBenchmarksResponse
err = json.Unmarshal(body, &getBenchmarksResponse)
if err != nil {
return err
}

if outputFormat == "table" {
rows := utils.GenerateBenchmarkRows(benchmarks)
rows := utils.GenerateBenchmarkRows(getBenchmarksResponse.Items)

tables.PrintBenchmarksTable(rows)
} else {
js, err := json.MarshalIndent(benchmarks, "", " ")
js, err := json.MarshalIndent(getBenchmarksResponse.Items, "", " ")
if err != nil {
return err
}
Expand All @@ -93,3 +95,9 @@ to quickly create a Cobra application.`,
return nil
},
}

func init() {
benchmarksCmd.Flags().Bool("show_only_root", true, "Show only root benchmarks(default: true)")
benchmarksCmd.Flags().Bool("include_findings_summary", false, "Include findings summary in response(default: false)")

}
2 changes: 1 addition & 1 deletion cmd/get/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ to quickly create a Cobra application.`,

requestPayload := types.RequestPayload{
Cursor: cursor,
PerPage: int(utils.ReadIntFlag(cmd, "page-size")),
PerPage: int(utils.ReadIntFlag(cmd, "page_size")),
}

payload, err := json.Marshal(requestPayload)
Expand Down
4 changes: 2 additions & 2 deletions cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Usage: opengovernance get controls|benchmarks --page-size")
fmt.Println("Usage: opengovernance get controls|benchmarks --page_size")
},
}

Expand All @@ -29,6 +29,6 @@ func init() {
GetCmd.AddCommand(controlsCmd)
GetCmd.AddCommand(benchmarksCmd)

GetCmd.PersistentFlags().Int("page-size", 25, "Defines page size of response")
GetCmd.PersistentFlags().Int("page_size", 25, "Defines page size of response")

}
34 changes: 23 additions & 11 deletions pkg/types/benchmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,32 @@ package types
import "time"

type Metadata struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Connectors []string `json:"connectors"`
NumberOfControls int `json:"number_of_controls"`
Enabled bool `json:"enabled"`
TrackDriftEvents bool `json:"track_drift_events"`
PrimaryTables []string `json:"primary_tables"`
Tags map[string]string `json:"tags"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
Connectors []string `json:"connectors"`
NumberOfControls int `json:"number_of_controls"`
Enabled bool `json:"enabled"`
TrackDriftEvents bool `json:"track_drift_events"`
PrimaryTables []string `json:"primary_tables"`
Tags map[string][]string `json:"tags"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

type BenchMark struct {
Metadata Metadata `json:"metadata"`
Findings interface{} `json:"findings"` // need to update with actual type
}

type GetBenchmarksResponse struct {
Items []BenchMark `json:"items"`
TotalCount int64 `json:"total_count"`
}

type GetBenchmarkPayload struct {
Cursor int `json:"cursor"`
PerPage int `json:"per_page"`
OnlyRootBenchmark bool `json:"root"`
IncludeFindingsSummary bool `json:"finding_summary"`
}

0 comments on commit 44e4b69

Please sign in to comment.