Skip to content

Commit

Permalink
fix: include x-goog-user-project on resumable upload puts for grpc tr…
Browse files Browse the repository at this point in the history
…ansport (#2586)

In HTTP transport, gcs includes the userProject in the returned location. However, in grpc the uploadId is opaque and does not necessarily include the userProject in a client visible way. For completeness sake, include x-goog-user-project in resumable upload puts.
  • Loading branch information
BenWhitehead committed Jun 13, 2024
1 parent adc14b9 commit 6f2f504
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ public WritableByteChannelSession<?, BlobInfo> writeSession(
grpc.startResumableWrite(grpcCallContext, req);
return ResumableMedia.gapic()
.write()
.byteChannel(grpc.storageClient.writeObjectCallable())
.byteChannel(
grpc.storageClient
.writeObjectCallable()
.withDefaultCallContext(grpcCallContext))
.setHasher(Hasher.noop())
.setByteStringStrategy(ByteStringStrategy.copy())
.resumable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public GrpcBlobWriteChannel writer(BlobInfo blobInfo, BlobWriteOption... options
// 3. wrap the result in another future container before constructing the BlobWriteChannel
ApiFuture<ResumableWrite> wrapped = ApiFutures.immediateFuture(resumableWrite);
return new GrpcBlobWriteChannel(
storageClient.writeObjectCallable(),
storageClient.writeObjectCallable().withDefaultCallContext(grpcCallContext),
getOptions(),
retryAlgorithmManager.idempotent(),
() -> wrapped,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.core.InternalApi;
import com.google.api.gax.grpc.GrpcCallContext;
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.ClientStreamingCallable;
import com.google.cloud.storage.Conversions.Decoder;
import com.google.cloud.storage.RecoveryFileManager.RecoveryVolumeSinkFactory;
import com.google.cloud.storage.Storage.BlobWriteOption;
Expand All @@ -34,6 +35,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.storage.v2.ServiceConstants.Values;
import com.google.storage.v2.WriteObjectRequest;
import com.google.storage.v2.WriteObjectResponse;
import java.io.IOException;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -184,16 +186,20 @@ public WritableByteChannelSession<?, BlobInfo> writeSession(
if (storage instanceof GrpcStorageImpl) {
GrpcStorageImpl grpcStorage = (GrpcStorageImpl) storage;
RecoveryFile recoveryFile = recoveryFileManager.newRecoveryFile(info);
GrpcCallContext grpcCallContext =
opts.grpcMetadataMapper().apply(GrpcCallContext.createDefault());
ApiFuture<ResumableWrite> f =
grpcStorage.startResumableWrite(
GrpcCallContext.createDefault(), grpcStorage.getWriteObjectRequest(info, opts));
grpcCallContext, grpcStorage.getWriteObjectRequest(info, opts));
ApiFuture<WriteCtx<ResumableWrite>> start =
ApiFutures.transform(f, WriteCtx::new, MoreExecutors.directExecutor());

ClientStreamingCallable<WriteObjectRequest, WriteObjectResponse> write =
grpcStorage.storageClient.writeObjectCallable().withDefaultCallContext(grpcCallContext);
BufferedWritableByteChannelSession<WriteObjectResponse> session =
ResumableMedia.gapic()
.write()
.byteChannel(grpcStorage.storageClient.writeObjectCallable())
.byteChannel(write)
.setHasher(Hasher.noop())
.setByteStringStrategy(ByteStringStrategy.copy())
.journaling()
Expand Down

0 comments on commit 6f2f504

Please sign in to comment.