Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris committed Nov 14, 2024
1 parent f1216c9 commit 6dd3c2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion systemapi-config.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[general]
listen_addr = "0.0.0.0:3535"
pipe_file = "pipe.fifo"
pprof = true
log_json = false
log_debug = true

# The path to the secret file used for basic auth
basic_auth_secret_path = "/tmp/basic_auth_secret"
# basic_auth_secret_path = "/tmp/basic_auth_secret"

[actions]
# reboot = "reboot"
Expand Down
9 changes: 5 additions & 4 deletions systemapi/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

type systemAPIConfigGeneral struct {
ListenAddr string `toml:"listen_addr"`
PipeFile string `toml:"pipe_file"`
LogJSON bool `toml:"log_json"`
LogDebug bool `toml:"log_debug"`
ListenAddr string `toml:"listen_addr"`
PipeFile string `toml:"pipe_file"`
LogJSON bool `toml:"log_json"`
LogDebug bool `toml:"log_debug"`
EnablePprof bool `toml:"pprof"` // Enables pprof endpoints

BasicAuthSecretPath string `toml:"basic_auth_secret_path"`
}
Expand Down
19 changes: 14 additions & 5 deletions systemapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
)

type HTTPServerConfig struct {
Config *SystemAPIConfig
Log *httplog.Logger
EnablePprof bool
Config *SystemAPIConfig
Log *httplog.Logger

DrainDuration time.Duration
GracefulShutdownDuration time.Duration
Expand Down Expand Up @@ -104,22 +103,32 @@ func (s *Server) getRouter() http.Handler {

mux.Use(httplog.RequestLogger(s.log))
mux.Use(middleware.Recoverer)

// Enable a custom HTTP Basic Auth middleware
mux.Use(BasicAuth("system-api", s.getBasicAuthHashedCredentials))

// Common APIs
mux.Get("/", s.handleLivenessCheck)
mux.Get("/livez", s.handleLivenessCheck)

// Event (log) APIs
mux.Get("/api/v1/new_event", s.handleNewEvent)
mux.Get("/api/v1/events", s.handleGetEvents)
mux.Get("/logs", s.handleGetLogs)

// API to set the basic auth secret
mux.Post("/api/v1/set-basic-auth", s.handleSetBasicAuthCreds)

// API to trigger an action
mux.Get("/api/v1/actions/{action}", s.handleAction)

// API to upload a file
mux.Post("/api/v1/file-upload/{file}", s.handleFileUpload)

if s.cfg.EnablePprof {
s.log.Info("pprof API enabled")
// Optionally, pprof
if s.cfg.Config.General.EnablePprof {
mux.Mount("/debug", middleware.Profiler())
s.log.Info("pprof API enabled: /debug/pprof/")
}

return mux
Expand Down

0 comments on commit 6dd3c2d

Please sign in to comment.