diff --git a/cmd/get/job_details.go b/cmd/get/job_details.go index 251870e..548d5ff 100644 --- a/cmd/get/job_details.go +++ b/cmd/get/job_details.go @@ -3,12 +3,12 @@ package get import ( "encoding/json" "fmt" + "github.com/adorigi/checkctl/pkg/types" "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" ) @@ -71,21 +71,59 @@ var jobDetailsCmd = &cobra.Command{ return nil } - var job types.GetComplianceJobStatusResponse - err = json.Unmarshal(body, &job) - if err != nil { - return err - } + switch jobType { + case "compliance": + 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 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)) + } + case "discovery": + var job types.GetDescribeJobStatusResponse + err = json.Unmarshal(body, &job) if err != nil { return err } - fmt.Print(string(js)) + + 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)) + } + case "analytics": + var job types.GetAnalyticsJobStatusResponse + 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 diff --git a/pkg/types/jobs.go b/pkg/types/jobs.go index f8e9480..312ce2b 100644 --- a/pkg/types/jobs.go +++ b/pkg/types/jobs.go @@ -18,3 +18,20 @@ type ListJobsByTypeItem struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } + +type GetDescribeJobStatusResponse struct { + JobId uint `json:"job_id"` + IntegrationInfo IntegrationInfo `json:"integration_info"` + JobStatus string `json:"job_status"` + DiscoveryType string `json:"discovery_type"` + ResourceType string `json:"resource_type"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +type GetAnalyticsJobStatusResponse struct { + JobId uint `json:"job_id"` + JobStatus string `json:"job_status"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +}