Access validation only for ListBuckets(), all others do not explicitly require Auth verification
This commit is contained in:
@@ -91,13 +91,6 @@ func (e errAliasExists) Error() string {
|
||||
return "Alias name: " + e.name + " exists"
|
||||
}
|
||||
|
||||
// errInvalidAuthKeys - invalid authorization keys
|
||||
type errInvalidAuthKeys struct{}
|
||||
|
||||
func (e errInvalidAuthKeys) Error() string {
|
||||
return "Invalid authorization keys"
|
||||
}
|
||||
|
||||
type errIsNotBucket struct {
|
||||
path string
|
||||
}
|
||||
|
||||
@@ -192,7 +192,11 @@ func (c *s3Client) getObjectMetadata(bucket, object string) (item *client.Item,
|
||||
if !client.IsValidBucketName(bucket) || strings.Contains(bucket, ".") {
|
||||
return nil, iodine.New(InvalidBucketName{Bucket: bucket}, nil)
|
||||
}
|
||||
req, err := c.newRequest("HEAD", c.objectURL(bucket, object), nil)
|
||||
queryURL := c.objectURL(bucket, object)
|
||||
if !c.isValidQueryURL(queryURL) {
|
||||
return nil, iodine.New(InvalidQueryURL{URL: queryURL}, nil)
|
||||
}
|
||||
req, err := c.newRequest("HEAD", queryURL, nil)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (c *s3Client) bucketURL(bucket string) string {
|
||||
// or write your own certificate verification logic.
|
||||
// =====================
|
||||
//
|
||||
if client.IsValidBucketName(bucket) && !strings.Contains(bucket, ".") {
|
||||
if client.IsValidBucketName(bucket) {
|
||||
// if localhost use PathStyle
|
||||
if strings.Contains(c.Host, "localhost") || strings.Contains(c.Host, "127.0.0.1") {
|
||||
return fmt.Sprintf("%s://%s/%s", c.Scheme, c.Host, bucket)
|
||||
|
||||
@@ -32,10 +32,14 @@ import (
|
||||
// Get - download a requested object from a given bucket
|
||||
func (c *s3Client) Get() (body io.ReadCloser, size int64, md5 string, err error) {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if !client.IsValidBucketName(bucket) || strings.Contains(bucket, ".") {
|
||||
if !client.IsValidBucketName(bucket) {
|
||||
return nil, 0, "", iodine.New(InvalidBucketName{Bucket: bucket}, nil)
|
||||
}
|
||||
req, err := c.newRequest("GET", c.objectURL(bucket, object), nil)
|
||||
queryURL := c.objectURL(bucket, object)
|
||||
if !c.isValidQueryURL(queryURL) {
|
||||
return nil, 0, "", iodine.New(InvalidQueryURL{URL: queryURL}, nil)
|
||||
}
|
||||
req, err := c.newRequest("GET", queryURL, nil)
|
||||
if err != nil {
|
||||
return nil, 0, "", iodine.New(err, nil)
|
||||
}
|
||||
@@ -58,13 +62,17 @@ func (c *s3Client) Get() (body io.ReadCloser, size int64, md5 string, err error)
|
||||
// If length is negative, the rest of the object is returned.
|
||||
func (c *s3Client) GetPartial(offset, length int64) (body io.ReadCloser, size int64, md5 string, err error) {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if !client.IsValidBucketName(bucket) || strings.Contains(bucket, ".") {
|
||||
if !client.IsValidBucketName(bucket) {
|
||||
return nil, 0, "", iodine.New(InvalidBucketName{Bucket: bucket}, nil)
|
||||
}
|
||||
if offset < 0 {
|
||||
return nil, 0, "", iodine.New(client.InvalidRange{Offset: offset}, nil)
|
||||
}
|
||||
req, err := c.newRequest("GET", c.objectURL(bucket, object), nil)
|
||||
queryURL := c.objectURL(bucket, object)
|
||||
if !c.isValidQueryURL(queryURL) {
|
||||
return nil, 0, "", iodine.New(InvalidQueryURL{URL: queryURL}, nil)
|
||||
}
|
||||
req, err := c.newRequest("GET", queryURL, nil)
|
||||
if err != nil {
|
||||
return nil, 0, "", iodine.New(err, nil)
|
||||
}
|
||||
|
||||
@@ -33,9 +33,13 @@ import (
|
||||
// Put - upload new object to bucket
|
||||
func (c *s3Client) Put(md5HexString string, size int64) (io.WriteCloser, error) {
|
||||
bucket, object := c.url2BucketAndObject()
|
||||
if !client.IsValidBucketName(bucket) || strings.Contains(bucket, ".") {
|
||||
if !client.IsValidBucketName(bucket) {
|
||||
return nil, iodine.New(InvalidBucketName{Bucket: bucket}, nil)
|
||||
}
|
||||
queryURL := c.objectURL(bucket, object)
|
||||
if !c.isValidQueryURL(queryURL) {
|
||||
return nil, iodine.New(InvalidQueryURL{URL: queryURL}, nil)
|
||||
}
|
||||
r, w := io.Pipe()
|
||||
blockingWriter := client.NewBlockingWriteCloser(w)
|
||||
go func() {
|
||||
@@ -45,7 +49,7 @@ func (c *s3Client) Put(md5HexString string, size int64) (io.WriteCloser, error)
|
||||
blockingWriter.Release(err)
|
||||
return
|
||||
}
|
||||
req, err := c.newRequest("PUT", c.objectURL(bucket, object), r)
|
||||
req, err := c.newRequest("PUT", queryURL, r)
|
||||
if err != nil {
|
||||
err := iodine.New(err, nil)
|
||||
r.CloseWithError(err)
|
||||
|
||||
Reference in New Issue
Block a user