add version to accounts
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
package command
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/owncloud/ocis/accounts/pkg/config"
|
||||||
|
"github.com/owncloud/ocis/accounts/pkg/logging"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Health is the entrypoint for the health command.
|
||||||
|
func Health(cfg *config.Config) *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "health",
|
||||||
|
Usage: "Check health status",
|
||||||
|
Before: func(c *cli.Context) error {
|
||||||
|
return ParseConfig(c, cfg)
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
logger := logging.Configure(cfg.Service.Name, cfg.Log)
|
||||||
|
|
||||||
|
resp, err := http.Get(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"http://%s/healthz",
|
||||||
|
cfg.Debug.Addr,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Fatal().
|
||||||
|
Err(err).
|
||||||
|
Msg("Failed to request health check")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
logger.Fatal().
|
||||||
|
Int("code", resp.StatusCode).
|
||||||
|
Msg("Health seems to be in bad state")
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Debug().
|
||||||
|
Int("code", resp.StatusCode).
|
||||||
|
Msg("Health got a good state")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,8 +39,10 @@ func Execute(cfg *config.Config) error {
|
|||||||
ListAccounts(cfg),
|
ListAccounts(cfg),
|
||||||
InspectAccount(cfg),
|
InspectAccount(cfg),
|
||||||
RemoveAccount(cfg),
|
RemoveAccount(cfg),
|
||||||
PrintVersion(cfg),
|
|
||||||
RebuildIndex(cfg),
|
RebuildIndex(cfg),
|
||||||
|
|
||||||
|
Health(cfg),
|
||||||
|
PrintVersion(cfg),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user