Repository: googleapis/java-storage
Pull request #1051 (2021-09-28 14:06:30)

fix: update PAP to use inherited instead of unspecified


Patch:
diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
index 2bc3df39..83a836f7 100644
--- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
+++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java
@@ -113,13 +113,19 @@ public class BucketInfo implements Serializable {
    */
   public enum PublicAccessPrevention {
     ENFORCED("enforced"),
-    /** Default value for Public Access Prevention */
-    UNSPECIFIED("unspecified"),
+    /**
+     * Default value for Public Access Prevention
+     *
+     * @deprecated use {@link #INHERITED}
+     */
+    @Deprecated
+    UNSPECIFIED("inherited"),
     /**
      * If the api returns a value that isn't defined in {@link PublicAccessPrevention} this value
      * will be returned.
      */
-    UNKNOWN(null);
+    UNKNOWN(null),
+    INHERITED("inherited");
 
     private final String value;
 
@@ -133,10 +139,14 @@ public class BucketInfo implements Serializable {
 
     public static PublicAccessPrevention parse(String value) {
       String upper = value.toUpperCase();
-      try {
-        return valueOf(upper);
-      } catch (IllegalArgumentException ignore) {
-        return UNKNOWN;
+      switch (upper) {
+        case "ENFORCED":
+          return ENFORCED;
+        case "UNSPECIFIED":
+        case "INHERITED":
+          return INHERITED;
+        default:
+          return UNKNOWN;
       }
     }
   }
@@ -300,7 +310,7 @@ public class BucketInfo implements Serializable {
 
       /**
        * Sets the bucket's Public Access Prevention configuration. Currently supported options are
-       * {@link PublicAccessPrevention#UNSPECIFIED} or {@link PublicAccessPrevention#ENFORCED}
+       * {@link PublicAccessPrevention#INHERITED} or {@link PublicAccessPrevention#ENFORCED}
        *
        * @see <a
        *     href="https://cloud.google.com/storage/docs/public-access-prevention">public-access-prevention</a>


Test patch:
diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
index f8f51d38..73ef7e9b 100644
--- a/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
+++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITStorageTest.java
@@ -3296,7 +3296,7 @@ public class ITStorageTest {
                     .setPublicAccessPrevention(
                         enforced
                             ? BucketInfo.PublicAccessPrevention.ENFORCED
-                            : BucketInfo.PublicAccessPrevention.UNSPECIFIED)
+                            : BucketInfo.PublicAccessPrevention.INHERITED)
                     .build())
             .build());
   }
@@ -3389,7 +3389,7 @@ public class ITStorageTest {
       Bucket bucket = generatePublicAccessPreventionBucket(papBucket, false);
       assertEquals(
           bucket.getIamConfiguration().getPublicAccessPrevention(),
-          BucketInfo.PublicAccessPrevention.UNSPECIFIED);
+          BucketInfo.PublicAccessPrevention.INHERITED);
       assertFalse(bucket.getIamConfiguration().isUniformBucketLevelAccessEnabled());
       assertFalse(bucket.getIamConfiguration().isBucketPolicyOnlyEnabled());