CI / Test (linux/amd64) (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Cross-build (darwin/amd64) (push) Waiting to run
CI / Cross-build (linux/amd64) (push) Waiting to run
CI / Cross-build (darwin/arm64) (push) Waiting to run
CI / Cross-build (linux/arm64) (push) Waiting to run
- Migrate .golangci.yml to golangci-lint v2 config format - Bump golangci-lint-action from v6 (Node 20, deprecated) to v9 (Node 24) - Fix errcheck: check fmt.Fscanln and fmt.Sscanf return values - Fix ineffassign: replace unused vars with _ in test files - Fix revive unused-parameter: rename unused cmd/args/r/c params to _ - Fix revive empty-block: invert if condition in push command - Fix revive redefines-builtin-id: rename 'clear' to 'clearsigned' - Fix revive blank-imports: add comment on modernc.org/sqlite import - Fix unused: remove unused 'suite' and 'gen' fields from cache entry
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package restapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
apitypes "urapt/shared/api"
|
|
"urapt/shared/httputil"
|
|
"urapt/shared/version"
|
|
)
|
|
|
|
// ServerInfo returns build/setup metadata for the server.
|
|
func (api *API) ServerInfo(w http.ResponseWriter, r *http.Request) {
|
|
users, err := api.Store.ListUsers(r.Context())
|
|
if err != nil {
|
|
httputil.WriteError(w, http.StatusInternalServerError, httputil.CodeInternal, "failed to read users")
|
|
return
|
|
}
|
|
fp := ""
|
|
if api.Signer != nil {
|
|
fp = api.Signer.Fingerprint()
|
|
}
|
|
httputil.WriteJSON(w, http.StatusOK, apitypes.ServerInfo{
|
|
Version: version.Version,
|
|
NeedsSetup: len(users) == 0,
|
|
DefaultKeyFingerprint: fp,
|
|
OpenRegistration: api.Config.OpenRegistration,
|
|
})
|
|
}
|
|
|
|
// ServerPubkey returns the ASCII-armored default signing key.
|
|
func (api *API) ServerPubkey(w http.ResponseWriter, _ *http.Request) {
|
|
if api.Signer == nil {
|
|
httputil.WriteError(w, http.StatusServiceUnavailable, httputil.CodeInternal, "no signing key configured")
|
|
return
|
|
}
|
|
pub, err := api.Signer.PublicKeyArmored()
|
|
if err != nil {
|
|
httputil.WriteError(w, http.StatusInternalServerError, httputil.CodeInternal, "failed to read key")
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/pgp-keys")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write([]byte(pub))
|
|
}
|