Add digest func to Remote Asset Downloader
A follow up from https://github.com/bazelbuild/remote-apis/pull/286
Closes #21996.
PiperOrigin-RevId: 628100606
Change-Id: Ib37a013d704dcfd14556f7914d90c1393ef73d38
diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
index a890127..97f9b4c 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteModule.java
@@ -716,6 +716,7 @@
Optional.ofNullable(callCredentials),
retrier,
cacheClient,
+ digestUtil.getDigestFunction(),
remoteOptions,
verboseFailures,
fallbackDownloader));
diff --git a/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java b/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java
index ed8233f..12350eb 100644
--- a/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java
+++ b/src/main/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloader.java
@@ -20,6 +20,7 @@
import build.bazel.remote.asset.v1.FetchGrpc.FetchBlockingStub;
import build.bazel.remote.asset.v1.Qualifier;
import build.bazel.remote.execution.v2.Digest;
+import build.bazel.remote.execution.v2.DigestFunction;
import build.bazel.remote.execution.v2.RequestMetadata;
import com.google.auth.Credentials;
import com.google.common.annotations.VisibleForTesting;
@@ -65,6 +66,7 @@
private final Optional<CallCredentials> credentials;
private final RemoteRetrier retrier;
private final RemoteCacheClient cacheClient;
+ private final DigestFunction.Value digestFunction;
private final RemoteOptions options;
private final boolean verboseFailures;
@Nullable private final Downloader fallbackDownloader;
@@ -89,6 +91,7 @@
Optional<CallCredentials> credentials,
RemoteRetrier retrier,
RemoteCacheClient cacheClient,
+ DigestFunction.Value digestFunction,
RemoteOptions options,
boolean verboseFailures,
@Nullable Downloader fallbackDownloader) {
@@ -98,6 +101,7 @@
this.credentials = credentials;
this.retrier = retrier;
this.cacheClient = cacheClient;
+ this.digestFunction = digestFunction;
this.options = options;
this.verboseFailures = verboseFailures;
this.fallbackDownloader = fallbackDownloader;
@@ -130,7 +134,8 @@
RemoteActionExecutionContext.create(metadata);
final FetchBlobRequest request =
- newFetchBlobRequest(options.remoteInstanceName, urls, checksum, canonicalId, headers);
+ newFetchBlobRequest(
+ options.remoteInstanceName, urls, checksum, canonicalId, digestFunction, headers);
try {
FetchBlobResponse response =
retrier.execute(
@@ -178,9 +183,12 @@
List<URL> urls,
Optional<Checksum> checksum,
String canonicalId,
+ DigestFunction.Value digestFunction,
Map<String, List<String>> headers) {
FetchBlobRequest.Builder requestBuilder =
- FetchBlobRequest.newBuilder().setInstanceName(instanceName);
+ FetchBlobRequest.newBuilder()
+ .setInstanceName(instanceName)
+ .setDigestFunction(digestFunction);
for (URL url : urls) {
requestBuilder.addUris(url.toString());
}
diff --git a/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java b/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java
index 4e58b6e..dbacc73 100644
--- a/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/remote/downloader/GrpcRemoteDownloaderTest.java
@@ -160,6 +160,7 @@
Optional.<CallCredentials>empty(),
retrier,
cacheClient,
+ DIGEST_UTIL.getDigestFunction(),
remoteOptions,
/* verboseFailures= */ false,
fallbackDownloader);
@@ -205,6 +206,7 @@
assertThat(request)
.isEqualTo(
FetchBlobRequest.newBuilder()
+ .setDigestFunction(DIGEST_UTIL.getDigestFunction())
.addUris("http://example.com/content.txt")
.build());
responseObserver.onNext(
@@ -270,6 +272,7 @@
assertThat(request)
.isEqualTo(
FetchBlobRequest.newBuilder()
+ .setDigestFunction(DIGEST_UTIL.getDigestFunction())
.addUris("http://example.com/content.txt")
.addQualifiers(
Qualifier.newBuilder()
@@ -308,6 +311,7 @@
assertThat(request)
.isEqualTo(
FetchBlobRequest.newBuilder()
+ .setDigestFunction(DIGEST_UTIL.getDigestFunction())
.addUris("http://example.com/content.txt")
.addQualifiers(
Qualifier.newBuilder()
@@ -352,6 +356,7 @@
Checksum.fromSubresourceIntegrity(
"sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=")),
"canonical ID",
+ DIGEST_UTIL.getDigestFunction(),
ImmutableMap.of(
"Authorization", ImmutableList.of("Basic Zm9vOmJhcg=="),
"X-Custom-Token", ImmutableList.of("foo", "bar")));
@@ -360,6 +365,7 @@
.isEqualTo(
FetchBlobRequest.newBuilder()
.setInstanceName("instance name")
+ .setDigestFunction(DIGEST_UTIL.getDigestFunction())
.addUris("http://example.com/a")
.addUris("http://example.com/b")
.addUris("file:/not/limited/to/http")