23
23
import build .bazel .remote .execution .v2 .RequestMetadata ;
24
24
import com .google .common .annotations .VisibleForTesting ;
25
25
import com .google .common .base .Strings ;
26
- import com .google .common .collect .ImmutableSet ;
27
- import com .google .common .collect .Iterables ;
28
26
import com .google .devtools .build .lib .bazel .repository .downloader .Checksum ;
29
27
import com .google .devtools .build .lib .bazel .repository .downloader .Downloader ;
30
28
import com .google .devtools .build .lib .bazel .repository .downloader .HashOutputStream ;
38
36
import com .google .devtools .build .lib .remote .util .TracingMetadataUtils ;
39
37
import com .google .devtools .build .lib .remote .util .Utils ;
40
38
import com .google .devtools .build .lib .vfs .Path ;
41
- import com .google .gson .Gson ;
42
- import com .google .gson .JsonArray ;
43
- import com .google .gson .JsonObject ;
44
39
import io .grpc .CallCredentials ;
45
40
import io .grpc .Channel ;
46
41
import io .grpc .StatusRuntimeException ;
51
46
import java .util .List ;
52
47
import java .util .Map ;
53
48
import java .util .Optional ;
54
- import java .util .TreeMap ;
55
49
import java .util .concurrent .TimeUnit ;
56
50
import java .util .concurrent .atomic .AtomicBoolean ;
57
51
import javax .annotation .Nullable ;
@@ -82,7 +76,6 @@ public class GrpcRemoteDownloader implements AutoCloseable, Downloader {
82
76
// supported by Bazel.
83
77
private static final String QUALIFIER_CHECKSUM_SRI = "checksum.sri" ;
84
78
private static final String QUALIFIER_CANONICAL_ID = "bazel.canonical_id" ;
85
- private static final String QUALIFIER_AUTH_HEADERS = "bazel.auth_headers" ;
86
79
87
80
public GrpcRemoteDownloader (
88
81
String buildRequestId ,
@@ -131,13 +124,7 @@ public void download(
131
124
RemoteActionExecutionContext .create (metadata );
132
125
133
126
final FetchBlobRequest request =
134
- newFetchBlobRequest (
135
- options .remoteInstanceName ,
136
- urls ,
137
- authHeaders ,
138
- checksum ,
139
- canonicalId ,
140
- options .remoteDownloaderSendAllHeaders );
127
+ newFetchBlobRequest (options .remoteInstanceName , urls , checksum , canonicalId );
141
128
try {
142
129
FetchBlobResponse response =
143
130
retrier .execute (
@@ -175,10 +162,8 @@ public void download(
175
162
static FetchBlobRequest newFetchBlobRequest (
176
163
String instanceName ,
177
164
List <URL > urls ,
178
- Map <URI , Map <String , List <String >>> authHeaders ,
179
165
com .google .common .base .Optional <Checksum > checksum ,
180
- String canonicalId ,
181
- boolean includeAllHeaders ) {
166
+ String canonicalId ) {
182
167
FetchBlobRequest .Builder requestBuilder =
183
168
FetchBlobRequest .newBuilder ().setInstanceName (instanceName );
184
169
for (URL url : urls ) {
@@ -195,13 +180,6 @@ static FetchBlobRequest newFetchBlobRequest(
195
180
requestBuilder .addQualifiers (
196
181
Qualifier .newBuilder ().setName (QUALIFIER_CANONICAL_ID ).setValue (canonicalId ).build ());
197
182
}
198
- if (!authHeaders .isEmpty ()) {
199
- requestBuilder .addQualifiers (
200
- Qualifier .newBuilder ()
201
- .setName (QUALIFIER_AUTH_HEADERS )
202
- .setValue (authHeadersJson (urls , authHeaders , includeAllHeaders ))
203
- .build ());
204
- }
205
183
206
184
return requestBuilder .build ();
207
185
}
@@ -224,43 +202,4 @@ private OutputStream newOutputStream(
224
202
}
225
203
return out ;
226
204
}
227
-
228
- private static String authHeadersJson (
229
- List <URL > urls , Map <URI , Map <String , List <String >>> authHeaders , boolean includeAllHeaders ) {
230
- ImmutableSet <String > hostSet =
231
- urls .stream ().map (URL ::getHost ).collect (ImmutableSet .toImmutableSet ());
232
- Map <String , JsonObject > subObjects = new TreeMap <>();
233
- for (Map .Entry <URI , Map <String , List <String >>> entry : authHeaders .entrySet ()) {
234
- URI uri = entry .getKey ();
235
- // Only add headers that are relevant to the hosts.
236
- if (!hostSet .contains (uri .getHost ())) {
237
- continue ;
238
- }
239
-
240
- JsonObject subObject = new JsonObject ();
241
- Map <String , List <String >> orderedHeaders = new TreeMap <>(entry .getValue ());
242
- for (Map .Entry <String , List <String >> subEntry : orderedHeaders .entrySet ()) {
243
- if (includeAllHeaders ) {
244
- JsonArray values = new JsonArray (subEntry .getValue ().size ());
245
- for (String value : subEntry .getValue ()) {
246
- values .add (value );
247
- }
248
- subObject .add (subEntry .getKey (), values );
249
- } else {
250
- String value = Iterables .getFirst (subEntry .getValue (), null );
251
- if (value != null ) {
252
- subObject .addProperty (subEntry .getKey (), value );
253
- }
254
- }
255
- }
256
- subObjects .put (uri .toString (), subObject );
257
- }
258
-
259
- JsonObject authHeadersJson = new JsonObject ();
260
- for (Map .Entry <String , JsonObject > entry : subObjects .entrySet ()) {
261
- authHeadersJson .add (entry .getKey (), entry .getValue ());
262
- }
263
-
264
- return new Gson ().toJson (authHeadersJson );
265
- }
266
205
}
0 commit comments