From fc73a7f85e99028066adc98192dc113551e1c51e Mon Sep 17 00:00:00 2001 From: Tim de Boer Date: Thu, 26 Sep 2024 22:55:45 +0200 Subject: [PATCH 1/3] Added Envirnoment variabel for the --cache flag (STAYRTR_CACHE) --- cmd/stayrtr/stayrtr.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index ce030f7..4092fec 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -31,9 +31,12 @@ import ( ) const ( + ENV_CACHE = "STAYRTR_CACHE" ENV_SSH_PASSWORD = "STAYRTR_SSH_PASSWORD" ENV_SSH_KEY = "STAYRTR_SSH_AUTHORIZEDKEYS" + DEFAULT_CACHE = "https://console.rpki-client.org/rpki.json" + METHOD_NONE = iota METHOD_PASSWORD METHOD_KEY @@ -80,7 +83,7 @@ var ( TimeCheck = flag.Bool("checktime", true, "Check if JSON file isn't stale (disable by passing -checktime=false)") - CacheBin = flag.String("cache", "https://console.rpki-client.org/rpki.json", "URL of the Validated RPKI data in JSON format") + CacheBin = flag.String("cache", DEFAULT_CACHE, fmt.Sprintf("URL of the Validated RPKI data in JSON format", ENV_CACHE)) Etag = flag.Bool("etag", true, "Control usage of Etag header (disable with -etag=false)") LastModified = flag.Bool("last.modified", true, "Control usage of Last-Modified header (disable with -last.modified=false)") @@ -756,6 +759,11 @@ func run() error { s.fetchConfig.EnableEtags = *Etag s.fetchConfig.EnableLastModified = *LastModified + cache := *CacheBin + if cache == DEFAULT_CACHE { + cache = os.Getenv(ENV_CACHE) + } + if enableHTTP { if *ExportPath != "" { http.HandleFunc(*ExportPath, s.exporter) From 7fc4d0999f609a7fa4607fc6c86e00e4b95ced8c Mon Sep 17 00:00:00 2001 From: Tim de Boer Date: Thu, 26 Sep 2024 23:28:50 +0200 Subject: [PATCH 2/3] Forgot the formatting variable --- cmd/stayrtr/stayrtr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 4092fec..07b4b8b 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -83,7 +83,7 @@ var ( TimeCheck = flag.Bool("checktime", true, "Check if JSON file isn't stale (disable by passing -checktime=false)") - CacheBin = flag.String("cache", DEFAULT_CACHE, fmt.Sprintf("URL of the Validated RPKI data in JSON format", ENV_CACHE)) + CacheBin = flag.String("cache", DEFAULT_CACHE, fmt.Sprintf("URL of the Validated RPKI data in JSON format (if blank, will use envvar %v"", ENV_CACHE)) Etag = flag.Bool("etag", true, "Control usage of Etag header (disable with -etag=false)") LastModified = flag.Bool("last.modified", true, "Control usage of Last-Modified header (disable with -last.modified=false)") From 69f30aa8ad140b72af63349bd832926db88c7cca Mon Sep 17 00:00:00 2001 From: Tim de Boer Date: Fri, 27 Sep 2024 14:21:59 +0200 Subject: [PATCH 3/3] Better default behaviour --- cmd/stayrtr/stayrtr.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 07b4b8b..fbb81cc 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -759,9 +759,8 @@ func run() error { s.fetchConfig.EnableEtags = *Etag s.fetchConfig.EnableLastModified = *LastModified - cache := *CacheBin - if cache == DEFAULT_CACHE { - cache = os.Getenv(ENV_CACHE) + if *CacheBin == DEFAULT_CACHE && os.Getenv(ENV_CACHE) != "" { + *CacheBin = os.Getenv(ENV_CACHE) } if enableHTTP {