Skip to content

Commit 5a160ee

Browse files
fix: Remove all client side validation for OLM, allow nonspecific lif… (#1160)
* fix: Remove all client side validation for OLM, allow nonspecific lifecycle actions * Test unsupported actions * address comments * Fix clirr * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * checkstyle Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent cc999b1 commit 5a160ee

File tree

5 files changed

+63
-18
lines changed

5 files changed

+63
-18
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-storage'
5656
If you are using Gradle without BOM, add this to your dependencies
5757

5858
```Groovy
59-
implementation 'com.google.cloud:google-cloud-storage:2.2.2'
59+
implementation 'com.google.cloud:google-cloud-storage:2.2.3'
6060
```
6161

6262
If you are using SBT, add this to your dependencies
6363

6464
```Scala
65-
libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.2.2"
65+
libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.2.3"
6666
```
6767

6868
## Authentication
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- see https://www.mojohaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
3+
<differences>
4+
<difference>
5+
<className>com/google/cloud/storage/BucketInfo$LifecycleRule$LifecycleAction</className>
6+
<method>BucketInfo$LifecycleRule$LifecycleAction()</method>
7+
<differenceType>7004</differenceType>
8+
</difference>
9+
</differences>

google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java

+36-16
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,13 @@ static LifecycleRule fromPb(Rule rule) {
548548
StorageClass.valueOf(action.getStorageClass()));
549549
break;
550550
default:
551-
throw new UnsupportedOperationException(
552-
"The specified lifecycle action " + action.getType() + " is not currently supported");
551+
log.warning(
552+
"The lifecycle action "
553+
+ action.getType()
554+
+ " is not supported by this version of the library. "
555+
+ "Attempting to update with this rule may cause errors. Please "
556+
+ "update to the latest version of google-cloud-storage.");
557+
lifecycleAction = LifecycleAction.newLifecycleAction("Unknown action");
553558
}
554559

555560
Rule.Condition condition = rule.getCondition();
@@ -799,13 +804,21 @@ public LifecycleCondition build() {
799804
}
800805

801806
/**
802-
* Base class for the Action to take when a Lifecycle Condition is met. Specific Actions are
807+
* Base class for the Action to take when a Lifecycle Condition is met. Supported Actions are
803808
* expressed as subclasses of this class, accessed by static factory methods.
804809
*/
805-
public abstract static class LifecycleAction implements Serializable {
810+
public static class LifecycleAction implements Serializable {
806811
private static final long serialVersionUID = 5801228724709173284L;
807812

808-
public abstract String getActionType();
813+
private final String actionType;
814+
815+
public LifecycleAction(String actionType) {
816+
this.actionType = actionType;
817+
}
818+
819+
public String getActionType() {
820+
return actionType;
821+
}
809822

810823
@Override
811824
public String toString() {
@@ -830,17 +843,24 @@ public static SetStorageClassLifecycleAction newSetStorageClassAction(
830843
StorageClass storageClass) {
831844
return new SetStorageClassLifecycleAction(storageClass);
832845
}
846+
847+
/**
848+
* Creates a new {@code LifecycleAction , with no specific supported action associated with it. This
849+
* is only intended as a "backup" for when the library doesn't recognize the type, and should
850+
* generally not be used, instead use the supported actions, and upgrade the library if necessary
851+
* to get new supported actions.
852+
*/
853+
public static LifecycleAction newLifecycleAction(String actionType) {
854+
return new LifecycleAction(actionType);
855+
}
833856
}
834857

835858
public static class DeleteLifecycleAction extends LifecycleAction {
836859
public static final String TYPE = "Delete";
837860
private static final long serialVersionUID = -2050986302222644873L;
838861

839-
private DeleteLifecycleAction() {}
840-
841-
@Override
842-
public String getActionType() {
843-
return TYPE;
862+
private DeleteLifecycleAction() {
863+
super(TYPE);
844864
}
845865
}
846866

@@ -851,14 +871,10 @@ public static class SetStorageClassLifecycleAction extends LifecycleAction {
851871
private final StorageClass storageClass;
852872

853873
private SetStorageClassLifecycleAction(StorageClass storageClass) {
874+
super(TYPE);
854875
this.storageClass = storageClass;
855876
}
856877

857-
@Override
858-
public String getActionType() {
859-
return TYPE;
860-
}
861-
862878
@Override
863879
public String toString() {
864880
return MoreObjects.toStringHelper(this)
@@ -1007,7 +1023,11 @@ static class RawDeleteRule extends DeleteRule {
10071023

10081024
@Override
10091025
void populateCondition(Rule.Condition condition) {
1010-
throw new UnsupportedOperationException();
1026+
log.warning(
1027+
"The lifecycle condition "
1028+
+ condition
1029+
+ " is not currently supported. Please update to the latest version of google-cloud-java."
1030+
+ " Also, use LifecycleRule rather than the deprecated DeleteRule.");
10111031
}
10121032

10131033
private void writeObject(ObjectOutputStream out) throws IOException {

google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ public void testDeleteRules() {
314314
for (DeleteRule delRule : rules) {
315315
assertEquals(delRule, DeleteRule.fromPb(delRule.toPb()));
316316
}
317+
Rule unsupportedRule =
318+
new Rule().setAction(new Rule.Action().setType("This action doesn't exist"));
319+
DeleteRule.fromPb(
320+
unsupportedRule); // if this doesn't throw an exception, unsupported rules work
317321
}
318322

319323
@Test
@@ -363,6 +367,17 @@ public void testLifecycleRules() {
363367
assertEquals(StorageClass.COLDLINE.toString(), lifecycleRule.getAction().getStorageClass());
364368
assertEquals(30, lifecycleRule.getCondition().getDaysSinceCustomTime().intValue());
365369
assertNotNull(lifecycleRule.getCondition().getCustomTimeBefore());
370+
371+
Rule unsupportedRule =
372+
new LifecycleRule(
373+
LifecycleAction.newLifecycleAction("This action type doesn't exist"),
374+
LifecycleCondition.newBuilder().setAge(10).build())
375+
.toPb();
376+
unsupportedRule.setAction(
377+
unsupportedRule.getAction().setType("This action type also doesn't exist"));
378+
379+
LifecycleRule.fromPb(
380+
unsupportedRule); // If this doesn't throw an exception, unsupported rules are working
366381
}
367382

368383
@Test

samples/snippets/src/main/java/com/example/storage/ConfigureRetries.java

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
package com.example.storage;
18+
1819
// [START storage_configure_retries]
1920

2021
import com.google.api.gax.retrying.RetrySettings;

0 commit comments

Comments
 (0)