From 216f45d5debed006c9e69d6e979cc21c7392fbd5 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 28 Mar 2022 14:37:15 +0200 Subject: Add proxy option to vespa-feed-client --- .../java/ai/vespa/feed/client/impl/CliArguments.java | 17 +++++++++++++++++ .../main/java/ai/vespa/feed/client/impl/CliClient.java | 1 + .../ai/vespa/feed/client/impl/CliArgumentsTest.java | 9 ++++++--- vespa-feed-client-cli/src/test/resources/help.txt | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) (limited to 'vespa-feed-client-cli/src') diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java index ac859359bfa..e024f961e26 100644 --- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java +++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliArguments.java @@ -55,6 +55,7 @@ class CliArguments { private static final String VERSION_OPTION = "version"; private static final String STDIN_OPTION = "stdin"; private static final String DOOM_OPTION = "max-failure-seconds"; + private static final String PROXY_OPTION = "proxy"; private final CommandLine arguments; @@ -165,6 +166,16 @@ class CliArguments { boolean dryrunEnabled() { return has(DRYRUN_OPTION); } + Optional proxy() throws CliArgumentsException { + try { + URL url = (URL) arguments.getParsedOptionValue(PROXY_OPTION); + if (url == null) return Optional.empty(); + return Optional.of(url.toURI()); + } catch (ParseException | URISyntaxException e) { + throw new CliArgumentsException("Invalid proxy: " + e.getMessage(), e); + } + } + private OptionalInt intValue(String option) throws CliArgumentsException { try { Number number = (Number) arguments.getParsedOptionValue(option); @@ -310,6 +321,12 @@ class CliArguments { .addOption(Option.builder() .longOpt(SHOW_ALL_OPTION) .desc("Print the result of every feed operation") + .build()) + .addOption(Option.builder() + .longOpt(PROXY_OPTION) + .desc("URI to proxy endpoint") + .hasArg() + .type(URL.class) .build()); } diff --git a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java index 5e904b37588..68b9cf6af0e 100644 --- a/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java +++ b/vespa-feed-client-cli/src/main/java/ai/vespa/feed/client/impl/CliClient.java @@ -138,6 +138,7 @@ public class CliClient { builder.setDryrun(cliArgs.dryrunEnabled()); cliArgs.doomSeconds().ifPresent(doom -> builder.setCircuitBreaker(new GracePeriodCircuitBreaker(Duration.ofSeconds(10), Duration.ofSeconds(doom)))); + cliArgs.proxy().ifPresent(builder::setProxy); return builder.build(); } diff --git a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java index fe3dc465814..201a85ed09d 100644 --- a/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java +++ b/vespa-feed-client-cli/src/test/java/ai/vespa/feed/client/impl/CliArgumentsTest.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.feed.client.impl; -import ai.vespa.feed.client.impl.CliArguments; import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; @@ -11,7 +10,10 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.time.Duration; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author bjorncs @@ -26,7 +28,7 @@ class CliArgumentsTest { "--ca-certificates=ca-certs.pem", "--disable-ssl-hostname-verification", "--header=\"My-Header: my-value\"", "--header", "Another-Header: another-value", "--benchmark", "--route=myroute", "--timeout=0.125", "--trace=9", "--verbose", "--silent", - "--show-errors", "--show-all", "--max-failure-seconds=30"}); + "--show-errors", "--show-all", "--max-failure-seconds=30", "--proxy", "https://myproxy:1234"}); assertEquals(URI.create("https://vespa.ai:4443/"), args.endpoint()); assertEquals(Paths.get("feed.json"), args.inputFile().get()); assertEquals(10, args.connections().getAsInt()); @@ -49,6 +51,7 @@ class CliArgumentsTest { assertTrue(args.showErrors()); assertTrue(args.showSuccesses()); assertFalse(args.showProgress()); + assertEquals(URI.create("https://myproxy:1234"), args.proxy().orElse(null)); } @Test diff --git a/vespa-feed-client-cli/src/test/resources/help.txt b/vespa-feed-client-cli/src/test/resources/help.txt index 323206ab128..66d7c3521c2 100644 --- a/vespa-feed-client-cli/src/test/resources/help.txt +++ b/vespa-feed-client-cli/src/test/resources/help.txt @@ -25,6 +25,7 @@ Vespa feed client streams per HTTP/2 connection --private-key Path to PEM/PKCS#8 encoded private key file + --proxy URI to proxy endpoint --route Target Vespa route for feed operations --show-all Print the result of every feed -- cgit v1.2.3