feat: authorize Creator continuity reads
CI / test (push) Failing after 15m12s

This commit is contained in:
m
2026-08-16 15:45:39 +03:00
parent 0d76c81f00
commit eb343cd76e
7 changed files with 237 additions and 3 deletions
+39 -3
View File
@@ -3,12 +3,15 @@ package main
import (
"context"
"encoding/json"
"git.cin.su/m/Assistant/adapters/postgres"
"git.cin.su/m/Assistant/contracts/continuity"
"git.cin.su/m/Assistant/runtime/health"
"errors"
"log"
"net/http"
"os"
"time"
"git.cin.su/m/Assistant/adapters/postgres"
"git.cin.su/m/Assistant/contracts/continuity"
"git.cin.su/m/Assistant/runtime/health"
)
func main() {
@@ -21,6 +24,10 @@ func main() {
log.Fatal(err)
}
defer repository.Close()
identityClient, err := newCreatorIdentityClient(envOr("CORE_RUNTIME_URL", "http://core-runtime:8080"), &http.Client{Timeout: 5 * time.Second})
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/healthz", health.Handler{Runtime: "continuity-runtime", SemanticGeneration: 1, ArchitectureGeneration: 1})
mux.HandleFunc("POST /v1/prospective-items", func(w http.ResponseWriter, r *http.Request) {
@@ -44,8 +51,37 @@ func main() {
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(item)
})
mux.HandleFunc("GET /v1/creator/prospective-items/{id}", func(w http.ResponseWriter, r *http.Request) {
session, err := identityClient.Session(r.Context(), r.Header.Get("Authorization"))
if errors.Is(err, errCreatorSessionDenied) {
http.Error(w, "creator session denied", http.StatusUnauthorized)
return
}
if err != nil {
http.Error(w, "identity service unavailable", http.StatusServiceUnavailable)
return
}
item, err := repository.Load(r.Context(), continuity.ProspectiveItemID(r.PathValue("id")))
if err != nil {
http.Error(w, "prospective item not found", http.StatusNotFound)
return
}
if item.OwnerPrincipalID != session.PrincipalID {
http.Error(w, "prospective item denied", http.StatusForbidden)
return
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(item)
})
log.Printf("continuity-runtime listening on %s", addr)
if err := http.ListenAndServe(addr, mux); err != nil {
log.Fatal(err)
}
}
func envOr(name, fallback string) string {
if value := os.Getenv(name); value != "" {
return value
}
return fallback
}