mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-20 01:04:15 +00:00
Implements linter for pkg/hold missing warnings
This commit is contained in:
@@ -150,16 +150,18 @@ func NewAdminUI(ctx context.Context, holdPDS *pds.HoldPDS, quotaMgr *quota.Manag
|
||||
|
||||
// Session management
|
||||
|
||||
func (ui *AdminUI) createSession(did, handle string) string {
|
||||
func (ui *AdminUI) createSession(did, handle string) (string, error) {
|
||||
b := make([]byte, 32)
|
||||
rand.Read(b)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
return "", fmt.Errorf("failed to create session token: %w", err)
|
||||
}
|
||||
token := base64.URLEncoding.EncodeToString(b)
|
||||
|
||||
ui.sessionsMu.Lock()
|
||||
ui.sessions[token] = &AdminSession{DID: did, Handle: handle}
|
||||
ui.sessionsMu.Unlock()
|
||||
|
||||
return token
|
||||
return token, nil
|
||||
}
|
||||
|
||||
func (ui *AdminUI) getSession(token string) *AdminSession {
|
||||
@@ -340,7 +342,10 @@ func (ui *AdminUI) handleClientMetadata(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Header().Set("Cache-Control", "public, max-age=3600")
|
||||
json.NewEncoder(w).Encode(metadata)
|
||||
if err := json.NewEncoder(w).Encode(metadata); err != nil {
|
||||
slog.Error("failed to encode json to http response", "error", err, "path", r.URL.Path)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// Close cleans up resources (no-op now, but keeps interface consistent)
|
||||
|
||||
@@ -123,7 +123,10 @@ func (ui *AdminUI) handleStatsAPI(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Otherwise return JSON
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(stats)
|
||||
if err := json.NewEncoder(w).Encode(stats); err != nil {
|
||||
slog.Error("failed to encode json to http response", "error", err, "path", r.URL.Path)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// UserUsage represents storage usage for a user
|
||||
@@ -192,5 +195,8 @@ func (ui *AdminUI) handleTopUsersAPI(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Otherwise return JSON
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(users)
|
||||
if err := json.NewEncoder(w).Encode(users); err != nil {
|
||||
slog.Error("failed to encode json to http response", "error", err, "path", r.URL.Path)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,12 @@ func (ui *AdminUI) handleCallback(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Create session and set cookie
|
||||
token := ui.createSession(did, handle)
|
||||
token, err := ui.createSession(did, handle)
|
||||
if err != nil {
|
||||
slog.Error("failed to create session token", "error", err, "path", r.URL.Path)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ui.setSessionCookie(w, r, token)
|
||||
|
||||
slog.Info("Admin login successful", "did", did, "handle", handle)
|
||||
|
||||
@@ -319,7 +319,11 @@ func (ui *AdminUI) handleCrewUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Re-apply tier to new record
|
||||
if tier != "" {
|
||||
ui.pds.UpdateCrewMemberTier(ctx, current.Member, tier)
|
||||
if err := ui.pds.UpdateCrewMemberTier(ctx, current.Member, tier); err != nil {
|
||||
slog.Error("failed to update crew member tier", "error", err, "path", r.URL.Path)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user