From 311f4d4b23cf34a386b733a73e18426ac92a8999 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Wed, 3 Sep 2025 15:26:10 +0200 Subject: [PATCH 01/13] Read secret from env var --- .../commands/DownloadIpInfoSiteCommand.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 678a409..b18791b 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -6,16 +6,24 @@ import technology.dice.dicewhere.downloader.actions.DownloadExecutionResult; import technology.dice.dicewhere.downloader.actions.ipinfo.DownloadIpInfoSite; +import java.util.Optional; + @Command( name = "ipinfo-site", description = "Downloads the selected IpInfo dataset from IpInfo's website") public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Option( names = {"-t", "--token"}, - required = true, + required = false, description = "The ipinfo download key") String token; + @Option(names = {"-k", "--api-key"}, + required = false, + defaultValue = "${env:API_KEY}", + description = "API key") + private String apiKey; + @Parameters( index = "0", description = @@ -24,8 +32,12 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Override public DownloadExecutionResult execute() { + String secretToken = Optional.of(apiKey) + .or(() -> Optional.of(token)) + .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); + return new DownloadIpInfoSite( - noCheckMd5, overwrite, verbose, dataset, format, token, destination) - .execute(); + noCheckMd5, overwrite, verbose, dataset, format, secretToken, destination) + .execute(); } } From 8b730abd3e5fa629a875eb2f6c76eb8633d48117 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Wed, 3 Sep 2025 15:29:05 +0200 Subject: [PATCH 02/13] Read secret from env var --- .../commands/DownloadIpInfoSiteCommand.java | 4 ++-- .../commands/DownloadMaxmindSiteCommand.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index b18791b..3c06bfb 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -18,10 +18,10 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { description = "The ipinfo download key") String token; - @Option(names = {"-k", "--api-key"}, + @Option(names = {"-ak", "--api-key"}, required = false, defaultValue = "${env:API_KEY}", - description = "API key") + description = "The ipinfo download key (env var)") private String apiKey; @Parameters( diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 9c13dfa..24bce27 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -6,6 +6,8 @@ import technology.dice.dicewhere.downloader.actions.DownloadExecutionResult; import technology.dice.dicewhere.downloader.actions.maxmind.DownloadMaxmindSite; +import java.util.Optional; + @Command( name = "maxmind-site", description = "Downloads the selected Maxmind edition of a database from Maxmind's website") @@ -17,6 +19,12 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { description = "The maxmind download key") String key; + @Option(names = {"-ak", "--api-key"}, + required = false, + defaultValue = "${env:API_KEY}", + description = "The maxmind download key (env var)") + private String apiKey; + @Parameters( index = "0", description = @@ -25,8 +33,12 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Override public DownloadExecutionResult execute() { + String secretToken = Optional.of(apiKey) + .or(() -> Optional.of(key)) + .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); + return new DownloadMaxmindSite( - noCheckMd5, overwrite, verbose, edition, database, format, key, destination) + noCheckMd5, overwrite, verbose, edition, database, format, secretToken, destination) .execute(); } } From 3d4307102df399c98fdca7ce85aee793764179a4 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Wed, 10 Sep 2025 13:52:30 +0200 Subject: [PATCH 03/13] rename api keys env vars --- .../downloader/picocli/commands/DownloadIpInfoSiteCommand.java | 2 +- .../downloader/picocli/commands/DownloadMaxmindSiteCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 3c06bfb..ad40a8c 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -20,7 +20,7 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Option(names = {"-ak", "--api-key"}, required = false, - defaultValue = "${env:API_KEY}", + defaultValue = "${env:IPINFO_API_KEY}", description = "The ipinfo download key (env var)") private String apiKey; diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 24bce27..c038e68 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -21,7 +21,7 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Option(names = {"-ak", "--api-key"}, required = false, - defaultValue = "${env:API_KEY}", + defaultValue = "${env:MAXMIND_API_KEY}", description = "The maxmind download key (env var)") private String apiKey; From c29b84b48523af9cd29e1f06dda9a80555975987 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Wed, 10 Sep 2025 16:19:03 +0200 Subject: [PATCH 04/13] test env vars --- .../picocli/commands/DownloadIpInfoSiteCommand.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index ad40a8c..328a1b7 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -1,5 +1,7 @@ package technology.dice.dicewhere.downloader.picocli.commands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -12,6 +14,8 @@ name = "ipinfo-site", description = "Downloads the selected IpInfo dataset from IpInfo's website") public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { + + private static final Logger LOG = LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); @Option( names = {"-t", "--token"}, required = false, @@ -33,7 +37,14 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Override public DownloadExecutionResult execute() { String secretToken = Optional.of(apiKey) - .or(() -> Optional.of(token)) + .map(v -> { + LOG.info("-ak param used"); + return v; + }) + .or(() -> { + LOG.info("-t param used"); + return Optional.of(token); + }) .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); return new DownloadIpInfoSite( From 5351691df86b12f776dc55fe51c610627fe57da8 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Wed, 10 Sep 2025 16:44:18 +0200 Subject: [PATCH 05/13] use env var with system.getenv --- .../commands/DownloadIpInfoSiteCommand.java | 15 ++++----------- .../commands/DownloadMaxmindSiteCommand.java | 10 +++------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 328a1b7..5081a8e 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -16,18 +16,14 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { private static final Logger LOG = LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); + + private static final String ENV_VAR_API_KEY = "IPINFO_API_KEY"; @Option( names = {"-t", "--token"}, required = false, description = "The ipinfo download key") String token; - @Option(names = {"-ak", "--api-key"}, - required = false, - defaultValue = "${env:IPINFO_API_KEY}", - description = "The ipinfo download key (env var)") - private String apiKey; - @Parameters( index = "0", description = @@ -36,15 +32,12 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Override public DownloadExecutionResult execute() { - String secretToken = Optional.of(apiKey) + String secretToken = Optional.of(System.getenv(ENV_VAR_API_KEY)) .map(v -> { LOG.info("-ak param used"); return v; }) - .or(() -> { - LOG.info("-t param used"); - return Optional.of(token); - }) + .or(() -> Optional.of(token)) .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); return new DownloadIpInfoSite( diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index c038e68..c2de57c 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -13,18 +13,14 @@ description = "Downloads the selected Maxmind edition of a database from Maxmind's website") public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { + private static final String ENV_VAR_API_KEY = "MAXMIND_API_KEY"; + @Option( names = {"-k", "--key"}, required = true, description = "The maxmind download key") String key; - @Option(names = {"-ak", "--api-key"}, - required = false, - defaultValue = "${env:MAXMIND_API_KEY}", - description = "The maxmind download key (env var)") - private String apiKey; - @Parameters( index = "0", description = @@ -33,7 +29,7 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Override public DownloadExecutionResult execute() { - String secretToken = Optional.of(apiKey) + String secretToken = Optional.of(System.getenv(ENV_VAR_API_KEY)) .or(() -> Optional.of(key)) .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); From 17c3a19fca36bb3a6b4086985f27cd263213ce4c Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Wed, 10 Sep 2025 16:45:49 +0200 Subject: [PATCH 06/13] use env var with system.getenv --- .../picocli/commands/DownloadIpInfoSiteCommand.java | 2 +- .../picocli/commands/DownloadMaxmindSiteCommand.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 5081a8e..9966776 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -38,7 +38,7 @@ public DownloadExecutionResult execute() { return v; }) .or(() -> Optional.of(token)) - .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); + .orElseThrow(() -> new IllegalStateException("Token param or api key env var should be provided")); return new DownloadIpInfoSite( noCheckMd5, overwrite, verbose, dataset, format, secretToken, destination) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index c2de57c..38d51de 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -17,7 +17,7 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Option( names = {"-k", "--key"}, - required = true, + required = false, description = "The maxmind download key") String key; @@ -31,7 +31,7 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { public DownloadExecutionResult execute() { String secretToken = Optional.of(System.getenv(ENV_VAR_API_KEY)) .or(() -> Optional.of(key)) - .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); + .orElseThrow(() -> new IllegalStateException("Token param or api key env var should be provided")); return new DownloadMaxmindSite( noCheckMd5, overwrite, verbose, edition, database, format, secretToken, destination) From e609b3f8fbf8c3e39b4bf043df9cbe4f66e2230d Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Thu, 11 Sep 2025 09:29:42 +0200 Subject: [PATCH 07/13] add env variable to read from --- .../commands/DownloadIpInfoSiteCommand.java | 20 ++++++++----------- .../commands/DownloadMaxmindSiteCommand.java | 19 ++++++++++-------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 9966776..cef387c 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -1,7 +1,5 @@ package technology.dice.dicewhere.downloader.picocli.commands; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -15,15 +13,17 @@ description = "Downloads the selected IpInfo dataset from IpInfo's website") public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { - private static final Logger LOG = LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); - - private static final String ENV_VAR_API_KEY = "IPINFO_API_KEY"; @Option( names = {"-t", "--token"}, required = false, description = "The ipinfo download key") String token; + @Option(names = "--token:env", + required = false, + description = "The ipinfo download key env variable") + private String tokenEnvVariable; + @Parameters( index = "0", description = @@ -32,13 +32,9 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Override public DownloadExecutionResult execute() { - String secretToken = Optional.of(System.getenv(ENV_VAR_API_KEY)) - .map(v -> { - LOG.info("-ak param used"); - return v; - }) - .or(() -> Optional.of(token)) - .orElseThrow(() -> new IllegalStateException("Token param or api key env var should be provided")); + var secretToken = Optional.ofNullable(token) + .or(() -> Optional.ofNullable(System.getenv(tokenEnvVariable))) + .orElseThrow(() -> new IllegalStateException("Token param or api key env var should be provided")); return new DownloadIpInfoSite( noCheckMd5, overwrite, verbose, dataset, format, secretToken, destination) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 38d51de..7bbca96 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -13,14 +13,17 @@ description = "Downloads the selected Maxmind edition of a database from Maxmind's website") public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { - private static final String ENV_VAR_API_KEY = "MAXMIND_API_KEY"; - @Option( - names = {"-k", "--key"}, - required = false, - description = "The maxmind download key") + names = {"-k", "--key"}, + required = false, + description = "The maxmind download key") String key; + @Option(names = "--key:env", + required = false, + description = "The maxmind download key env variable") + String keyEnvVariable; + @Parameters( index = "0", description = @@ -29,9 +32,9 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Override public DownloadExecutionResult execute() { - String secretToken = Optional.of(System.getenv(ENV_VAR_API_KEY)) - .or(() -> Optional.of(key)) - .orElseThrow(() -> new IllegalStateException("Token param or api key env var should be provided")); + var secretToken = Optional.ofNullable(key) + .or(() -> Optional.ofNullable(System.getenv(keyEnvVariable))) + .orElseThrow(() -> new IllegalStateException("Key param or api key env var should be provided")); return new DownloadMaxmindSite( noCheckMd5, overwrite, verbose, edition, database, format, secretToken, destination) From 99a6ba2ce0266aa458aa41efc66f83a2515c0f52 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Thu, 11 Sep 2025 16:07:05 +0200 Subject: [PATCH 08/13] add env variable to read from --- .../commands/DownloadIpInfoSiteCommand.java | 15 ++++++++------- .../commands/DownloadMaxmindSiteCommand.java | 13 +++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index cef387c..590631d 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -19,10 +19,11 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { description = "The ipinfo download key") String token; - @Option(names = "--token:env", - required = false, - description = "The ipinfo download key env variable") - private String tokenEnvVariable; + @Option(names = {"-ak", "--api-key"}, + required = false, + defaultValue = "${env:API_KEY}", + description = "The ipinfo download key (env var)") + private String apiKey; @Parameters( index = "0", @@ -32,9 +33,9 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Override public DownloadExecutionResult execute() { - var secretToken = Optional.ofNullable(token) - .or(() -> Optional.ofNullable(System.getenv(tokenEnvVariable))) - .orElseThrow(() -> new IllegalStateException("Token param or api key env var should be provided")); + String secretToken = Optional.of(apiKey) + .or(() -> Optional.of(token)) + .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); return new DownloadIpInfoSite( noCheckMd5, overwrite, verbose, dataset, format, secretToken, destination) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 7bbca96..8b2b0a0 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -19,10 +19,11 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { description = "The maxmind download key") String key; - @Option(names = "--key:env", + @Option(names = {"-ak", "--api-key"}, required = false, - description = "The maxmind download key env variable") - String keyEnvVariable; + defaultValue = "${env:API_KEY}", + description = "The maxmind download key (env var)") + private String apiKey; @Parameters( index = "0", @@ -32,9 +33,9 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Override public DownloadExecutionResult execute() { - var secretToken = Optional.ofNullable(key) - .or(() -> Optional.ofNullable(System.getenv(keyEnvVariable))) - .orElseThrow(() -> new IllegalStateException("Key param or api key env var should be provided")); + String secretToken = Optional.of(apiKey) + .or(() -> Optional.of(key)) + .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); return new DownloadMaxmindSite( noCheckMd5, overwrite, verbose, edition, database, format, secretToken, destination) From 9a0ecf8e547c5f55c8ff8209c283c01bf5e26f4f Mon Sep 17 00:00:00 2001 From: skurtEnd Date: Thu, 11 Sep 2025 18:12:31 +0300 Subject: [PATCH 09/13] use env var from SM --- .../source/ipinfosite/IpInfoSiteSource.java | 2 +- .../source/maxmindsite/MaxmindSiteSource.java | 2 +- .../commands/DownloadIpInfoSiteCommand.java | 22 +++++++----------- .../commands/DownloadMaxmindSiteCommand.java | 23 ++++++++----------- 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/ipinfosite/IpInfoSiteSource.java b/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/ipinfosite/IpInfoSiteSource.java index bce3e60..17cd7c7 100644 --- a/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/ipinfosite/IpInfoSiteSource.java +++ b/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/ipinfosite/IpInfoSiteSource.java @@ -33,7 +33,7 @@ public FileInfo fileInfo() { dataConnection.setRequestMethod("HEAD"); if (dataConnection.getResponseCode() > 299 || dataConnection.getResponseCode() < 200) { - throw new DownloaderException("Could not find remote file"); + throw new DownloaderException("Could not find remote file " + dataConnection.getResponseCode()); } long fileSize = dataConnection.getContentLengthLong(); diff --git a/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/maxmindsite/MaxmindSiteSource.java b/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/maxmindsite/MaxmindSiteSource.java index 7d01f0a..9f1f7f4 100644 --- a/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/maxmindsite/MaxmindSiteSource.java +++ b/dice-where-downloader-lib/src/main/java/technology/dice/dicewhere/downloader/source/maxmindsite/MaxmindSiteSource.java @@ -33,7 +33,7 @@ public synchronized FileInfo fileInfo() { dataConnection.setRequestMethod("HEAD"); if (dataConnection.getResponseCode() > 299 || dataConnection.getResponseCode() < 200) { - throw new DownloaderException("Could not find remote file"); + throw new DownloaderException("Could not find remote file " + dataConnection.getResponseCode()); } long fileSize = dataConnection.getContentLengthLong(); diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 590631d..2805dc4 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -1,5 +1,7 @@ package technology.dice.dicewhere.downloader.picocli.commands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -12,19 +14,15 @@ name = "ipinfo-site", description = "Downloads the selected IpInfo dataset from IpInfo's website") public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { + private static final Logger LOG = LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); @Option( - names = {"-t", "--token"}, - required = false, - description = "The ipinfo download key") + names = {"-t", "--token"}, + required = false, + defaultValue = "${env:IPINFO_API_KEY}", + description = "The ipinfo download key") String token; - @Option(names = {"-ak", "--api-key"}, - required = false, - defaultValue = "${env:API_KEY}", - description = "The ipinfo download key (env var)") - private String apiKey; - @Parameters( index = "0", description = @@ -33,12 +31,8 @@ public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { @Override public DownloadExecutionResult execute() { - String secretToken = Optional.of(apiKey) - .or(() -> Optional.of(token)) - .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); - return new DownloadIpInfoSite( - noCheckMd5, overwrite, verbose, dataset, format, secretToken, destination) + noCheckMd5, overwrite, verbose, dataset, format, token, destination) .execute(); } } diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 8b2b0a0..337abd3 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -1,5 +1,7 @@ package technology.dice.dicewhere.downloader.picocli.commands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -13,18 +15,15 @@ description = "Downloads the selected Maxmind edition of a database from Maxmind's website") public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { + private static final Logger LOG = LoggerFactory.getLogger(DownloadMaxmindSiteCommand.class); + @Option( - names = {"-k", "--key"}, - required = false, - description = "The maxmind download key") + names = {"-k", "--key"}, + required = false, + defaultValue = "${env:MAXMIND_API_KEY}", + description = "The maxmind download key") String key; - @Option(names = {"-ak", "--api-key"}, - required = false, - defaultValue = "${env:API_KEY}", - description = "The maxmind download key (env var)") - private String apiKey; - @Parameters( index = "0", description = @@ -33,12 +32,8 @@ public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { @Override public DownloadExecutionResult execute() { - String secretToken = Optional.of(apiKey) - .or(() -> Optional.of(key)) - .orElseThrow(() -> new IllegalStateException("Token or api key parameters should be provided")); - return new DownloadMaxmindSite( - noCheckMd5, overwrite, verbose, edition, database, format, secretToken, destination) + noCheckMd5, overwrite, verbose, edition, database, format, key, destination) .execute(); } } From 3d322d59ec3b5293f4c8a80d766ce04a0b86446f Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Thu, 11 Sep 2025 17:21:41 +0200 Subject: [PATCH 10/13] add env variable to read from --- .../picocli/commands/DownloadIpInfoSiteCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 2805dc4..0461ac1 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -14,9 +14,11 @@ name = "ipinfo-site", description = "Downloads the selected IpInfo dataset from IpInfo's website") public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { - private static final Logger LOG = LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); + static { + LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); + } - @Option( + @Option( names = {"-t", "--token"}, required = false, defaultValue = "${env:IPINFO_API_KEY}", From 54b47e60e273be1463d39b0a23c00fdf96bdc924 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Thu, 11 Sep 2025 17:22:19 +0200 Subject: [PATCH 11/13] add env variable to read from --- .../picocli/commands/DownloadIpInfoSiteCommand.java | 1 - .../picocli/commands/DownloadMaxmindSiteCommand.java | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 0461ac1..6721176 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -1,6 +1,5 @@ package technology.dice.dicewhere.downloader.picocli.commands; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 337abd3..84132d7 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -1,6 +1,5 @@ package technology.dice.dicewhere.downloader.picocli.commands; -import org.slf4j.Logger; import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; @@ -15,9 +14,11 @@ description = "Downloads the selected Maxmind edition of a database from Maxmind's website") public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { - private static final Logger LOG = LoggerFactory.getLogger(DownloadMaxmindSiteCommand.class); + static { + LoggerFactory.getLogger(DownloadMaxmindSiteCommand.class); + } - @Option( + @Option( names = {"-k", "--key"}, required = false, defaultValue = "${env:MAXMIND_API_KEY}", From 77896cd6fc22e840f805ab601a3dff5abd54c83c Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Thu, 11 Sep 2025 17:23:09 +0200 Subject: [PATCH 12/13] remove unused code --- .../downloader/picocli/commands/DownloadIpInfoSiteCommand.java | 2 -- .../downloader/picocli/commands/DownloadMaxmindSiteCommand.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 6721176..9faea02 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -7,8 +7,6 @@ import technology.dice.dicewhere.downloader.actions.DownloadExecutionResult; import technology.dice.dicewhere.downloader.actions.ipinfo.DownloadIpInfoSite; -import java.util.Optional; - @Command( name = "ipinfo-site", description = "Downloads the selected IpInfo dataset from IpInfo's website") diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index 84132d7..c66e61b 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -7,8 +7,6 @@ import technology.dice.dicewhere.downloader.actions.DownloadExecutionResult; import technology.dice.dicewhere.downloader.actions.maxmind.DownloadMaxmindSite; -import java.util.Optional; - @Command( name = "maxmind-site", description = "Downloads the selected Maxmind edition of a database from Maxmind's website") From 26c1e61ee6f4fd47027e4fc7e1da4a4da08dd403 Mon Sep 17 00:00:00 2001 From: Weronika Majewska Date: Thu, 11 Sep 2025 17:36:40 +0200 Subject: [PATCH 13/13] remove unused code --- .../picocli/commands/DownloadIpInfoSiteCommand.java | 4 ---- .../picocli/commands/DownloadMaxmindSiteCommand.java | 5 ----- 2 files changed, 9 deletions(-) diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java index 9faea02..f7f2e49 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadIpInfoSiteCommand.java @@ -1,6 +1,5 @@ package technology.dice.dicewhere.downloader.picocli.commands; -import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -11,9 +10,6 @@ name = "ipinfo-site", description = "Downloads the selected IpInfo dataset from IpInfo's website") public class DownloadIpInfoSiteCommand extends IpInfoBaseCommand { - static { - LoggerFactory.getLogger(DownloadIpInfoSiteCommand.class); - } @Option( names = {"-t", "--token"}, diff --git a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java index c66e61b..e1619f9 100644 --- a/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java +++ b/dice-where-downloader/src/main/java/technology/dice/dicewhere/downloader/picocli/commands/DownloadMaxmindSiteCommand.java @@ -1,6 +1,5 @@ package technology.dice.dicewhere.downloader.picocli.commands; -import org.slf4j.LoggerFactory; import picocli.CommandLine.Command; import picocli.CommandLine.Option; import picocli.CommandLine.Parameters; @@ -12,10 +11,6 @@ description = "Downloads the selected Maxmind edition of a database from Maxmind's website") public class DownloadMaxmindSiteCommand extends MaxmindBaseCommand { - static { - LoggerFactory.getLogger(DownloadMaxmindSiteCommand.class); - } - @Option( names = {"-k", "--key"}, required = false,