package v1 import ( "log/slog" "net/http" "github.com/wild-cloud/wild-central/internal/secrets" ) // GetIntegrations returns integration info including the API bearer token. func (api *API) GetIntegrations(w http.ResponseWriter, r *http.Request) { token, err := api.secrets.GetSecret("api.bearerToken") if err != nil { token = "" } respondJSON(w, http.StatusOK, map[string]any{ "apiToken": map[string]any{ "token": token, "description": "Bearer token for authenticating with the Wild Central API. Used by Wild Cloud and other services.", }, }) } // RotateAPIToken generates a new API bearer token and saves it to secrets. func (api *API) RotateAPIToken(w http.ResponseWriter, r *http.Request) { token, err := secrets.GenerateSecret(secrets.DefaultSecretLength) if err != nil { respondError(w, http.StatusInternalServerError, "Failed to generate token") return } if err := api.secrets.SetSecret("api.bearerToken", token); err != nil { respondError(w, http.StatusInternalServerError, "Failed to save token") return } slog.Info("API bearer token rotated") respondJSON(w, http.StatusOK, map[string]any{ "token": token, "message": "API token rotated. Services using the old token will need to be updated.", }) }