-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ADorigi/fix-run-jobs
Fix run jobs
- Loading branch information
Showing
14 changed files
with
601 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package get | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/adorigi/checkctl/pkg/config" | ||
"github.com/adorigi/checkctl/pkg/request" | ||
"github.com/adorigi/checkctl/pkg/types" | ||
"github.com/adorigi/checkctl/pkg/utils" | ||
"github.com/spf13/cobra" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
// complianceSummaryForBenchmarkCmd represents the benchmarks command | ||
var complianceSummaryForBenchmarkCmd = &cobra.Command{ | ||
Use: "compliance-summary-for-benchmark", | ||
Short: "Get compliance summary for benchmark", | ||
Long: `Get compliance summary for benchmark`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client := &http.Client{} | ||
configuration, err := config.ReadConfigFile() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
outputFormat := utils.ReadStringFlag(cmd, "output") | ||
if outputFormat == "" { | ||
outputFormat = configuration.OutputFormat | ||
} | ||
|
||
benchmarkIDs, err := utils.ReadStringSliceFlag(cmd, "benchmark-id") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
isRoot := utils.ReadBoolFlag(cmd, "is-root") | ||
requestPayload := types.ComplianceSummaryOfBenchmarkRequest{ | ||
Benchmarks: benchmarkIDs, | ||
IsRoot: &isRoot, | ||
} | ||
|
||
payload, err := json.Marshal(requestPayload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url := fmt.Sprintf("main/compliance/api/v3/compliance/summary/benchmark") | ||
request, err := request.GenerateRequest( | ||
configuration.ApiKey, | ||
configuration.ApiEndpoint, | ||
"POST", | ||
url, | ||
payload, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
response, err := client.Do(request) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
fmt.Println(string(body)) | ||
return nil | ||
} | ||
|
||
var summary []types.ComplianceSummaryOfBenchmarkResponse | ||
err = json.Unmarshal(body, &summary) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if outputFormat == "table" { | ||
fmt.Println("Table view not supported, use json view: --output json") | ||
// TODO | ||
} else { | ||
js, err := json.MarshalIndent(summary, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(js)) | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package get | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/adorigi/checkctl/pkg/config" | ||
"github.com/adorigi/checkctl/pkg/request" | ||
"github.com/adorigi/checkctl/pkg/types" | ||
"github.com/adorigi/checkctl/pkg/utils" | ||
"github.com/spf13/cobra" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
// complianceSummaryForIntegrationCmd represents the benchmarks command | ||
var complianceSummaryForIntegrationCmd = &cobra.Command{ | ||
Use: "compliance-summary-for-integration", | ||
Short: "Get compliance summary for integration", | ||
Long: `Get compliance summary for integration`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client := &http.Client{} | ||
configuration, err := config.ReadConfigFile() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
outputFormat := utils.ReadStringFlag(cmd, "output") | ||
if outputFormat == "" { | ||
outputFormat = configuration.OutputFormat | ||
} | ||
|
||
benchmarkId := utils.ReadStringFlag(cmd, "benchmark-id") | ||
if benchmarkId == "" { | ||
fmt.Println("Error: must specify benchmark id") | ||
return nil | ||
} | ||
|
||
integrationStr := utils.ReadStringFlag(cmd, "integration") | ||
if integrationStr == "" { | ||
fmt.Println(`Error: must specify integration | ||
Integration info in the form 'integration=AWS,id=123,id_name=name'`) | ||
return nil | ||
} | ||
integration := types.ParseIntegrationInfo(integrationStr) | ||
|
||
requestPayload := types.ComplianceSummaryOfIntegrationRequest{ | ||
Integration: integration, | ||
BenchmarkId: benchmarkId, | ||
} | ||
|
||
payload, err := json.Marshal(requestPayload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url := fmt.Sprintf("main/compliance/api/v3/compliance/summary/integration") | ||
request, err := request.GenerateRequest( | ||
configuration.ApiKey, | ||
configuration.ApiEndpoint, | ||
"POST", | ||
url, | ||
payload, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
response, err := client.Do(request) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
fmt.Println(string(body)) | ||
return nil | ||
} | ||
|
||
var summary types.ComplianceSummaryOfIntegrationResponse | ||
err = json.Unmarshal(body, &summary) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if outputFormat == "table" { | ||
fmt.Println("Table view not supported, use json view: --output json") | ||
// TODO | ||
} else { | ||
js, err := json.MarshalIndent(summary, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(js)) | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package get | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/adorigi/checkctl/pkg/config" | ||
"github.com/adorigi/checkctl/pkg/request" | ||
"github.com/adorigi/checkctl/pkg/types" | ||
"github.com/adorigi/checkctl/pkg/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// jobDetailsCmd represents the controls command | ||
var jobDetailsCmd = &cobra.Command{ | ||
Use: "job-details", | ||
Short: "Get Job Details", | ||
Long: `Get Job Details`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
client := &http.Client{} | ||
configuration, err := config.ReadConfigFile() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
outputFormat := utils.ReadStringFlag(cmd, "output") | ||
if outputFormat == "" { | ||
outputFormat = configuration.OutputFormat | ||
} | ||
|
||
jobId := utils.ReadStringFlag(cmd, "job-id") | ||
if jobId == "" { | ||
return fmt.Errorf("job-id flag is required") | ||
} | ||
|
||
var url string | ||
jobType := utils.ReadStringFlag(cmd, "job-type") | ||
switch jobType { | ||
case "compliance", "analytics", "discovery": | ||
url = fmt.Sprintf("main/schedule/api/v3/job/%s/%s", jobType, jobId) | ||
default: | ||
return fmt.Errorf("please provide a valid job-type: compliance, analytics, discovery") | ||
} | ||
|
||
request, err := request.GenerateRequest( | ||
configuration.ApiKey, | ||
configuration.ApiEndpoint, | ||
"GET", | ||
url, | ||
[]byte{}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
response, err := client.Do(request) | ||
if err != nil { | ||
return err | ||
} | ||
defer response.Body.Close() | ||
|
||
body, err := io.ReadAll(response.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if response.StatusCode != 200 { | ||
fmt.Println(string(body)) | ||
return nil | ||
} | ||
|
||
var job types.GetComplianceJobStatusResponse | ||
err = json.Unmarshal(body, &job) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if outputFormat == "table" { | ||
fmt.Println("Table view not supported, use json view: --output json") | ||
//TODO | ||
} else { | ||
js, err := json.MarshalIndent(job, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Print(string(js)) | ||
} | ||
|
||
return nil | ||
}, | ||
} |
Oops, something went wrong.