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

bucketExists: Use a bool to indicate if a bucket exists or not #666

Merged
merged 1 commit into from
Feb 9, 2018

Conversation

vadmeste
Copy link
Member

@vadmeste vadmeste commented Jan 29, 2018

This is a breaking API change. bucketExists API will require
a callback with this signature cb(err, bool). This is a better
way to indicate whether a bucket exists or not.

Fixes #648

@vadmeste vadmeste force-pushed the bucket_exists_not_found branch from 06ecfb7 to a50aef3 Compare January 29, 2018 16:55
@vadmeste vadmeste force-pushed the bucket_exists_not_found branch from a50aef3 to 42da800 Compare January 29, 2018 18:13
ebozduman
ebozduman previously approved these changes Jan 29, 2018
@vadmeste
Copy link
Member Author

@ebozduman, I checked with aws s3api, this latter starts by making path style request with us-east-1 region in all cases, then when it receives 301 Moved Permanently, it will just follow the new location and update the region. However, I don't understand why we really need to follow the link since 301 Move Permanently also means the bucket exists.

@ebozduman
Copy link
Contributor

ebozduman commented Jan 29, 2018

Good point.
I also would like to remind you to add the reason why the request in the issue, about "bucketExists" api to just return true or false as its name implies, instead of throwing error messages, is not addressed. If we decided to not address that request for any reason, then it would be a good idea to explain the reason in the issue.

@vadmeste vadmeste force-pushed the bucket_exists_not_found branch 3 times, most recently from 1e74d4f to 242072a Compare January 30, 2018 21:37
@vadmeste
Copy link
Member Author

@ebozduman this PR is updated without following redirection. I think MovedPermanently status code is enough to indicate that a bucket exists.

Copy link
Contributor

@krishnasrinivas krishnasrinivas left a comment

Choose a reason for hiding this comment

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

@vadmeste can you confirm that it works as expected with AWS-S3 bucket in non us-east-1 location

@vadmeste
Copy link
Member Author

vadmeste commented Feb 5, 2018

@vadmeste can you confirm that it works as expected with AWS-S3 bucket in non us-east-1 location

@krishnasrinivas, yeah it is already tested with AWS with non standard location, AWS returns 301 status code (permanently moved) and the code considers it as the bucket exists and doesn't return any error.

@krishnasrinivas
Copy link
Contributor

@vadmeste I think it is better to be consistent on the request styles (virtual vs path) unless there is a strong reason so that the request styles are predictable. Also some S3 servers don't support path style requests (reason by minio-go now supports virtual-style as config option).

A better fix for this would be change the API of bucketExists like how @dcharbonnier has suggested here #648

So bucketExists will be called like s3Client.bucketExists('bucketname', (err, exists) =>{..})

This will fix it:

diff --git a/src/main/minio.js b/src/main/minio.js
index 38f8af1..d725e37 100644
--- a/src/main/minio.js
+++ b/src/main/minio.js
@@ -645,7 +645,13 @@ export class Client {
       throw new TypeError('callback should be of type "function"')
     }
     var method = 'HEAD'
-    this.makeRequest({method, bucketName}, '', 200, '', false, cb)
+    this.makeRequest({method, bucketName}, '', 200, '', false, err => {
+      if (err) {
+       if (err.code == 'NoSuchBucket' || err.code == 'NotFound') return cb(null, false)
+       return cb(err)
+      }
+      cb(null, true)
+    })
   }
 
   // Remove a bucket.

@vadmeste
Copy link
Member Author

vadmeste commented Feb 6, 2018

Also some S3 servers don't support path style requests

oups, I didn't know that.

Actually I was following "aws s3api head-bucket" command but also your suggestion seems to be fine and easier than the aws way. Will do it.

@vadmeste vadmeste force-pushed the bucket_exists_not_found branch from 242072a to 56c21cb Compare February 8, 2018 13:23
@vadmeste vadmeste changed the title bucketExists: return consistent NotFound error code bucketExists: Use a bool to indicate if a bucket exists or not Feb 8, 2018
@vadmeste vadmeste force-pushed the bucket_exists_not_found branch from 56c21cb to 4ef681a Compare February 8, 2018 13:41
@vadmeste
Copy link
Member Author

vadmeste commented Feb 8, 2018

@krishnasrinivas @ebozduman, updated the PR. But this is a breaking change, is @abperiasamy okay with that ?

@dcharbonnier
Copy link
Contributor

my 2 cents, if there is a plan to break compatibility maybe it would be time to start a 5.x milestone with more changes

@krishnasrinivas
Copy link
Contributor

@vadmeste yes this change is correct. Previous API was implemented by me which was incorrect. Can you increment major version as well?

This is a breaking API change. bucketExists API will require
a callback with this signature cb(err, bool). This is a better
way to indicate whether a bucket exists or not. Major version
is also incremented.
@vadmeste vadmeste force-pushed the bucket_exists_not_found branch from 4ef681a to 653c14b Compare February 8, 2018 16:44
@vadmeste
Copy link
Member Author

vadmeste commented Feb 8, 2018

@krishnasrinivas, done, I set '5.0.0' in package.json.

@krishnasrinivas krishnasrinivas merged commit ccd2c23 into minio:master Feb 9, 2018
@ruslan-polutsygan
Copy link

Latest version(4.0) still throws NoSuchBucket exception.

@ruslan-polutsygan
Copy link

Hm. Just seen that it is going to be in 5.0.

@ruslan-polutsygan
Copy link

And docs already say it returns boolean - https://docs.minio.io/docs/javascript-client-api-reference#bucketExists
:(

@krishnasrinivas
Copy link
Contributor

@ruslan-polutsygan sorry about that :-( we will make a release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants