Skip to content
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

feat: Add support to disable logging from bucket #390

Merged
merged 6 commits into from Jun 25, 2020

Conversation

athakor
Copy link
Contributor

@athakor athakor commented Jun 23, 2020

Fixes #389

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 23, 2020
@athakor athakor changed the title Add support to disable logging from bucket feat: Add support to disable logging from bucket Jun 23, 2020
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #390 into master will increase coverage by 0.13%.
The diff coverage is 83.33%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #390      +/-   ##
============================================
+ Coverage     63.13%   63.27%   +0.13%     
- Complexity      601      609       +8     
============================================
  Files            32       32              
  Lines          5078     5113      +35     
  Branches        481      487       +6     
============================================
+ Hits           3206     3235      +29     
- Misses         1708     1713       +5     
- Partials        164      165       +1     
Impacted Files Coverage Δ Complexity Δ
...main/java/com/google/cloud/storage/BucketInfo.java 81.57% <83.33%> (+0.23%) 83.00 <0.00> (ø)
...ogle/cloud/storage/testing/StorageRpcTestBase.java 96.00% <0.00%> (-1.96%) 48.00% <0.00%> (ø%)
...om/google/cloud/storage/spi/v1/HttpStorageRpc.java 1.50% <0.00%> (-0.02%) 1.00% <0.00%> (ø%)
...rc/main/java/com/google/cloud/storage/Storage.java 80.90% <0.00%> (ø) 0.00% <0.00%> (ø%)
...ain/java/com/google/cloud/storage/StorageImpl.java 81.00% <0.00%> (+0.47%) 138.00% <0.00%> (+7.00%)
...src/main/java/com/google/cloud/storage/Bucket.java 82.07% <0.00%> (+0.71%) 34.00% <0.00%> (ø%)
...ava/com/google/cloud/storage/BlobWriteChannel.java 74.60% <0.00%> (+2.93%) 10.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81472a4...b3aab02. Read the comment docs.

@@ -1310,7 +1310,7 @@ public Builder setIamConfiguration(IamConfiguration iamConfiguration) {

@Override
public Builder setLogging(Logging logging) {
this.logging = logging;
this.logging = logging != null ? logging : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead do:

this.logging = logging != null ? logging : Data.nullOf(Bucket.Logging.class);

Copy link
Contributor Author

@athakor athakor Jun 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankyn thanks for the quick review I think we have to go with the null instead of Data.nullOf(com.google.cloud.storage.Bucket.Logging.class) because if we do as you said then the following error occurs : unable to create new instance of class com.google.cloud.storage.BucketInfo$Logging because it has no accessible default constructor

if (logging != null) {
bucketPb.setLogging(logging.toPb());
}
Bucket.Logging loggingPb = logging != null ? logging.toPb() : Data.nullOf(Bucket.Logging.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this change:

 Bucket.Logging loggingPb = logging != null ? logging.toPb() : Data.nullOf(Bucket.Logging.class);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also have to keep this check because when the object of logging is null, the logging.toPb() will throw the nullPointer exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/googleapis/java-storage/compare/qlogics?expand=1

Here's alternative solution. If you have concerns with it always open to discuss further.

I'd like to address the issue with logging field is not selected in Fields. In which case it comes back null and this PR can corrupt the logging field when not selected.

For example this will corrupt logging metadata:

      BucketInfo.Logging logging =
          BucketInfo.Logging.newBuilder()
              .setLogBucket(logsBucket)
              .setLogObjectPrefix("test-logs")
              .build();
      Bucket bucket =
          storage.create(
              BucketInfo.newBuilder(loggingBucket).setLocation("us").setLogging(logging).build());
      // Perform Get Request without selecting logging field
      Bucket remoteBucket = storage.get(loggingBucket);
      // Don't update logging and only perform an update.
      Bucket updatedBucket = bucket.toBuilder().build().update();
      // Logging is now null.

Additionally could you remove setting IAM policy to allow writes from allAuthenticatedUsers. This is a security risk:

          storage.setIamPolicy(
              logsBucket,
              policy
                  .toBuilder()
                  .addIdentity(StorageRoles.legacyBucketWriter(), Identity.allAuthenticatedUsers())
                  .build()));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@frankyn good catch and thanks for the detailed description.

Both the comments have been addressed PTAL when get chance.

Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more change but looks good to me overall, thanks!

logging.setLogBucket(logBucket);
logging.setLogObjectPrefix(logObjectPrefix);
Bucket.Logging logging;
if (logBucket != null && logObjectPrefix != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be an || an or.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@frankyn frankyn merged commit be72027 into googleapis:master Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable logging from bucket is not working
3 participants