aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-31 00:13:17 +0100
committerLibravatar Rutger Broekhoff2023-12-31 00:13:17 +0100
commit01940ecf7696b33bcecd82f00f5b5eaf81d2b156 (patch)
tree157ca52bcb744937fed860a7ec0fdccbb86cb83b /cmd
parent3c03c787c8fb32768d222ae1323b8dafb6aa0fdf (diff)
downloadgitolfs3-01940ecf7696b33bcecd82f00f5b5eaf81d2b156.tar.gz
gitolfs3-01940ecf7696b33bcecd82f00f5b5eaf81d2b156.zip
Try formatting x-amz-checksum-sha256 as Base64
Although this already looks like a lost cause (Scaleway Object Storage doesn't seem to care about these headers -- certainly not about Content-Length -- I wanted to see if I could still get automatic checksum verification working.
Diffstat (limited to 'cmd')
-rw-r--r--cmd/git-lfs-server/main.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/cmd/git-lfs-server/main.go b/cmd/git-lfs-server/main.go
index 63b6edf..a1ad5a4 100644
--- a/cmd/git-lfs-server/main.go
+++ b/cmd/git-lfs-server/main.go
@@ -4,6 +4,7 @@ import (
4 "bytes" 4 "bytes"
5 "context" 5 "context"
6 "crypto/ed25519" 6 "crypto/ed25519"
7 "encoding/base64"
7 "encoding/hex" 8 "encoding/hex"
8 "encoding/json" 9 "encoding/json"
9 "errors" 10 "errors"
@@ -134,6 +135,14 @@ func makeObjError(obj parsedBatchObject, message string, code int) batchResponse
134 } 135 }
135} 136}
136 137
138func sha256AsBase64(hash string) string {
139 raw, err := hex.DecodeString(hash)
140 if err != nil {
141 return ""
142 }
143 return base64.StdEncoding.EncodeToString(raw)
144}
145
137func (h *handler) handleDownloadObject(ctx context.Context, repo string, obj parsedBatchObject) batchResponseObject { 146func (h *handler) handleDownloadObject(ctx context.Context, repo string, obj parsedBatchObject) batchResponseObject {
138 fullPath := path.Join(repo+".git", "lfs/objects", obj.firstByte, obj.secondByte, obj.fullHash) 147 fullPath := path.Join(repo+".git", "lfs/objects", obj.firstByte, obj.secondByte, obj.fullHash)
139 expiresIn := time.Hour * 24 148 expiresIn := time.Hour * 24
@@ -184,7 +193,7 @@ func (h *handler) handleUploadObject(ctx context.Context, repo string, obj parse
184 193
185 presigned, err := h.mc.Presign(ctx, http.MethodPut, h.bucket, fullPath, expiresIn, url.Values{ 194 presigned, err := h.mc.Presign(ctx, http.MethodPut, h.bucket, fullPath, expiresIn, url.Values{
186 "x-amz-sdk-checksum-algorithm": {"sha256"}, 195 "x-amz-sdk-checksum-algorithm": {"sha256"},
187 "x-amz-checksum-sha256": {obj.fullHash}, 196 "x-amz-checksum-sha256": {sha256AsBase64(obj.fullHash)},
188 "Content-Length": {strconv.FormatUint(obj.size, 10)}, 197 "Content-Length": {strconv.FormatUint(obj.size, 10)},
189 }) 198 })
190 if err != nil { 199 if err != nil {
@@ -332,6 +341,11 @@ func (h *handler) authorize(ctx context.Context, w http.ResponseWriter, r *http.
332func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 341func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
333 ctx := context.WithValue(r.Context(), requestIDKey, xid.New().String()) 342 ctx := context.WithValue(r.Context(), requestIDKey, xid.New().String())
334 343
344 if r.Method != http.MethodPost {
345 makeRespError(ctx, w, "Method not allowed", http.StatusMethodNotAllowed)
346 return
347 }
348
335 reqPath := os.Getenv("PATH_INFO") 349 reqPath := os.Getenv("PATH_INFO")
336 if reqPath == "" { 350 if reqPath == "" {
337 reqPath = r.URL.Path 351 reqPath = r.URL.Path