-
-
Notifications
You must be signed in to change notification settings - Fork 348
/
health_alive.go
42 lines (34 loc) · 1.01 KB
/
health_alive.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
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/ory/oathkeeper/internal/httpclient/client/health"
"github.com/ory/x/cmdx"
)
// healthCmd represents the health command
var healthAliveCmd = &cobra.Command{
Use: "alive",
Short: "Checks if an ORY Oathkeeper deployment is alive",
Long: `Usage example:
oathkeeper health --endpoint=http://localhost:4456/ alive
Note:
The endpoint URL should point to a single ORY Oathkeeper deployment.
If the endpoint URL points to a Load Balancer, these commands will effective test the Load Balancer.
`,
Run: func(cmd *cobra.Command, args []string) {
client := newClient(cmd)
r, err := client.Health.IsInstanceAlive(health.NewIsInstanceAliveParams())
// If err, print err and exit 1
cmdx.Must(err, "%s", err)
// Print payload
fmt.Println(cmdx.FormatResponse(r.Payload))
// When healthy, ORY Oathkeeper always returns a status of "ok"
if r.Payload.Status != "ok" {
os.Exit(1)
}
},
}
func init() {
healthCmd.AddCommand(healthAliveCmd)
}