grim/hgkeeper

Add a health endpoing at /hgk/health

2022-03-07, Gary Kramlich
09d54726d3f1
Parents bc46a398eba6
Children 61b4f876b057
Add a health endpoing at /hgk/health
--- a/README.md Mon Mar 07 02:14:35 2022 -0600
+++ b/README.md Mon Mar 07 02:22:45 2022 -0600
@@ -85,11 +85,14 @@
the repositories.
You can optionally disable either one of the HGWeb or SSH servers to limit
-resources or just disable the portions you don't need.
+resources or just disable the portions you don't need. However, the HTTP server
+will always be active as it contains a health endpoint at `/hgk/health` and
+could be used for integration with OpenSSH Server via the `--external-hostname`
+argument.
-For example, say you don't need public access or the web interface at all, you
-can disable it by passing `--disable-hgweb` to the `serve` command or by setting
-the `HGK_DISABLE_HGWEB` environment variable to `true`.
+For example, say you don't need public access or the HGWeb interface at all,
+you can disable it by passing `--disable-hgweb` to the `serve` command or by
+setting the `HGK_DISABLE_HGWEB` environment variable to `true`.
Likewise, if you just want to serve up read only repositories over http you can
disable the SSH server by passing `--disable-ssh` to the `serve` command or by
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/http/health.go Mon Mar 07 02:22:45 2022 -0600
@@ -0,0 +1,9 @@
+package http
+
+import (
+ "net/http"
+)
+
+func healthHandler(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusOK)
+}
--- a/http/server.go Mon Mar 07 02:14:35 2022 -0600
+++ b/http/server.go Mon Mar 07 02:22:45 2022 -0600
@@ -47,6 +47,8 @@
mux := http.NewServeMux()
+ mux.HandleFunc("/hgk/health", healthHandler)
+
if s.externalHostname != "" {
mux.Handle("/hgk/authorized_keys", authorizedKeysHandler(s.externalHostname, s.externalPort))
log.Infof("added /hgk/authorized_keys endpoint with external hostname %s and export port %s", s.externalHostname, s.externalPort)