-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd: Add health check commands (#319)
Co-Authored-By: hackerman <[email protected]>
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// healthCmd represents the health command | ||
var healthCmd = &cobra.Command{ | ||
Use: "health", | ||
Short: "Commands for checking the status of an ORY Oathkeeper deployment", | ||
Long: `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) { | ||
fmt.Println(cmd.UsageString()) | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(healthCmd) | ||
healthCmd.PersistentFlags().StringP("endpoint", "e", "", "The endpoint URL of ORY Oathkeeper's management API") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ory/oathkeeper/sdk/go/oathkeeper/client/api" | ||
"github.com/ory/x/cmdx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// 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.API.IsInstanceAlive(api.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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/ory/oathkeeper/sdk/go/oathkeeper/client/api" | ||
"github.com/ory/x/cmdx" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// 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.API.IsInstanceReady(api.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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters