.examples
.github
alerting
client
config
controller
handler
badge.go
badge_test.go
chart.go
chart_test.go
config.go
config_test.go
cors.go
endpoint_status.go
endpoint_status_test.go
favicon.go
favicon_test.go
gzip.go
handler.go
handler_test.go
spa.go
spa_test.go
util.go
util_test.go
controller.go
controller_test.go
core
docs
jsonpath
metrics
pattern
security
storage
test
util
vendor
watchdog
web
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE
Makefile
README.md
config.yaml
go.mod
go.sum
main.go
27 lines
766 B
Go
27 lines
766 B
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/TwiN/gatus/v3/security"
|
|
)
|
|
|
|
// ConfigHandler is a handler that returns information for the front end of the application.
|
|
type ConfigHandler struct {
|
|
securityConfig *security.Config
|
|
}
|
|
|
|
func (handler ConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
hasOIDC := false
|
|
isAuthenticated := true // Default to true if no security config is set
|
|
if handler.securityConfig != nil {
|
|
hasOIDC = handler.securityConfig.OIDC != nil
|
|
isAuthenticated = handler.securityConfig.IsAuthenticated(r)
|
|
}
|
|
// Return the config
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write([]byte(fmt.Sprintf(`{"oidc":%v,"authenticated":%v}`, hasOIDC, isAuthenticated)))
|
|
}
|