Monorepo for Tangled tangled.org

appview,knotserver: immutable nix flakeref link header #741

closed opened by boltless.me targeting master from push-ptrrwwvnkmxq
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3m4nnmyspof22
+59 -26
Interdiff #2 โ†’ #3
api/tangled/repoarchive.go

This file has not been changed.

appview/repo/archive.go

This patch was likely rebased, as context lines do not match.

appview/repo/router.go

This file has not been changed.

appview/state/git_http.go

This file has not been changed.

+53 -2
appview/state/proxy_knot.go
··· 5 5 "io" 6 6 "maps" 7 7 "net/http" 8 + "strings" 8 9 9 10 "github.com/bluesky-social/indigo/atproto/identity" 11 + indigoxrpc "github.com/bluesky-social/indigo/xrpc" 10 12 "github.com/go-chi/chi/v5" 13 + "github.com/go-git/go-git/v5/plumbing" 14 + "github.com/hashicorp/go-version" 15 + "tangled.org/core/api/tangled" 11 16 "tangled.org/core/appview/models" 17 + xrpcclient "tangled.org/core/appview/xrpcclient" 12 18 ) 13 19 14 20 func (s *State) InfoRefs(w http.ResponseWriter, r *http.Request) { ··· 59 65 s.proxyRequest(w, r, targetURL) 60 66 } 61 67 68 + var knotVersionDownloadArchiveConstraint = version.MustConstraints(version.NewConstraint(">= 1.12")) 69 + 62 70 func (s *State) DownloadArchive(w http.ResponseWriter, r *http.Request) { 71 + l := s.logger.With("handler", "DownloadArchive") 63 72 ref := chi.URLParam(r, "ref") 64 73 65 74 user, ok := r.Context().Value("resolvedId").(identity.Identity) 66 75 if !ok { 76 + l.Error("failed to resolve user") 67 77 http.Error(w, "failed to resolve user", http.StatusInternalServerError) 68 78 return 69 79 } ··· 74 84 scheme = "http" 75 85 } 76 86 77 - targetURL := fmt.Sprintf("%s://%s/%s/%s/archive/%s", scheme, repo.Knot, user.DID, repo.Name, ref) 78 - s.proxyRequest(w, r, targetURL) 87 + xrpcc := &indigoxrpc.Client{ 88 + Host: repo.Knot, 89 + } 90 + l = l.With("knot", repo.Knot) 91 + 92 + isCompatible := func() bool { 93 + out, err := tangled.KnotVersion(r.Context(), xrpcc) 94 + if err != nil { 95 + l.Warn("failed to get knot version", "err", err) 96 + return false 97 + } 98 + 99 + v, err := version.NewVersion(out.Version) 100 + if err != nil { 101 + l.Warn("failed to parse knot version", "version", out.Version, "err", err) 102 + return false 103 + } 104 + 105 + if !knotVersionDownloadArchiveConstraint.Check(v) { 106 + l.Warn("knot version incompatible.", "version", v) 107 + return false 108 + } 109 + return true 110 + }() 111 + l.Debug("knot compatibility check", "isCompatible", isCompatible) 112 + if isCompatible { 113 + targetURL := fmt.Sprintf("%s://%s/%s/%s/archive/%s", scheme, repo.Knot, user.DID, repo.Name, ref) 114 + s.proxyRequest(w, r, targetURL) 115 + } else { 116 + l.Debug("requesting xrpc/sh.tangled.repo.archive") 117 + archiveBytes, err := tangled.RepoArchive(r.Context(), xrpcc, "tar.gz", "", ref, repo.DidSlashRepo()) 118 + if xrpcerr := xrpcclient.HandleXrpcErr(err); xrpcerr != nil { 119 + l.Error("failed to call XRPC repo.archive", "err", xrpcerr) 120 + s.pages.Error503(w) 121 + return 122 + } 123 + safeRefFilename := strings.ReplaceAll(plumbing.ReferenceName(ref).Short(), "/", "-") 124 + filename := fmt.Sprintf("%s-%s.tar.gz", repo.Name, safeRefFilename) 125 + w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", filename)) 126 + w.Header().Set("Content-Type", "application/gzip") 127 + w.Header().Set("Content-Length", fmt.Sprintf("%d", len(archiveBytes))) 128 + w.Write(archiveBytes) 129 + } 79 130 } 80 131 81 132 func (s *State) proxyRequest(w http.ResponseWriter, r *http.Request, targetURL string) {
appview/state/router.go

This patch was likely rebased, as context lines do not match.

knotserver/archive.go

This file has not been changed.

knotserver/git/git.go

This patch was likely rebased, as context lines do not match.

knotserver/router.go

This file has not been changed.

knotserver/xrpc/repo_archive.go

This file has not been changed.

knotserver/xrpc/xrpc.go

This file has not been changed.

lexicons/repo/archive.json

This file has not been changed.

+1
go.mod
··· 132 132 github.com/hashicorp/go-secure-stdlib/parseutil v0.2.0 // indirect 133 133 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect 134 134 github.com/hashicorp/go-sockaddr v1.0.7 // indirect 135 + github.com/hashicorp/go-version v1.8.0 // indirect 135 136 github.com/hashicorp/golang-lru v1.0.2 // indirect 136 137 github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect 137 138 github.com/hashicorp/hcl v1.0.1-vault-7 // indirect
+2
go.sum
··· 264 264 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= 265 265 github.com/hashicorp/go-sockaddr v1.0.7 h1:G+pTkSO01HpR5qCxg7lxfsFEZaG+C0VssTy/9dbT+Fw= 266 266 github.com/hashicorp/go-sockaddr v1.0.7/go.mod h1:FZQbEYa1pxkQ7WLpyXJ6cbjpT8q0YgQaK/JakXqGyWw= 267 + github.com/hashicorp/go-version v1.8.0 h1:KAkNb1HAiZd1ukkxDFGmokVZe1Xy9HG6NUp+bPle2i4= 268 + github.com/hashicorp/go-version v1.8.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= 267 269 github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= 268 270 github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= 269 271 github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
+3 -24
nix/gomod2nix.toml
··· 165 165 [mod."github.com/davecgh/go-spew"] 166 166 version = "v1.1.2-0.20180830191138-d8f796af33cc" 167 167 hash = "sha256-fV9oI51xjHdOmEx6+dlq7Ku2Ag+m/bmbzPo6A4Y74qc=" 168 - [mod."github.com/decred/dcrd/dcrec/secp256k1/v4"] 169 - version = "v4.4.0" 170 - hash = "sha256-qrhEIwhDll3cxoVpMbm1NQ9/HTI42S7ms8Buzlo5HCg=" 171 168 [mod."github.com/dgraph-io/ristretto"] 172 169 version = "v0.2.0" 173 170 hash = "sha256-bnpxX+oO/Qf7IJevA0gsbloVoqRx+5bh7RQ9d9eLNYw=" ··· 307 304 [mod."github.com/hashicorp/go-sockaddr"] 308 305 version = "v1.0.7" 309 306 hash = "sha256-p6eDOrGzN1jMmT/F/f/VJMq0cKNFhUcEuVVwTE6vSrs=" 307 + [mod."github.com/hashicorp/go-version"] 308 + version = "v1.8.0" 309 + hash = "sha256-KXtqERmYrWdpqPCViWcHbe6jnuH7k16bvBIcuJuevj8=" 310 310 [mod."github.com/hashicorp/golang-lru"] 311 311 version = "v1.0.2" 312 312 hash = "sha256-yy+5botc6T5wXgOe2mfNXJP3wr+MkVlUZ2JBkmmrA48=" ··· 373 373 [mod."github.com/klauspost/cpuid/v2"] 374 374 version = "v2.3.0" 375 375 hash = "sha256-50JhbQyT67BK38HIdJihPtjV7orYp96HknI2VP7A9Yc=" 376 - [mod."github.com/lestrrat-go/blackmagic"] 377 - version = "v1.0.4" 378 - hash = "sha256-HmWOpwoPDNMwLdOi7onNn3Sb+ZsAa3Ai3gVBbXmQ0e8=" 379 - [mod."github.com/lestrrat-go/httpcc"] 380 - version = "v1.0.1" 381 - hash = "sha256-SMRSwJpqDIs/xL0l2e8vP0W65qtCHX2wigcOeqPJmos=" 382 - [mod."github.com/lestrrat-go/httprc"] 383 - version = "v1.0.6" 384 - hash = "sha256-mfZzePEhrmyyu/avEBd2MsDXyto8dq5+fyu5lA8GUWM=" 385 - [mod."github.com/lestrrat-go/iter"] 386 - version = "v1.0.2" 387 - hash = "sha256-30tErRf7Qu/NOAt1YURXY/XJSA6sCr6hYQfO8QqHrtw=" 388 - [mod."github.com/lestrrat-go/jwx/v2"] 389 - version = "v2.1.6" 390 - hash = "sha256-0LszXRZIba+X8AOrs3T4uanAUafBdlVB8/MpUNEFpbc=" 391 - [mod."github.com/lestrrat-go/option"] 392 - version = "v1.0.1" 393 - hash = "sha256-jVcIYYVsxElIS/l2akEw32vdEPR8+anR6oeT1FoYULI=" 394 376 [mod."github.com/lucasb-eyer/go-colorful"] 395 377 version = "v1.2.0" 396 378 hash = "sha256-Gg9dDJFCTaHrKHRR1SrJgZ8fWieJkybljybkI9x0gyE=" ··· 511 493 [mod."github.com/ryanuber/go-glob"] 512 494 version = "v1.0.0" 513 495 hash = "sha256-YkMl1utwUhi3E0sHK23ISpAsPyj4+KeXyXKoFYGXGVY=" 514 - [mod."github.com/segmentio/asm"] 515 - version = "v1.2.0" 516 - hash = "sha256-zbNuKxNrUDUc6IlmRQNuJQzVe5Ol/mqp7srDg9IMMqs=" 517 496 [mod."github.com/sergi/go-diff"] 518 497 version = "v1.1.0" 519 498 hash = "sha256-8NJMabldpf40uwQN20T6QXx5KORDibCBJL02KD661xY="

History

7 rounds 2 comments
sign up or login to add to the discussion
2 commits
expand
appview,knotserver: support immutable nix flakeref link header
lexicons,knotserver: remove /xrpc/sh.tangled.repo.archive endpoint
3/3 success
expand
expand 1 comment
closed without merging
2 commits
expand
appview,knotserver: support immutable nix flakeref link header
lexicons,knotserver: remove /xrpc/sh.tangled.repo.archive endpoint
3/3 success
expand
expand 0 comments
3 commits
expand
nix: bump gomod2nix
appview,knotserver: support immutable nix flakeref link header
lexicons,knotserver: remove /xrpc/sh.tangled.repo.archive endpoint
3/3 success
expand
expand 0 comments
3 commits
expand
nix: bump gomod2nix
appview,knotserver: support immutable nix flakeref link header
lexicons,knotserver: remove sh.tangled.repo.archive
2/3 failed, 1/3 success
expand
expand 0 comments
3 commits
expand
appview,knotserver: support knot http endpoint for archive
knotserver: support immutable nix flakeref link header
lexicons,knotserver: remove sh.tangled.repo.archive
3/3 success
expand
expand 0 comments
1 commit
expand
appview,knotserver: immutable nix flakeref link header
3/3 success
expand
expand 0 comments
1 commit
expand
appview,knotserver: immutable nix flakeref link header
1/3 failed, 2/3 timeout
expand
expand 1 comment

link to related issue: #231