diff --git a/cmd/get/benchmarks.go b/cmd/get/benchmarks.go index 65eb4fa..3bfd3f3 100644 --- a/cmd/get/benchmarks.go +++ b/cmd/get/benchmarks.go @@ -41,7 +41,7 @@ to quickly create a Cobra application.`, } requestPayload := types.GetBenchmarkPayload{ - Cursor: 1, + Cursor: int(utils.ReadIntFlag(cmd, "page_number")), PerPage: int(utils.ReadIntFlag(cmd, "page_size")), OnlyRootBenchmark: utils.ReadBoolFlag(cmd, "show_only_root"), IncludeFindingsSummary: utils.ReadBoolFlag(cmd, "include_findings_summary"), @@ -92,6 +92,13 @@ to quickly create a Cobra application.`, fmt.Print(string(js)) } + fmt.Printf( + "\n\n\n\nNext Page: \n\tcheckctl get benchmarks --page_size %d --page_number %d --output %s\n", + utils.ReadIntFlag(cmd, "page_size"), + utils.ReadIntFlag(cmd, "page_number")+1, + outputFormat, + ) + return nil }, } diff --git a/cmd/get/controls.go b/cmd/get/controls.go index 2cd4baf..2e7392e 100644 --- a/cmd/get/controls.go +++ b/cmd/get/controls.go @@ -40,70 +40,63 @@ to quickly create a Cobra application.`, outputFormat = configuration.OutputFormat } - var cursor = 1 - var controls []types.Control - - for { - - requestPayload := types.RequestPayload{ - Cursor: cursor, - PerPage: int(utils.ReadIntFlag(cmd, "page_size")), - } - - payload, err := json.Marshal(requestPayload) - if err != nil { - return err - } - - request, err := request.GenerateRequest( - configuration.ApiKey, - configuration.ApiEndpoint, - "POST", - "main/compliance/api/v3/controls", - payload, - ) - if err != nil { - return err - } - - response, err := client.Do(request) - if err != nil { - return err - } - defer response.Body.Close() + requestPayload := types.RequestPayload{ + Cursor: int(utils.ReadIntFlag(cmd, "page_number")), + PerPage: int(utils.ReadIntFlag(cmd, "page_size")), + } - body, err := io.ReadAll(response.Body) - if err != nil { - return err - } + payload, err := json.Marshal(requestPayload) + if err != nil { + return err + } - var getControlsResponse types.GetControlsResponse - err = json.Unmarshal(body, &getControlsResponse) - if err != nil { - return err - } + request, err := request.GenerateRequest( + configuration.ApiKey, + configuration.ApiEndpoint, + "POST", + "main/compliance/api/v3/controls", + payload, + ) + if err != nil { + return err + } - if len(getControlsResponse.Items) == 0 { - break - } + response, err := client.Do(request) + if err != nil { + return err + } + defer response.Body.Close() - controls = append(controls, getControlsResponse.Items...) - cursor += 1 + body, err := io.ReadAll(response.Body) + if err != nil { + return err + } + var getControlsResponse types.GetControlsResponse + err = json.Unmarshal(body, &getControlsResponse) + if err != nil { + return err } if outputFormat == "table" { - rows := utils.GenerateControlRows(controls) + rows := utils.GenerateControlRows(getControlsResponse.Items) tables.PrintControlsTable(rows) } else { - js, err := json.MarshalIndent(controls, "", " ") + js, err := json.MarshalIndent(getControlsResponse.Items, "", " ") if err != nil { return err } fmt.Print(string(js)) } + fmt.Printf( + "\n\n\n\nNext Page: \n\tcheckctl get controls --page_size %d --page_number %d --output %s\n", + utils.ReadIntFlag(cmd, "page_size"), + utils.ReadIntFlag(cmd, "page_number")+1, + outputFormat, + ) + return nil }, } diff --git a/cmd/get/get.go b/cmd/get/get.go index 37a4b22..e54d27a 100644 --- a/cmd/get/get.go +++ b/cmd/get/get.go @@ -30,5 +30,6 @@ func init() { GetCmd.AddCommand(benchmarksCmd) GetCmd.PersistentFlags().Int("page_size", 25, "Defines page size of response") + GetCmd.PersistentFlags().Int("page_number", 1, "Defines page number of response") }