Skip to content

Commit

Permalink
Show a warning message when the credential helper invocation fails
Browse files Browse the repository at this point in the history
Fixes #20146.

PiperOrigin-RevId: 581891244
Change-Id: Ifbcdba69b731c0a4e3d8f3e45184054b4e52b62e
  • Loading branch information
Wyverald authored and bazel-io committed Jan 22, 2024
1 parent 269c70b commit 4d55e13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public HttpStream connect(
throw new InterruptedIOException();
}
Function<URL, ImmutableMap<String, List<String>>> headerFunction =
getHeaderFunction(REQUEST_HEADERS, credentials);
getHeaderFunction(REQUEST_HEADERS, credentials, eventHandler);
URLConnection connection = connector.connect(url, headerFunction);
return httpStreamFactory.create(
connection,
Expand All @@ -125,7 +125,7 @@ public HttpStream connect(

@VisibleForTesting
static Function<URL, ImmutableMap<String, List<String>>> getHeaderFunction(
Map<String, List<String>> baseHeaders, Credentials credentials) {
Map<String, List<String>> baseHeaders, Credentials credentials, EventHandler eventHandler) {
Preconditions.checkNotNull(baseHeaders);
Preconditions.checkNotNull(credentials);

Expand All @@ -137,6 +137,8 @@ static Function<URL, ImmutableMap<String, List<String>>> 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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public void testHeaderComputationFunction() throws Exception {

Function<URL, ImmutableMap<String, List<String>>> 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")))
Expand Down Expand Up @@ -218,7 +218,7 @@ public void testHeaderComputationFunction() throws Exception {
ImmutableMap.of("Authentication", ImmutableList.of("YW5vbnltb3VzOmZvb0BleGFtcGxlLm9yZw=="));
Function<URL, ImmutableMap<String, List<String>>> 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")))
Expand Down

0 comments on commit 4d55e13

Please sign in to comment.