mirror of
https://github.com/hanzoai/status.git
synced 2026-10-30 18:21:48 +00:00
zip's registration is a verb method on the group, so a route that is not a typed operation says which method it answers with. The security package's own two-method router goes with it: it existed so both the app and a sub-router could satisfy one name, and restating a routing surface is what let the two disagree — the methods it named no longer exist. The app spells itself as a group, which registers at exactly the paths it did. The toolchain and the pin move together, because below zip v1.36.50 the JSON encoder was selected on a build tag: a repo whose go directive rises first writes a wire that is neither the old release's nor the new one's until the pin catches up. metrics_test.go still does not compile, before and after: it compares a metric registry against a gatherer from a different metrics library, so the two Gather signatures disagree. That is its own change. Co-authored-by: Hanzo Dev <[email protected]>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/zap-proto/zip"
|
|
"hanzo.ai/status/config"
|
|
"hanzo.ai/status/security"
|
|
)
|
|
|
|
type ConfigHandler struct {
|
|
securityConfig *security.Config
|
|
config *config.Config
|
|
}
|
|
|
|
func (handler ConfigHandler) GetConfig(c *zip.Ctx) error {
|
|
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(c)
|
|
}
|
|
|
|
// Prepare response with announcements
|
|
response := map[string]interface{}{
|
|
"oidc": hasOIDC,
|
|
"authenticated": isAuthenticated,
|
|
}
|
|
// Add announcements if available, otherwise use empty slice
|
|
if handler.config != nil && handler.config.Announcements != nil && len(handler.config.Announcements) > 0 {
|
|
response["announcements"] = handler.config.Announcements
|
|
} else {
|
|
response["announcements"] = []interface{}{}
|
|
}
|
|
|
|
// Return the config as JSON
|
|
c.SetHeader("Content-Type", "application/json")
|
|
responseBytes, err := json.Marshal(response)
|
|
if err != nil {
|
|
return c.String(500, fmt.Sprintf(`{"error":"Failed to marshal response: %s"}`, err.Error()))
|
|
}
|
|
return c.Bytes(200, responseBytes)
|
|
}
|