From a8441491a1a042c5368f4d55a81f13078ad173df Mon Sep 17 00:00:00 2001 From: Roberto D'Auria Date: Thu, 16 May 2024 06:46:14 -0400 Subject: [PATCH] Add -hostname-file flag (#65) * Update m-lab/go to v0.1.73 * Add -hostname-file flag --- go.mod | 2 +- go.sum | 4 ++-- main.go | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index e865888..40e8f11 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/go-test/deep v1.0.6 - github.com/m-lab/go v0.1.66 + github.com/m-lab/go v0.1.73 github.com/m-lab/tcp-info v1.5.3 github.com/oschwald/geoip2-golang v1.7.0 github.com/prometheus/client_golang v1.12.2 diff --git a/go.sum b/go.sum index be573c1..8b66f89 100644 --- a/go.sum +++ b/go.sum @@ -237,8 +237,8 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/m-lab/go v0.1.66 h1:adDJILqKBCkd5YeVhCrrjWkjoNRtDzlDr6uizWu5/pE= -github.com/m-lab/go v0.1.66/go.mod h1:O1D/EoVarJ8lZt9foANcqcKtwxHatBzUxXFFyC87aQQ= +github.com/m-lab/go v0.1.73 h1:vy4MRcEyvYOhfA55V6tT/NZlrfWS0qTNJktIrLaAbmw= +github.com/m-lab/go v0.1.73/go.mod h1:BirARfHWjjXHaCGNyWCm/CKW1OarjuEj8Yn6Z2rc0M4= github.com/m-lab/tcp-info v1.5.3 h1:4IspTPcNc8D8LNRvuFnID8gDiz+hxPAtYvpKZaiGGe8= github.com/m-lab/tcp-info v1.5.3/go.mod h1:bkvI4qbjB6QVC2tsLSHqf5OnIYcmuLEVjo7+8YA56Kg= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= diff --git a/main.go b/main.go index d1c7ad0..f5a8577 100644 --- a/main.go +++ b/main.go @@ -28,6 +28,7 @@ import ( var ( datadir = flag.String("datadir", ".", "The directory to put the data in") hostname = flag.String("hostname", "", "The server hostname, used to lookup server siteinfo annotations") + hostnameFile = flagx.FileBytes{} maxmindurl = flagx.URL{} routeviewv4 = flagx.URL{} routeviewv6 = flagx.URL{} @@ -49,6 +50,7 @@ var ( ) func init() { + flag.Var(&hostnameFile, "hostname-file", "The file containing the server hostname.") flag.Var(&maxmindurl, "maxmind.url", "The URL for the file containing MaxMind IP metadata. Accepted URL schemes currently are: gs://bucket/file and file:./relativepath/file") flag.Var(&routeviewv4, "routeview-v4.url", "The URL for the RouteViewIPv4 file containing ASN metadata. gs:// and file:// schemes accepted.") flag.Var(&routeviewv6, "routeview-v6.url", "The URL for the RouteViewIPv6 file containing ASN metadata. gs:// and file:// schemes accepted.") @@ -73,6 +75,12 @@ func main() { flag.Parse() rtx.Must(flagx.ArgsFromEnv(flag.CommandLine), "Could not get args from environment variables") + // If the -hostname flag was not set, try reading the hostname from the + // -hostname-file. + if hostnameFile.String() != "" && *hostname == "" { + *hostname = hostnameFile.String() + } + // Create the datatype directory immediately, since pusher will crash // without it. rtx.Must(os.MkdirAll(*datadir, 0755), "Could not create datatype dir %s", datadir) @@ -87,7 +95,7 @@ func main() { // // https://siteinfo.mlab-oti.measurementlab.net/v2/sites/annotations.json h, err := host.Parse(*hostname) - rtx.Must(err, "Failed to parse -hostname flag value") + rtx.Must(err, "Failed to parse the provided hostname") mlabHostname := h.String() defer mainCancel()