|
21 | 21 | import static com.google.cloud.storage.Utils.ifNonNull;
|
22 | 22 | import static com.google.cloud.storage.Utils.lift;
|
23 | 23 | import static com.google.cloud.storage.Utils.nullableDateTimeCodec;
|
| 24 | +import static com.google.cloud.storage.Utils.projectNameCodec; |
24 | 25 | import static com.google.common.base.MoreObjects.firstNonNull;
|
25 | 26 |
|
26 | 27 | import com.google.api.client.util.Data;
|
|
84 | 85 | @InternalApi
|
85 | 86 | final class ApiaryConversions {
|
86 | 87 | static final ApiaryConversions INSTANCE = new ApiaryConversions();
|
| 88 | + // gRPC has a Bucket.project property that apiary doesn't have yet. |
| 89 | + // when converting from gRPC to apiary or vice-versa we want to preserve this property. Until |
| 90 | + // such a time as the apiary model has a project field, we manually apply it with this name. |
| 91 | + private static final String PROJECT_ID_FIELD_NAME = "x_project"; |
87 | 92 |
|
88 | 93 | private final Codec<Entity, String> entityCodec =
|
89 | 94 | Codec.of(this::entityEncode, this::entityDecode);
|
@@ -323,6 +328,7 @@ private CustomerEncryption customerEncryptionDecode(StorageObject.CustomerEncryp
|
323 | 328 |
|
324 | 329 | private Bucket bucketInfoEncode(BucketInfo from) {
|
325 | 330 | Bucket to = new Bucket();
|
| 331 | + ifNonNull(from.getProject(), projectNameCodec::encode, p -> to.set(PROJECT_ID_FIELD_NAME, p)); |
326 | 332 | ifNonNull(from.getAcl(), toListOf(bucketAcl()::encode), to::setAcl);
|
327 | 333 | ifNonNull(from.getCors(), toListOf(cors()::encode), to::setCors);
|
328 | 334 | ifNonNull(from.getCreateTimeOffsetDateTime(), dateTimeCodec::encode, to::setTimeCreated);
|
@@ -395,6 +401,10 @@ private Bucket bucketInfoEncode(BucketInfo from) {
|
395 | 401 | @SuppressWarnings("deprecation")
|
396 | 402 | private BucketInfo bucketInfoDecode(com.google.api.services.storage.model.Bucket from) {
|
397 | 403 | BucketInfo.Builder to = new BucketInfo.BuilderImpl(from.getName());
|
| 404 | + ifNonNull( |
| 405 | + from.get(PROJECT_ID_FIELD_NAME), |
| 406 | + lift(String.class::cast).andThen(projectNameCodec::decode), |
| 407 | + to::setProject); |
398 | 408 | ifNonNull(from.getAcl(), toListOf(bucketAcl()::decode), to::setAcl);
|
399 | 409 | ifNonNull(from.getCors(), toListOf(cors()::decode), to::setCors);
|
400 | 410 | ifNonNull(from.getDefaultObjectAcl(), toListOf(objectAcl()::decode), to::setDefaultAcl);
|
|
0 commit comments