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(bucket): add enableLogging method #876

Merged
merged 10 commits into from Oct 14, 2019

Conversation

stephenplusplus
Copy link
Contributor

Fixes #23

Hello! This adds the bucket.enableLogging() shortcut method as discussed in #23.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 4, 2019
@codecov
Copy link

codecov bot commented Oct 4, 2019

Codecov Report

Merging #876 into master will increase coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #876      +/-   ##
==========================================
+ Coverage   95.31%   95.36%   +0.05%     
==========================================
  Files          11       11              
  Lines        1217     1231      +14     
  Branches      304      307       +3     
==========================================
+ Hits         1160     1174      +14     
  Misses         29       29              
  Partials       28       28
Impacted Files Coverage Δ
src/bucket.ts 92.98% <100%> (+0.29%) ⬆️

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 fc1feb7...2a69735. Read the comment docs.

src/bucket.ts Outdated Show resolved Hide resolved
src/bucket.ts Outdated Show resolved Hide resolved
src/bucket.ts Outdated Show resolved Hide resolved
src/bucket.ts Outdated
logObjectPrefix: config.prefix,
},
});
callback!(null, setMetadataResponse);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should execute the callback here, only because it is wrapped inside of the try block and if a user error would occur, we would end up calling their callback twice

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’m sure you’re right, although I’m not following the scenario. Could you elaborate how that would happen?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure

bucket.enableLogging({prefix: 'hithere'}, err => {
  if (err.code === 404) {
    console.log('oh no!');
  }
});

Using that example, if we pretend the user forgets to check that err actually exists when it doesn't, it might result in a TypeError being thrown. That would move us to the catch section where we would execute the callback again with that very same TypeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, thanks!

src/bucket.ts Show resolved Hide resolved
src/bucket.ts Outdated
*
* bucket.enableLogging(config, function(err, apiResponse) {});
*
* @example <caption>If the callback is omitted, we'll return a Promise.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@callmehiphop Ran into the end of the line. How's this looking?

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think you have to run over the end in this case. Pretty sure our docs aren't smart enough to know that the closing tag is part of the caption still.

src/bucket.ts Outdated Show resolved Hide resolved
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 nit.

src/bucket.ts Outdated
try {
await this.acl.add({
entity: 'group-cloud-storage-analytics@google.com',
role: 'WRITER',
Copy link
Member

Choose a reason for hiding this comment

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

use IAM Policy instead.


try {
const [policy] = await this.iam.getPolicy();
policy.bindings.push({
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 is this the correct configuration?

Copy link
Member

Choose a reason for hiding this comment

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

+1, it's the role with the least number of permissions following the least privileges model.

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.

LGTM,


try {
const [policy] = await this.iam.getPolicy();
policy.bindings.push({
Copy link
Member

Choose a reason for hiding this comment

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

+1, it's the role with the least number of permissions following the least privileges model.

src/bucket.ts Outdated
try {
const [policy] = await this.iam.getPolicy();
policy.bindings.push({
members: ['cloud-storage-analytics@google.com'],
Copy link
Member

@frankyn frankyn Oct 10, 2019

Choose a reason for hiding this comment

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

Ah, I missed the system test failure, cloud-storage-analytics@google.com is a group.

You should do:

members: ['group:cloud-storage-analytics@google.com']

src/bucket.ts Outdated
const [policy] = await this.iam.getPolicy();
policy.bindings.push({
members: ['cloud-storage-analytics@google.com'],
role: 'roles/storage.objectAdmin',
Copy link
Member

Choose a reason for hiding this comment

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

Use roles/storage.objectCreator instead. GCS shouldn't need to overwrite/delete data.

@AVaksman
Copy link
Contributor

AVaksman commented Oct 10, 2019

Should we worry about making codecov happy?
adding a test case scenario to disregard config.bucket value if it is neither instance of Bucket nor string?
Or error out in that case?

@stephenplusplus
Copy link
Contributor Author

@AVaksman that's a good point. I don't think we should error, but I just made the check less verbose to just take whatever they give us. PTAL

@stephenplusplus stephenplusplus added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 11, 2019
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 11, 2019
@AVaksman
Copy link
Contributor

LGTM

@stephenplusplus stephenplusplus merged commit b09ecac into googleapis:master Oct 14, 2019
@stephenplusplus stephenplusplus deleted the spp--23 branch October 14, 2019 13:02
@chrishiestand
Copy link

Thanks everyone!

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.

logging endpoint support
8 participants