mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-29 06:31:10 +01:00
Return different exit codes for different diagnose results (#11758)
This allows operators to run diagnose in scripts and detect the difference between success, warning, and failure. Exit codes are now: 0: Success (no warnings) 1: Failure (some test failed) 2: Warning (some test warned) 3: User input failure such as a bad flag 4: Other error
This commit is contained in:
parent
d06e2a015d
commit
001b89c090
@ -141,7 +141,7 @@ func (c *OperatorDiagnoseCommand) Run(args []string) int {
|
|||||||
f := c.Flags()
|
f := c.Flags()
|
||||||
if err := f.Parse(args); err != nil {
|
if err := f.Parse(args); err != nil {
|
||||||
c.UI.Error(err.Error())
|
c.UI.Error(err.Error())
|
||||||
return 1
|
return 3
|
||||||
}
|
}
|
||||||
return c.RunWithParsedFlags()
|
return c.RunWithParsedFlags()
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ func (c *OperatorDiagnoseCommand) RunWithParsedFlags() int {
|
|||||||
|
|
||||||
if len(c.flagConfigs) == 0 {
|
if len(c.flagConfigs) == 0 {
|
||||||
c.UI.Error("Must specify a configuration file using -config.")
|
c.UI.Error("Must specify a configuration file using -config.")
|
||||||
return 1
|
return 3
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.diagnose == nil {
|
if c.diagnose == nil {
|
||||||
@ -171,7 +171,7 @@ func (c *OperatorDiagnoseCommand) RunWithParsedFlags() int {
|
|||||||
resultsJS, err := json.MarshalIndent(results, "", " ")
|
resultsJS, err := json.MarshalIndent(results, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error marshalling results: %v", err)
|
fmt.Fprintf(os.Stderr, "error marshalling results: %v", err)
|
||||||
return 2
|
return 4
|
||||||
}
|
}
|
||||||
c.UI.Output(string(resultsJS))
|
c.UI.Output(string(resultsJS))
|
||||||
} else {
|
} else {
|
||||||
@ -180,6 +180,13 @@ func (c *OperatorDiagnoseCommand) RunWithParsedFlags() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
// Use a different return code
|
||||||
|
switch results.Status {
|
||||||
|
case diagnose.WarningStatus:
|
||||||
|
return 2
|
||||||
|
case diagnose.ErrorStatus:
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user