-
Notifications
You must be signed in to change notification settings - Fork 89
feat: BucketInfo conversion for gRPC #1431
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
Conversation
daa1619 to
de73884
Compare
google-cloud-storage/src/main/java/com/google/cloud/storage/ApiaryConversions.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| /** | ||
| * Returns the date in RFC 3339 format with only the date part (for instance, "2013-01-15"). |
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.
OffesetDateTime isn't exactly an RFC 3339 date.
I think we'll want to change the comment here to be a bit more explicit. Something like:
Returns the date and offset from UTC for this condition.
If a time other than00:00:00.000is present in the value, GCS will truncate to00:00:00.000.
| import net.jqwik.api.Property; | ||
|
|
||
| final class BucketPropertyTest { | ||
| final class BucketInfoPropertyTest extends BaseConvertablePropertyTest<BucketInfo, Bucket> { |
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.
👍🏻
| .offsetBetween(ZoneOffset.UTC, ZoneOffset.UTC) | ||
| .map( | ||
| odt -> { | ||
| OffsetDateTime utc = odt.withOffsetSameInstant(ZoneOffset.UTC); |
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.
I don't think you need this transform here, the input has previously been constrained to UTC.
| return rule() | ||
| .list() | ||
| .ofMinSize(0) | ||
| .ofMaxSize(100) |
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.
Is there an actual limit on the gcs side for how many rules can be present? If so it might make sense to use a similar value here.
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.
I thought it was 100 but i can't seem to find a limit. I can remove the upperbound but 100 feels okay to me. What do you think?
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.
100's probably fine in that case. We probably won't want to somehow end up slowing down tests because the generator needs to construct like 700k of these things.
| if (createdBefore == null) return this; | ||
| return setCreateBeforeOffsetDateTime( | ||
| millisOffsetDateTimeCodec.encode(createdBefore.getValue())); |
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.
Similar to the getter, I think this can be simplified to
| if (createdBefore == null) return this; | |
| return setCreateBeforeOffsetDateTime( | |
| millisOffsetDateTimeCodec.encode(createdBefore.getValue())); | |
| return setCustomTimeBeforeOffsetDateTime( | |
| Utils.dateTimeCodec.nullable().decode(customTimeBefore)); |
| if (noncurrentTimeBefore == null) return this; | ||
| return setNoncurrentTimeBeforeOffsetDateTime( | ||
| millisOffsetDateTimeCodec.encode(noncurrentTimeBefore.getValue())); |
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.
Same as #setCustomDateTime
| if (customTimeBefore == null) return this; | ||
| return setCustomTimeBeforeOffsetDateTime( | ||
| millisOffsetDateTimeCodec.encode(customTimeBefore.getValue())); |
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.
Same as #setCustomDateTime
| if (createdBefore == null) return this; | ||
| return setCreateBeforeOffsetDateTime( | ||
| millisOffsetDateTimeCodec.encode(createdBefore.getValue())); | ||
| } |
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.
Additionally, when using the Utils.dateTimeCodec.nullable() you'll want to put that in a variable so it doesn't construct a new codec instance each time.
| if (from.getWebsite() != null | ||
| || from.getWebsite().getMainPageSuffix() != null | ||
| || from.getWebsite().getNotFoundPage() != null) { | ||
| to.setIndexPage(from.getWebsite().getMainPageSuffix()); | ||
| to.setNotFoundPage(from.getWebsite().getNotFoundPage()); | ||
| } |
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.
According to the proto definition, both of these properties are non-optional.
java-storage/proto-google-cloud-storage-v2/src/main/proto/google/storage/v2/storage.proto
Lines 1520 to 1533 in 1f14acd
| message Website { | |
| // If the requested object path is missing, the service will ensure the path | |
| // has a trailing '/', append this suffix, and attempt to retrieve the | |
| // resulting object. This allows the creation of `index.html` | |
| // objects to represent directory pages. | |
| string main_page_suffix = 1; | |
| // If the requested object path is missing, and any | |
| // `mainPageSuffix` object is missing, if applicable, the service | |
| // will return the named object from this bucket as the content for a | |
| // [https://tools.ietf.org/html/rfc7231#section-6.5.4][404 Not Found] | |
| // result. | |
| string not_found_page = 2; | |
| } |
This if condition can be simplified to:
if (from.hasWebsite())
| actionBuilder.setStorageClass(s); | ||
| } | ||
| return actionBuilder.build(); | ||
| }); |
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.
I found the previous version easier to read, but if you feel this is easier feel free to keep it.
BenWhitehead
left a comment
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.
A few minor requests to update some of the javadocs. I'll approve so you can merge after updating those items.
| * truncated. This condition is satisfied when the custom time on an object is before this | ||
| * date in UTC. | ||
| * | ||
| * @deprecated {@link #setCustomTimeBeforeOffsetDateTime(OffsetDateTime)} |
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.
Missing the Use on this statement like the others
| /** | ||
| * Returns the date in RFC 3339 format with only the date part (for instance, "2013-01-15"). | ||
| * | ||
| * @deprecated {@link #getNoncurrentTimeBeforeOffsetDateTime()} |
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.
Missing the Use on this statement like the others
| /** | ||
| * Sets the date in RFC 3339 format with only the date part (for instance, "2013-01-15"). | ||
| * Note that only date part will be considered, if the time is specified it will be | ||
| * truncated. This condition is satisfied when the noncurrent time on an object is before | ||
| * this date. This condition is relevant only for versioned objects. | ||
| */ |
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.
Can we drop the RFC 3339 part of this statement?
| } | ||
|
|
||
| /** | ||
| * Sets the date in RFC 3339 format with only the date part (for instance, "2013-01-15"). |
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.
Can we drop the RFC 3339 part of this statement.
| Utils.toImmutableListOf(lifecycleRule()::encode), | ||
| lifecycleBuilder::addAllRule); | ||
| /* | ||
| // Corruption occurs by having deleteRule() values added |
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.
@BenWhitehead deleteRule() corrupts the policy and I commented it out. I can do a follow-up PR to better handle this case as this PR is long. WDYT?
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.
SGTM
Introducing more support for BucketInfo conversions