2022-01-03 00:29:34 +01:00
|
|
|
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
|
2022-01-03 03:37:15 +01:00
|
|
|
isAuthenticated := true // Default to true if no security config is set
|
2022-01-03 00:29:34 +01:00
|
|
|
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)))
|
|
|
|
}
|