aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/git-lfs-server
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/git-lfs-server')
-rw-r--r--cmd/git-lfs-server/main.go32
1 files changed, 21 insertions, 11 deletions
diff --git a/cmd/git-lfs-server/main.go b/cmd/git-lfs-server/main.go
index 0e2ea80..6688f68 100644
--- a/cmd/git-lfs-server/main.go
+++ b/cmd/git-lfs-server/main.go
@@ -205,6 +205,7 @@ func isLFSMediaType(t string) bool {
205func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 205func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
206 submatches := re.FindStringSubmatch(r.URL.Path) 206 submatches := re.FindStringSubmatch(r.URL.Path)
207 if len(submatches) != 1 { 207 if len(submatches) != 1 {
208 log("Got URL: %s", r.URL.Path)
208 makeRespError(w, "Not found", http.StatusNotFound) 209 makeRespError(w, "Not found", http.StatusNotFound)
209 return 210 return
210 } 211 }
@@ -290,10 +291,14 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
290 json.NewEncoder(w).Encode(resp) 291 json.NewEncoder(w).Encode(resp)
291} 292}
292 293
293func die(msg string, args ...any) { 294func log(msg string, args ...any) {
294 fmt.Fprint(os.Stderr, "Error: ") 295 fmt.Fprint(os.Stderr, "[gitolfs3] ")
295 fmt.Fprintf(os.Stderr, msg, args...) 296 fmt.Fprintf(os.Stderr, msg, args...)
296 fmt.Fprint(os.Stderr, "\n") 297 fmt.Fprint(os.Stderr, "\n")
298}
299
300func die(msg string, args ...any) {
301 log(msg, args...)
297 os.Exit(1) 302 os.Exit(1)
298} 303}
299 304
@@ -304,30 +309,35 @@ func main() {
304 accessKeyIDFile := os.Getenv("S3_ACCESS_KEY_ID_FILE") 309 accessKeyIDFile := os.Getenv("S3_ACCESS_KEY_ID_FILE")
305 secretAccessKeyFile := os.Getenv("S3_SECRET_ACCESS_KEY_FILE") 310 secretAccessKeyFile := os.Getenv("S3_SECRET_ACCESS_KEY_FILE")
306 311
312 log("Environment variables:")
313 for _, s := range os.Environ() {
314 log(" %s", s)
315 }
316
307 if anonUser == "" { 317 if anonUser == "" {
308 die("Expected environment variable ANON_USER to be set") 318 die("Fatal: expected environment variable ANON_USER to be set")
309 } 319 }
310 if endpoint == "" { 320 if endpoint == "" {
311 die("Expected environment variable S3_ENDPOINT to be set") 321 die("Fatal: expected environment variable S3_ENDPOINT to be set")
312 } 322 }
313 if bucket == "" { 323 if bucket == "" {
314 die("Expected environment variable S3_BUCKET to be set") 324 die("Fatal: expected environment variable S3_BUCKET to be set")
315 } 325 }
316 326
317 if accessKeyIDFile == "" { 327 if accessKeyIDFile == "" {
318 die("Expected environment variable S3_ACCESS_KEY_ID_FILE to be set") 328 die("Fatal: expected environment variable S3_ACCESS_KEY_ID_FILE to be set")
319 } 329 }
320 if secretAccessKeyFile == "" { 330 if secretAccessKeyFile == "" {
321 die("Expected environment variable S3_SECRET_ACCESS_KEY_FILE to be set") 331 die("Fatal: expected environment variable S3_SECRET_ACCESS_KEY_FILE to be set")
322 } 332 }
323 333
324 accessKeyID, err := os.ReadFile(accessKeyIDFile) 334 accessKeyID, err := os.ReadFile(accessKeyIDFile)
325 if err != nil { 335 if err != nil {
326 die("Failed to read access key ID from specified file: %s", err) 336 die("Fatal: failed to read access key ID from specified file: %s", err)
327 } 337 }
328 secretAccessKey, err := os.ReadFile(secretAccessKeyFile) 338 secretAccessKey, err := os.ReadFile(secretAccessKeyFile)
329 if err != nil { 339 if err != nil {
330 die("Failed to read secret access key from specified file: %s", err) 340 die("Fatal: failed to read secret access key from specified file: %s", err)
331 } 341 }
332 342
333 mc, err := minio.New(endpoint, &minio.Options{ 343 mc, err := minio.New(endpoint, &minio.Options{
@@ -335,11 +345,11 @@ func main() {
335 Secure: true, 345 Secure: true,
336 }) 346 })
337 if err != nil { 347 if err != nil {
338 die("Failed to create S3 client: %s", err) 348 die("Fatal: failed to create S3 client: %s", err)
339 } 349 }
340 350
341 if err = cgi.Serve(&handler{mc, bucket, anonUser}); err != nil { 351 if err = cgi.Serve(&handler{mc, bucket, anonUser}); err != nil {
342 die("Failed to serve CGI: %s", err) 352 die("Fatal: failed to serve CGI: %s", err)
343 } 353 }
344} 354}
345 355