-
Notifications
You must be signed in to change notification settings - Fork 787
/
compliance_status.go
84 lines (74 loc) · 2.23 KB
/
compliance_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package cmd
import (
"fmt"
"io"
"github.com/heptio/sonobuoy/pkg/plugin/aggregation"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/log"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1/terminal"
)
var (
complianceStatusLong = templates.LongDesc(`
Retrieves the current status of the compliance tests
`)
complianceStatusExample = templates.Examples(`
# Get the status
jx compliance status
`)
)
// ComplianceStatusOptions options for "compliance status" command
type ComplianceStatusOptions struct {
CommonOptions
}
// NewCmdComplianceStatus creates a command object for the "compliance status" action, which
// retrieve the status of E2E compliance tests
func NewCmdComplianceStatus(f Factory, in terminal.FileReader, out terminal.FileWriter, errOut io.Writer) *cobra.Command {
options := &ComplianceStatusOptions{
CommonOptions: CommonOptions{
Factory: f,
In: in,
Out: out,
Err: errOut,
},
}
cmd := &cobra.Command{
Use: "status",
Short: "Retrieves the status of compliance tests",
Long: complianceStatusLong,
Example: complianceStatusExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
return cmd
}
// Run implements the "compliance status" command
func (o *ComplianceStatusOptions) Run() error {
cc, err := o.Factory.CreateComplianceClient()
if err != nil {
return errors.Wrap(err, "could not create the compliance client")
}
status, err := cc.GetStatus(complianceNamespace)
if err != nil {
return errors.Wrap(err, "failed to retrieve the status")
}
log.Infoln(hummanReadableStatus(status.Status))
return nil
}
func hummanReadableStatus(status string) string {
switch status {
case aggregation.RunningStatus:
return "Compliance tests are still running, it can take up to 60 minutes."
case aggregation.FailedStatus:
return "Compliance tests have failed. You can check what happened with `jx compliance results`."
case aggregation.CompleteStatus:
return "Compliance tests completed. Use `jx compliance results` to display the results."
default:
return fmt.Sprintf("Compliance tests are in unknown state %q.", status)
}
}