-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update GrpcConversions to use Bucket.RetentionPolicy.retention_duration #1798
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,13 @@ | |
import com.google.api.client.http.json.JsonHttpContent; | ||
import com.google.api.client.json.JsonFactory; | ||
import com.google.api.client.json.jackson2.JacksonFactory; | ||
import com.google.api.client.util.Data; | ||
import com.google.api.client.util.DateTime; | ||
import com.google.api.services.storage.Storage; | ||
import com.google.api.services.storage.Storage.Objects.Get; | ||
import com.google.api.services.storage.Storage.Objects.Insert; | ||
import com.google.api.services.storage.model.Bucket; | ||
import com.google.api.services.storage.model.Bucket.RetentionPolicy; | ||
import com.google.api.services.storage.model.BucketAccessControl; | ||
import com.google.api.services.storage.model.Buckets; | ||
import com.google.api.services.storage.model.ComposeRequest; | ||
|
@@ -534,6 +537,18 @@ public Bucket patch(Bucket bucket, Map<Option, ?> options) { | |
Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_BUCKET); | ||
Scope scope = tracer.withSpan(span); | ||
try { | ||
RetentionPolicy retentionPolicy = bucket.getRetentionPolicy(); | ||
if (retentionPolicy != null) { | ||
// according to https://cloud.google.com/storage/docs/json_api/v1/buckets both effectiveTime | ||
// and isLocked are output_only. Strip them out if present without retentionPeriod. | ||
if (retentionPolicy.getRetentionPeriod() == null) { | ||
bucket.setRetentionPolicy(Data.nullOf(RetentionPolicy.class)); | ||
} else { | ||
retentionPolicy.setEffectiveTime(Data.nullOf(DateTime.class)); | ||
retentionPolicy.setIsLocked(Data.nullOf(Boolean.class)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you set these values to the "null of" of their type? This does seem necessary in the client if they're read-only anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That else branch is leftover from some debugging, I'll clean it up. You're correct, it effectively don't have any impact. |
||
} | ||
} | ||
|
||
String projection = Option.PROJECTION.getString(options); | ||
if (bucket.getIamConfiguration() != null | ||
&& bucket.getIamConfiguration().getBucketPolicyOnly() != null | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.storage; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.cloud.storage.Conversions.Codec; | ||
import com.google.cloud.storage.jqwik.StorageArbitraries; | ||
import com.google.protobuf.Duration; | ||
import net.jqwik.api.Arbitrary; | ||
import net.jqwik.api.ArbitrarySupplier; | ||
import net.jqwik.api.ForAll; | ||
import net.jqwik.api.Property; | ||
|
||
final class DurationCodecPropertyTest { | ||
|
||
@Property | ||
void timestampCodecShouldRoundTrip(@ForAll(supplier = Supp.class) Duration ts) { | ||
Codec<java.time.Duration, Duration> codec = GrpcConversions.INSTANCE.durationCodec; | ||
java.time.Duration decode = codec.decode(ts); | ||
Duration encode = codec.encode(decode); | ||
|
||
assertThat(encode).isEqualTo(ts); | ||
} | ||
|
||
private static final class Supp implements ArbitrarySupplier<Duration> { | ||
@Override | ||
public Arbitrary<Duration> get() { | ||
return StorageArbitraries.duration(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use
from.getRententionPeriodDuration()
orfrom.retentionPolicyIsLocked()
only and leave outfrom.getRetentionEffectiveTimeOffsetDateTime()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These converters are ignorant to the services constraints on fields. Our converters are always fully mapping, so we care about each of the fields. When this makes its way down to an actual request, that request handler is the place to apply service level field filtering.