New Integrations page in Wild Central UI for managing API tokens. Provides token display, copy, and rotation so Wild Cloud and other services can easily retrieve their authentication credentials. - GET /api/v1/integrations returns current API token - POST /api/v1/integrations/api-token/rotate generates a new token - Frontend with show/hide toggle, copy button, and usage instructions - Added to sidebar navigation under Central section
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
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.",
|
|
})
|
|
}
|