2019-04-14 21:53:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *server) serveAllocationsHTTPPage() {
|
|
|
|
mux := http.NewServeMux()
|
|
|
|
|
|
|
|
mux.HandleFunc("/allocations", func(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
res := ""
|
|
|
|
a, err := s.db.Allocations()
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
|
|
if _, err := io.WriteString(w, err.Error()); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for podName, pubkeys := range a {
|
|
|
|
for _, pk := range pubkeys {
|
|
|
|
res += fmt.Sprintf("%s=%#x\n", podName, pk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
if _, err := io.WriteString(w, res); err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
srv := &http.Server{Addr: ":8080", Handler: mux}
|
2019-06-19 22:34:57 +00:00
|
|
|
go func() {
|
|
|
|
log.Fatal(srv.ListenAndServe())
|
|
|
|
}()
|
2019-04-14 21:53:34 +00:00
|
|
|
log.Info("Serving allocations page at :8080/allocations")
|
|
|
|
}
|