/
health_ready.go
45 lines (36 loc) · 1.08 KB
/
health_ready.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
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"fmt"
"os"
"github.com/ory/oathkeeper/internal/httpclient/client/health"
"github.com/spf13/cobra"
"github.com/ory/x/cmdx"
)
// healthCmd represents the health command
var healthReadyCmd = &cobra.Command{
Use: "ready",
Short: "Checks if an ORY Oathkeeper deployment is ready",
Long: `Usage example:
oathkeeper health --endpoint=http://localhost:4456/ ready
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.IsInstanceReady(health.NewIsInstanceReadyParams())
// 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(healthReadyCmd)
}