From 38269c66aea584721e1291b90ed50d9b5aa4d188 Mon Sep 17 00:00:00 2001 From: Catherine Date: Mon, 22 Sep 2025 21:33:23 +0000 Subject: [PATCH] Add `-get-blob` mode, printing contents of a blob. --- src/main.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main.go b/src/main.go index 2f7cf87..03dad24 100644 --- a/src/main.go +++ b/src/main.go @@ -3,10 +3,12 @@ package main import ( "flag" "fmt" + "io" "log" "log/slog" "net" "net/http" + "os" "runtime/debug" "strings" @@ -74,11 +76,17 @@ func main() { printConfig := flag.Bool("print-config", false, "print configuration as JSON and exit") configTomlPath := flag.String("config", "config.toml", - "set path to configuration file") + "load configuration from `filename`") getManifest := flag.String("get-manifest", "", - "retrieve manifest for web root as ProtoJSON") + "write manifest for `webroot` (either 'domain.tld' or 'domain.tld/dir') to stdout as ProtoJSON") + getBlob := flag.String("get-blob", "", + "write `blob` ('sha256-xxxxxxx...xxx') to stdout") flag.Parse() + if *getManifest != "" && *getBlob != "" { + log.Fatalln("-get-manifest and -get-blob are mutually exclusive") + } + if *printConfigEnvVars { PrintConfigEnvVars() return @@ -124,7 +132,8 @@ func main() { log.Println("memlimit: was", memlimitBefore.HR(), "now", memlimitAfter.HR()) } - if *getManifest != "" { + switch { + case *getManifest != "": if err := ConfigureBackend(&config.Storage); err != nil { log.Fatalln(err) } @@ -139,7 +148,20 @@ func main() { log.Fatalln(err) } fmt.Println(ManifestDebugJSON(manifest)) - } else { + + case *getBlob != "": + if err := ConfigureBackend(&config.Storage); err != nil { + log.Fatalln(err) + } + + reader, _, err := backend.GetBlob(*getBlob) + if err != nil { + log.Fatalln(err) + } + + io.Copy(os.Stdout, reader) + + default: // Start listening on all ports before initializing the backend, otherwise if the backend // spends some time initializing (which the S3 backend does) a proxy like Caddy can race // with git-pages on startup and return errors for requests that would have been served