From b0d099925c9a4a95bd9434181869f25d1aa90ecc Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 13 Nov 2023 02:35:45 -0800 Subject: [PATCH] Show a warning message when the credential helper invocation fails Fixes https://github.com/bazelbuild/bazel/issues/20146. PiperOrigin-RevId: 581891244 Change-Id: Ifbcdba69b731c0a4e3d8f3e45184054b4e52b62e --- .../repository/downloader/HttpConnectorMultiplexer.java | 6 ++++-- .../repository/downloader/HttpConnectorMultiplexerTest.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexer.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexer.java index b82587b5a91a0c..691f565e089168 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexer.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexer.java @@ -112,7 +112,7 @@ public HttpStream connect( baseHeaders.putAll(REQUEST_HEADERS); Function>> headerFunction = - getHeaderFunction(baseHeaders.buildKeepingLast(), credentials); + getHeaderFunction(baseHeaders.buildKeepingLast(), credentials, eventHandler); URLConnection connection = connector.connect(url, headerFunction); return httpStreamFactory.create( connection, @@ -134,7 +134,7 @@ public HttpStream connect( @VisibleForTesting static Function>> getHeaderFunction( - Map> baseHeaders, Credentials credentials) { + Map> baseHeaders, Credentials credentials, EventHandler eventHandler) { Preconditions.checkNotNull(baseHeaders); Preconditions.checkNotNull(credentials); @@ -146,6 +146,8 @@ static Function>> getHeaderFunction( // If we can't convert the URL to a URI (because it is syntactically malformed), or fetching // credentials fails for any other reason, still try to do the connection, not adding // authentication information as we cannot look it up. + eventHandler.handle( + Event.warn("Error retrieving auth headers, continuing without: " + e.getMessage())); } return ImmutableMap.copyOf(headers); }; diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java index 3ca3c8d443a79a..44a7aa863122f4 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorMultiplexerTest.java @@ -165,7 +165,7 @@ public void testHeaderComputationFunction() throws Exception { Function>> headerFunction = HttpConnectorMultiplexer.getHeaderFunction( - baseHeaders, new StaticCredentials(additionalHeaders)); + baseHeaders, new StaticCredentials(additionalHeaders), eventHandler); // Unrelated URL assertThat(headerFunction.apply(new URL("http://example.org/some/path/file.txt"))) @@ -218,7 +218,7 @@ public void testHeaderComputationFunction() throws Exception { ImmutableMap.of("Authentication", ImmutableList.of("YW5vbnltb3VzOmZvb0BleGFtcGxlLm9yZw==")); Function>> combinedHeaders = HttpConnectorMultiplexer.getHeaderFunction( - annonAuth, new StaticCredentials(additionalHeaders)); + annonAuth, new StaticCredentials(additionalHeaders), eventHandler); assertThat(combinedHeaders.apply(new URL("http://hosting.example.com/user/foo/file.txt"))) .containsExactly("Authentication", ImmutableList.of("Zm9vOmZvb3NlY3JldA==")); assertThat(combinedHeaders.apply(new URL("http://unreleated.example.org/user/foo/file.txt")))