Skip to content

Commit 6a71b86

Browse files
authored
Merge pull request #39 from YASSERRMD/phase_2
refactor/fix: Phase 2 — code quality and safety
2 parents 38eb747 + 7215b34 commit 6a71b86

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

cmd/siqlah/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func main() {
143143
reg := provider.NewRegistry()
144144
srv := api.NewWithOptions(st, cpBuilder, operatorPub, operatorPriv, reg, version, *inferenceRegion)
145145
srv.WithBackendInfo(*logBackend, *signingBackend)
146+
if *rekorURL != "" {
147+
srv.WithRekorURL(*rekorURL)
148+
}
146149
if *x402Recipient != "" {
147150
srv.WithX402Recipient(*x402Recipient)
148151
}

internal/api/checkpoint.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ func (s *Server) handleVerifyCheckpoint(w http.ResponseWriter, r *http.Request)
128128
if cp.RekorLogIndex >= 0 {
129129
resp.RekorAnchored = true
130130
resp.RekorLogIndex = cp.RekorLogIndex
131-
resp.RekorEntryURL = "https://rekor.sigstore.dev/api/v1/log/entries?logIndex=" +
131+
rekorBase := s.rekorURL
132+
if rekorBase == "" {
133+
rekorBase = "https://rekor.sigstore.dev"
134+
}
135+
resp.RekorEntryURL = rekorBase + "/api/v1/log/entries?logIndex=" +
132136
strconv.FormatInt(cp.RekorLogIndex, 10)
133137
}
134138
writeJSON(w, http.StatusOK, resp)

internal/api/ingest.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"encoding/json"
77
"errors"
8+
"fmt"
89
"log/slog"
910
"net/http"
1011
"strconv"
@@ -86,10 +87,16 @@ func (s *Server) handleIngestBatch(w http.ResponseWriter, r *http.Request) {
8687
writeError(w, http.StatusBadRequest, "invalid JSON: "+err.Error())
8788
return
8889
}
90+
const maxBatchItems = 500
8991
if len(req.Items) == 0 {
9092
writeError(w, http.StatusBadRequest, "items must not be empty")
9193
return
9294
}
95+
if len(req.Items) > maxBatchItems {
96+
writeError(w, http.StatusBadRequest,
97+
fmt.Sprintf("batch exceeds maximum of %d items", maxBatchItems))
98+
return
99+
}
93100
receipts := make([]*vur.Receipt, 0, len(req.Items))
94101
for _, item := range req.Items {
95102
if err := validateIngestRequest(item); err != nil {

internal/api/server.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Server struct {
3333
logOrigin string
3434
logBackend string
3535
signerType string
36+
rekorURL string
3637
x402Bridge *x402.Bridge
3738
x402Recipient string
3839
modelReg *model.Registry
@@ -71,10 +72,6 @@ func NewWithOptions(
7172
) *Server {
7273
s := NewWithOrigin(st, b, operatorPub, operatorPriv, reg, version, "")
7374
s.inferenceRegion = inferenceRegion
74-
if inferenceRegion != "" && s.energyEst == nil {
75-
s.energyEst = energy.NewBenchmarkEstimator()
76-
s.carbonLookup = energy.NewStaticCarbonLookup()
77-
}
7875
return s
7976
}
8077

@@ -116,6 +113,13 @@ func (s *Server) WithX402Recipient(addr string) *Server {
116113
return s
117114
}
118115

116+
// WithRekorURL sets the Rekor transparency log base URL used when building
117+
// entry links in checkpoint verify responses. Defaults to the public Rekor instance.
118+
func (s *Server) WithRekorURL(url string) *Server {
119+
s.rekorURL = url
120+
return s
121+
}
122+
119123
// WithBackendInfo sets the log backend and signer type strings surfaced by GET /v1/health.
120124
func (s *Server) WithBackendInfo(logBackend, signerType string) *Server {
121125
s.logBackend = logBackend

0 commit comments

Comments
 (0)