Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
docs(samples): remove bucket CORS configuration #7288
Conversation
|
@frankyn PTAL |
|
|
||
| Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
| Bucket bucket = storage.get(bucketName); | ||
| bucket.toBuilder().setCors(ImmutableList.<Cors>of()).build().update(); |
frankyn
Jul 17, 2020
Member
does null not work here?
does null not work here?
athakor
Jul 20, 2020
•
Author
Member
@frankyn null setting doesn't works here see the respected example with response
Storage storage = StorageOptions.getDefaultInstance().getService();
String bucketName = RemoteStorageHelper.generateBucketName();
try{
Cors cors = Cors.newBuilder()
.setOrigins(ImmutableList.of(Cors.Origin.of("*")))
.setMethods(ImmutableList.of(HttpMethod.GET))
.setResponseHeaders(ImmutableList.of("Content-Type"))
.setMaxAgeSeconds(100)
.build();
Bucket bucket =
storage.create(BucketInfo.newBuilder(bucketName).setCors(ImmutableList.of(cors)).build());
System.out.println("Prior size : " + bucket.getCors().size());
Bucket updatedBucket = bucket.toBuilder().setCors(null).build().update();
System.out.println("After updating operation size must be zero instead of : " + updatedBucket.getCors().size());
}finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
Response :
Prior size : 1
After updating operation size must be zero instead of : 1
@frankyn null setting doesn't works here see the respected example with response
Storage storage = StorageOptions.getDefaultInstance().getService();
String bucketName = RemoteStorageHelper.generateBucketName();
try{
Cors cors = Cors.newBuilder()
.setOrigins(ImmutableList.of(Cors.Origin.of("*")))
.setMethods(ImmutableList.of(HttpMethod.GET))
.setResponseHeaders(ImmutableList.of("Content-Type"))
.setMaxAgeSeconds(100)
.build();
Bucket bucket =
storage.create(BucketInfo.newBuilder(bucketName).setCors(ImmutableList.of(cors)).build());
System.out.println("Prior size : " + bucket.getCors().size());
Bucket updatedBucket = bucket.toBuilder().setCors(null).build().update();
System.out.println("After updating operation size must be zero instead of : " + updatedBucket.getCors().size());
}finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}Response :
Prior size : 1
After updating operation size must be zero instead of : 1
lesv
Jul 20, 2020
Collaborator
I can see @frankyn 's argument, but following it's point, why need to call setCors() at all if it's empty or NULL?
Lots of folks (Effective Java 3rd ed.) prefer empty lists to using NULL, and I was going to comment w/ that, but really, if it's empty, why have to set it at all?
I can see @frankyn 's argument, but following it's point, why need to call setCors() at all if it's empty or NULL?
Lots of folks (Effective Java 3rd ed.) prefer empty lists to using NULL, and I was going to comment w/ that, but really, if it's empty, why have to set it at all?
frankyn
Jul 20, 2020
Member
In this case the example is to remove CORS from a bucket metadata. Good call, I think we can move forward with this PR with ImmutableList.<Cors>Of()
In this case the example is to remove CORS from a bucket metadata. Good call, I think we can move forward with this PR with ImmutableList.<Cors>Of()
frankyn
Jul 20, 2020
Member
Maybe one additional change that could be made here @athakor is to confirm that CORS are set before making a subsequent call. That way you reduce the need to make a patch request.
Maybe one additional change that could be made here @athakor is to confirm that CORS are set before making a subsequent call. That way you reduce the need to make a patch request.
athakor
Jul 21, 2020
Author
Member
done
done
|
Approved for java-samples-reviewers |
|
|
||
| Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
| Bucket bucket = storage.get(bucketName); | ||
| bucket.toBuilder().setCors(ImmutableList.<Cors>of()).build().update(); |
lesv
Jul 20, 2020
Collaborator
I can see @frankyn 's argument, but following it's point, why need to call setCors() at all if it's empty or NULL?
Lots of folks (Effective Java 3rd ed.) prefer empty lists to using NULL, and I was going to comment w/ that, but really, if it's empty, why have to set it at all?
I can see @frankyn 's argument, but following it's point, why need to call setCors() at all if it's empty or NULL?
Lots of folks (Effective Java 3rd ed.) prefer empty lists to using NULL, and I was going to comment w/ that, but really, if it's empty, why have to set it at all?
|
|
||
| Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService(); | ||
| Bucket bucket = storage.get(bucketName); | ||
| bucket.toBuilder().setCors(ImmutableList.<Cors>of()).build().update(); |
frankyn
Jul 20, 2020
Member
Maybe one additional change that could be made here @athakor is to confirm that CORS are set before making a subsequent call. That way you reduce the need to make a patch request.
Maybe one additional change that could be made here @athakor is to confirm that CORS are set before making a subsequent call. That way you reduce the need to make a patch request.
| List<Cors> cors = new ArrayList<>(bucket.getCors()); | ||
|
|
||
| // Remove bucket CORS configuration. | ||
| for (int index = 0; index < cors.size(); index++) { |
frankyn
Jul 21, 2020
Member
Use cors.clear() instead if all cors will be deleted.
Use cors.clear() instead if all cors will be deleted.
athakor
Jul 22, 2020
Author
Member
done
done
cd43d0d
into
googleapis:master

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

No description provided.