mirror of
https://github.com/minio/minio.git
synced 2025-03-03 15:20:08 -05:00
Golint cleanup pkg/api
This commit is contained in:
parent
76e601b26b
commit
540723d7ae
@ -41,7 +41,7 @@ var _ = Suite(&MySuite{})
|
|||||||
|
|
||||||
func (s *MySuite) TestNonExistantObject(c *C) {
|
func (s *MySuite) TestNonExistantObject(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ func (s *MySuite) TestNonExistantObject(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestEmptyObject(c *C) {
|
func (s *MySuite) TestEmptyObject(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ func (s *MySuite) TestEmptyObject(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestObject(c *C) {
|
func (s *MySuite) TestObject(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ func (s *MySuite) TestObject(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestMultipleObjects(c *C) {
|
func (s *MySuite) TestMultipleObjects(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ func (s *MySuite) TestMultipleObjects(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestNotImplemented(c *C) {
|
func (s *MySuite) TestNotImplemented(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ func (s *MySuite) TestNotImplemented(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestHeader(c *C) {
|
func (s *MySuite) TestHeader(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ func (s *MySuite) TestHeader(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestPutBucket(c *C) {
|
func (s *MySuite) TestPutBucket(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ func (s *MySuite) TestPutBucket(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestPutObject(c *C) {
|
func (s *MySuite) TestPutObject(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ func (s *MySuite) TestPutObject(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestListBuckets(c *C) {
|
func (s *MySuite) TestListBuckets(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentTy
|
|||||||
|
|
||||||
func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
@ -426,7 +426,7 @@ func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) {
|
|||||||
|
|
||||||
func (s *MySuite) TestContentTypePersists(c *C) {
|
func (s *MySuite) TestContentTypePersists(c *C) {
|
||||||
_, _, storage := inmemory.Start()
|
_, _, storage := inmemory.Start()
|
||||||
httpHandler := HttpHandler("", storage)
|
httpHandler := HTTPHandler("", storage)
|
||||||
testServer := httptest.NewServer(httpHandler)
|
testServer := httptest.NewServer(httpHandler)
|
||||||
defer testServer.Close()
|
defer testServer.Close()
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
// of the objects in a bucket. You can use the request parameters as selection
|
// of the objects in a bucket. You can use the request parameters as selection
|
||||||
// criteria to return a subset of the objects in a bucket.
|
// criteria to return a subset of the objects in a bucket.
|
||||||
//
|
//
|
||||||
func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) listObjectsHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchBucket)
|
error := errorCodeError(NoSuchBucket)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ImplementationError:
|
case mstorage.ImplementationError:
|
||||||
@ -65,21 +65,21 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketNameInvalid:
|
case mstorage.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
error := errorCodeError(InvalidBucketName)
|
error := errorCodeError(InvalidBucketName)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ObjectNameInvalid:
|
case mstorage.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchKey)
|
error := errorCodeError(NoSuchKey)
|
||||||
errorResponse := getErrorResponse(error, resources.Prefix)
|
errorResponse := getErrorResponse(error, resources.Prefix)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ func (server *minioApi) listObjectsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
// -----------
|
// -----------
|
||||||
// This implementation of the GET operation returns a list of all buckets
|
// This implementation of the GET operation returns a list of all buckets
|
||||||
// owned by the authenticated sender of the request.
|
// owned by the authenticated sender of the request.
|
||||||
func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) listBucketsHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
buckets, err := server.storage.ListBuckets()
|
buckets, err := server.storage.ListBuckets()
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
@ -103,7 +103,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, "")
|
errorResponse := getErrorResponse(error, "")
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BackendCorrupted:
|
case mstorage.BackendCorrupted:
|
||||||
@ -111,7 +111,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, "")
|
errorResponse := getErrorResponse(error, "")
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func (server *minioApi) listBucketsHandler(w http.ResponseWriter, req *http.Requ
|
|||||||
// PUT Bucket
|
// PUT Bucket
|
||||||
// ----------
|
// ----------
|
||||||
// This implementation of the PUT operation creates a new bucket for authenticated request
|
// This implementation of the PUT operation creates a new bucket for authenticated request
|
||||||
func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) putBucketHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
err := server.storage.StoreBucket(bucket)
|
err := server.storage.StoreBucket(bucket)
|
||||||
@ -142,14 +142,14 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
{
|
{
|
||||||
error := errorCodeError(InvalidBucketName)
|
error := errorCodeError(InvalidBucketName)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketExists:
|
case mstorage.BucketExists:
|
||||||
{
|
{
|
||||||
error := errorCodeError(BucketAlreadyExists)
|
error := errorCodeError(BucketAlreadyExists)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ImplementationError:
|
case mstorage.ImplementationError:
|
||||||
@ -158,7 +158,7 @@ func (server *minioApi) putBucketHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ type ObjectListResponse struct {
|
|||||||
CommonPrefixes []*Prefix
|
CommonPrefixes []*Prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucket list response format
|
// BucketListResponse - bucket list response format
|
||||||
type BucketListResponse struct {
|
type BucketListResponse struct {
|
||||||
XMLName xml.Name `xml:"ListAllMyBucketsResult" json:"-"`
|
XMLName xml.Name `xml:"ListAllMyBucketsResult" json:"-"`
|
||||||
Owner Owner
|
Owner Owner
|
||||||
@ -47,17 +47,18 @@ type BucketListResponse struct {
|
|||||||
} // Buckets are nested
|
} // Buckets are nested
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prefix - common prefix
|
||||||
type Prefix struct {
|
type Prefix struct {
|
||||||
Prefix string
|
Prefix string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucket struct
|
// Bucket - bucket item
|
||||||
type Bucket struct {
|
type Bucket struct {
|
||||||
Name string
|
Name string
|
||||||
CreationDate string
|
CreationDate string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Object struct
|
// Item - object item
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Key string
|
Key string
|
||||||
LastModified string
|
LastModified string
|
||||||
@ -67,6 +68,7 @@ type Item struct {
|
|||||||
Owner Owner
|
Owner Owner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Owner - bucket owner/principal
|
||||||
type Owner struct {
|
type Owner struct {
|
||||||
ID string
|
ID string
|
||||||
DisplayName string
|
DisplayName string
|
||||||
|
@ -25,17 +25,17 @@ import (
|
|||||||
type Error struct {
|
type Error struct {
|
||||||
Code string
|
Code string
|
||||||
Description string
|
Description string
|
||||||
HttpStatusCode int
|
HTTPStatusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error response format
|
// ErrorResponse - error response format
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
XMLName xml.Name `xml:"Error" json:"-"`
|
XMLName xml.Name `xml:"Error" json:"-"`
|
||||||
Code string
|
Code string
|
||||||
Message string
|
Message string
|
||||||
Resource string
|
Resource string
|
||||||
RequestId string
|
RequestID string
|
||||||
HostId string
|
HostID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error codes, non exhaustive list
|
// Error codes, non exhaustive list
|
||||||
@ -47,7 +47,7 @@ const (
|
|||||||
EntityTooLarge
|
EntityTooLarge
|
||||||
IncompleteBody
|
IncompleteBody
|
||||||
InternalError
|
InternalError
|
||||||
InvalidAccessKeyId
|
InvalidAccessKeyID
|
||||||
InvalidBucketName
|
InvalidBucketName
|
||||||
InvalidDigest
|
InvalidDigest
|
||||||
InvalidRange
|
InvalidRange
|
||||||
@ -70,117 +70,117 @@ var errorCodeResponse = map[int]Error{
|
|||||||
AccessDenied: {
|
AccessDenied: {
|
||||||
Code: "AccessDenied",
|
Code: "AccessDenied",
|
||||||
Description: "Access Denied",
|
Description: "Access Denied",
|
||||||
HttpStatusCode: http.StatusForbidden,
|
HTTPStatusCode: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
BadDigest: {
|
BadDigest: {
|
||||||
Code: "BadDigest",
|
Code: "BadDigest",
|
||||||
Description: "The Content-MD5 you specified did not match what we received.",
|
Description: "The Content-MD5 you specified did not match what we received.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
BucketAlreadyExists: {
|
BucketAlreadyExists: {
|
||||||
Code: "BucketAlreadyExists",
|
Code: "BucketAlreadyExists",
|
||||||
Description: "The requested bucket name is not available.",
|
Description: "The requested bucket name is not available.",
|
||||||
HttpStatusCode: http.StatusConflict,
|
HTTPStatusCode: http.StatusConflict,
|
||||||
},
|
},
|
||||||
EntityTooSmall: {
|
EntityTooSmall: {
|
||||||
Code: "EntityTooSmall",
|
Code: "EntityTooSmall",
|
||||||
Description: "Your proposed upload is smaller than the minimum allowed object size.",
|
Description: "Your proposed upload is smaller than the minimum allowed object size.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
EntityTooLarge: {
|
EntityTooLarge: {
|
||||||
Code: "EntityTooLarge",
|
Code: "EntityTooLarge",
|
||||||
Description: "Your proposed upload exceeds the maximum allowed object size.",
|
Description: "Your proposed upload exceeds the maximum allowed object size.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
IncompleteBody: {
|
IncompleteBody: {
|
||||||
Code: "IncompleteBody",
|
Code: "IncompleteBody",
|
||||||
Description: "You did not provide the number of bytes specified by the Content-Length HTTP header",
|
Description: "You did not provide the number of bytes specified by the Content-Length HTTP header",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
InternalError: {
|
InternalError: {
|
||||||
Code: "InternalError",
|
Code: "InternalError",
|
||||||
Description: "We encountered an internal error, please try again.",
|
Description: "We encountered an internal error, please try again.",
|
||||||
HttpStatusCode: http.StatusInternalServerError,
|
HTTPStatusCode: http.StatusInternalServerError,
|
||||||
},
|
},
|
||||||
InvalidAccessKeyId: {
|
InvalidAccessKeyID: {
|
||||||
Code: "InvalidAccessKeyId",
|
Code: "InvalidAccessKeyID",
|
||||||
Description: "The access key Id you provided does not exist in our records.",
|
Description: "The access key ID you provided does not exist in our records.",
|
||||||
HttpStatusCode: http.StatusForbidden,
|
HTTPStatusCode: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
InvalidBucketName: {
|
InvalidBucketName: {
|
||||||
Code: "InvalidBucketName",
|
Code: "InvalidBucketName",
|
||||||
Description: "The specified bucket is not valid.",
|
Description: "The specified bucket is not valid.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
InvalidDigest: {
|
InvalidDigest: {
|
||||||
Code: "InvalidDigest",
|
Code: "InvalidDigest",
|
||||||
Description: "The Content-MD5 you specified is not valid.",
|
Description: "The Content-MD5 you specified is not valid.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
InvalidRange: {
|
InvalidRange: {
|
||||||
Code: "InvalidRange",
|
Code: "InvalidRange",
|
||||||
Description: "The requested range cannot be satisfied.",
|
Description: "The requested range cannot be satisfied.",
|
||||||
HttpStatusCode: http.StatusRequestedRangeNotSatisfiable,
|
HTTPStatusCode: http.StatusRequestedRangeNotSatisfiable,
|
||||||
},
|
},
|
||||||
MalformedXML: {
|
MalformedXML: {
|
||||||
Code: "MalformedXML",
|
Code: "MalformedXML",
|
||||||
Description: "The XML you provided was not well-formed or did not validate against our published schema.",
|
Description: "The XML you provided was not well-formed or did not validate against our published schema.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
MissingContentLength: {
|
MissingContentLength: {
|
||||||
Code: "MissingContentLength",
|
Code: "MissingContentLength",
|
||||||
Description: "You must provide the Content-Length HTTP header.",
|
Description: "You must provide the Content-Length HTTP header.",
|
||||||
HttpStatusCode: http.StatusLengthRequired,
|
HTTPStatusCode: http.StatusLengthRequired,
|
||||||
},
|
},
|
||||||
MissingRequestBodyError: {
|
MissingRequestBodyError: {
|
||||||
Code: "MissingRequestBodyError",
|
Code: "MissingRequestBodyError",
|
||||||
Description: "Request body is empty.",
|
Description: "Request body is empty.",
|
||||||
HttpStatusCode: http.StatusLengthRequired,
|
HTTPStatusCode: http.StatusLengthRequired,
|
||||||
},
|
},
|
||||||
NoSuchBucket: {
|
NoSuchBucket: {
|
||||||
Code: "NoSuchBucket",
|
Code: "NoSuchBucket",
|
||||||
Description: "The specified bucket does not exist.",
|
Description: "The specified bucket does not exist.",
|
||||||
HttpStatusCode: http.StatusNotFound,
|
HTTPStatusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
NoSuchKey: {
|
NoSuchKey: {
|
||||||
Code: "NoSuchKey",
|
Code: "NoSuchKey",
|
||||||
Description: "The specified key does not exist.",
|
Description: "The specified key does not exist.",
|
||||||
HttpStatusCode: http.StatusNotFound,
|
HTTPStatusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
NoSuchUpload: {
|
NoSuchUpload: {
|
||||||
Code: "NoSuchUpload",
|
Code: "NoSuchUpload",
|
||||||
Description: "The specified multipart upload does not exist.",
|
Description: "The specified multipart upload does not exist.",
|
||||||
HttpStatusCode: http.StatusNotFound,
|
HTTPStatusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
NotImplemented: {
|
NotImplemented: {
|
||||||
Code: "NotImplemented",
|
Code: "NotImplemented",
|
||||||
Description: "A header you provided implies functionality that is not implemented.",
|
Description: "A header you provided implies functionality that is not implemented.",
|
||||||
HttpStatusCode: http.StatusNotImplemented,
|
HTTPStatusCode: http.StatusNotImplemented,
|
||||||
},
|
},
|
||||||
RequestTimeTooSkewed: {
|
RequestTimeTooSkewed: {
|
||||||
Code: "RequestTimeTooSkewed",
|
Code: "RequestTimeTooSkewed",
|
||||||
Description: "The difference between the request time and the server's time is too large.",
|
Description: "The difference between the request time and the server's time is too large.",
|
||||||
HttpStatusCode: http.StatusForbidden,
|
HTTPStatusCode: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
SignatureDoesNotMatch: {
|
SignatureDoesNotMatch: {
|
||||||
Code: "SignatureDoesNotMatch",
|
Code: "SignatureDoesNotMatch",
|
||||||
Description: "The request signature we calculated does not match the signature you provided.",
|
Description: "The request signature we calculated does not match the signature you provided.",
|
||||||
HttpStatusCode: http.StatusForbidden,
|
HTTPStatusCode: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
TooManyBuckets: {
|
TooManyBuckets: {
|
||||||
Code: "TooManyBuckets",
|
Code: "TooManyBuckets",
|
||||||
Description: "You have attempted to create more buckets than allowed.",
|
Description: "You have attempted to create more buckets than allowed.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
InvalidPolicyDocument: {
|
InvalidPolicyDocument: {
|
||||||
Code: "InvalidPolicyDocument",
|
Code: "InvalidPolicyDocument",
|
||||||
Description: "The content of the form does not meet the conditions specified in the policy document.",
|
Description: "The content of the form does not meet the conditions specified in the policy document.",
|
||||||
HttpStatusCode: http.StatusBadRequest,
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
NoSuchBucketPolicy: {
|
NoSuchBucketPolicy: {
|
||||||
Code: "NoSuchBucketPolicy",
|
Code: "NoSuchBucketPolicy",
|
||||||
Description: "The specified bucket does not have a bucket policy.",
|
Description: "The specified bucket does not have a bucket policy.",
|
||||||
HttpStatusCode: http.StatusNotFound,
|
HTTPStatusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,8 +199,8 @@ func getErrorResponse(err Error, resource string) ErrorResponse {
|
|||||||
data.Resource = resource
|
data.Resource = resource
|
||||||
}
|
}
|
||||||
// TODO implement this in future
|
// TODO implement this in future
|
||||||
data.RequestId = "3L137"
|
data.RequestID = "3L137"
|
||||||
data.HostId = "3L137"
|
data.HostID = "3L137"
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -60,14 +60,14 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
if err := h.conf.ReadConfig(); err != nil {
|
if err := h.conf.ReadConfig(); err != nil {
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, "")
|
errorResponse := getErrorResponse(error, "")
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
} else {
|
} else {
|
||||||
user, ok := h.conf.Users[accessKey]
|
user, ok := h.conf.Users[accessKey]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
error := errorCodeError(AccessDenied)
|
error := errorCodeError(AccessDenied)
|
||||||
errorResponse := getErrorResponse(error, "")
|
errorResponse := getErrorResponse(error, "")
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
} else {
|
} else {
|
||||||
ok, _ = signers.ValidateRequest(user, r)
|
ok, _ = signers.ValidateRequest(user, r)
|
||||||
@ -76,7 +76,7 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
} else {
|
} else {
|
||||||
error := errorCodeError(AccessDenied)
|
error := errorCodeError(AccessDenied)
|
||||||
errorResponse := getErrorResponse(error, "")
|
errorResponse := getErrorResponse(error, "")
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
// ## Uncommented below links of code after disabling anonymous requests
|
// ## Uncommented below links of code after disabling anonymous requests
|
||||||
// error := errorCodeError(AccessDenied)
|
// error := errorCodeError(AccessDenied)
|
||||||
// errorResponse := getErrorResponse(error, "")
|
// errorResponse := getErrorResponse(error, "")
|
||||||
// w.WriteHeader(error.HttpStatusCode)
|
// w.WriteHeader(error.HTTPStatusCode)
|
||||||
// w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
// w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ func (h rHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) {
|
if ignoreUnImplementedObjectResources(r) || ignoreUnImplementedBucketResources(r) {
|
||||||
error := errorCodeError(NotImplemented)
|
error := errorCodeError(NotImplemented)
|
||||||
errorResponse := getErrorResponse(error, "")
|
errorResponse := getErrorResponse(error, "")
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
} else {
|
} else {
|
||||||
h.handler.ServeHTTP(w, r)
|
h.handler.ServeHTTP(w, r)
|
||||||
|
@ -26,13 +26,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// private use
|
// private use
|
||||||
type minioApi struct {
|
type minioAPI struct {
|
||||||
domain string
|
domain string
|
||||||
storage mstorage.Storage
|
storage mstorage.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path based routing
|
// Path based routing
|
||||||
func pathMux(api minioApi, mux *x.Router) *x.Router {
|
func pathMux(api minioAPI, mux *x.Router) *x.Router {
|
||||||
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
|
mux.HandleFunc("/", api.listBucketsHandler).Methods("GET")
|
||||||
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
|
mux.HandleFunc("/{bucket}", api.listObjectsHandler).Methods("GET")
|
||||||
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
|
mux.HandleFunc("/{bucket}", api.putBucketHandler).Methods("PUT")
|
||||||
@ -44,7 +44,7 @@ func pathMux(api minioApi, mux *x.Router) *x.Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Domain based routing
|
// Domain based routing
|
||||||
func domainMux(api minioApi, mux *x.Router) *x.Router {
|
func domainMux(api minioAPI, mux *x.Router) *x.Router {
|
||||||
mux.HandleFunc("/",
|
mux.HandleFunc("/",
|
||||||
api.listObjectsHandler).Host("{bucket}" + "." + api.domain).Methods("GET")
|
api.listObjectsHandler).Host("{bucket}" + "." + api.domain).Methods("GET")
|
||||||
mux.HandleFunc("/{object:.*}",
|
mux.HandleFunc("/{object:.*}",
|
||||||
@ -60,7 +60,7 @@ func domainMux(api minioApi, mux *x.Router) *x.Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get proper router based on domain availability
|
// Get proper router based on domain availability
|
||||||
func getMux(api minioApi, mux *x.Router) *x.Router {
|
func getMux(api minioAPI, mux *x.Router) *x.Router {
|
||||||
switch true {
|
switch true {
|
||||||
case api.domain == "":
|
case api.domain == "":
|
||||||
return pathMux(api, mux)
|
return pathMux(api, mux)
|
||||||
@ -71,10 +71,10 @@ func getMux(api minioApi, mux *x.Router) *x.Router {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Http wrapper handler
|
// HTTPHandler - http wrapper handler
|
||||||
func HttpHandler(domain string, storage mstorage.Storage) http.Handler {
|
func HTTPHandler(domain string, storage mstorage.Storage) http.Handler {
|
||||||
var mux *x.Router
|
var mux *x.Router
|
||||||
var api = minioApi{}
|
var api = minioAPI{}
|
||||||
api.storage = storage
|
api.storage = storage
|
||||||
api.domain = domain
|
api.domain = domain
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
// ----------
|
// ----------
|
||||||
// This implementation of the GET operation retrieves object. To use GET,
|
// This implementation of the GET operation retrieves object. To use GET,
|
||||||
// you must have READ access to the object.
|
// you must have READ access to the object.
|
||||||
func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) getObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
var object, bucket string
|
var object, bucket string
|
||||||
|
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
@ -50,21 +50,21 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchKey)
|
error := errorCodeError(NoSuchKey)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ObjectNameInvalid:
|
case mstorage.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchKey)
|
error := errorCodeError(NoSuchKey)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketNameInvalid:
|
case mstorage.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
error := errorCodeError(InvalidBucketName)
|
error := errorCodeError(InvalidBucketName)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ImplementationError:
|
case mstorage.ImplementationError:
|
||||||
@ -73,7 +73,7 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ func (server *minioApi) getObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
// HEAD Object
|
// HEAD Object
|
||||||
// -----------
|
// -----------
|
||||||
// The HEAD operation retrieves metadata from an object without returning the object itself.
|
// The HEAD operation retrieves metadata from an object without returning the object itself.
|
||||||
func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) headObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
var object, bucket string
|
var object, bucket string
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
@ -97,14 +97,14 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchKey)
|
error := errorCodeError(NoSuchKey)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ObjectNameInvalid:
|
case mstorage.ObjectNameInvalid:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchKey)
|
error := errorCodeError(NoSuchKey)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ImplementationError:
|
case mstorage.ImplementationError:
|
||||||
@ -113,7 +113,7 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ func (server *minioApi) headObjectHandler(w http.ResponseWriter, req *http.Reque
|
|||||||
// PUT Object
|
// PUT Object
|
||||||
// ----------
|
// ----------
|
||||||
// This implementation of the PUT operation adds an object to a bucket.
|
// This implementation of the PUT operation adds an object to a bucket.
|
||||||
func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) putObjectHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
var object, bucket string
|
var object, bucket string
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
@ -146,28 +146,28 @@ func (server *minioApi) putObjectHandler(w http.ResponseWriter, req *http.Reques
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketNotFound:
|
case mstorage.BucketNotFound:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchBucket)
|
error := errorCodeError(NoSuchBucket)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketNameInvalid:
|
case mstorage.BucketNameInvalid:
|
||||||
{
|
{
|
||||||
error := errorCodeError(InvalidBucketName)
|
error := errorCodeError(InvalidBucketName)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.ObjectExists:
|
case mstorage.ObjectExists:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NotImplemented)
|
error := errorCodeError(NotImplemented)
|
||||||
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
errorResponse := getErrorResponse(error, "/"+bucket+"/"+object)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
// -----------------
|
// -----------------
|
||||||
// This implementation of the PUT operation uses the policy subresource
|
// This implementation of the PUT operation uses the policy subresource
|
||||||
// to add to or replace a policy on a bucket
|
// to add to or replace a policy on a bucket
|
||||||
func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) putBucketPolicyHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
@ -39,7 +39,7 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
if ok == false {
|
if ok == false {
|
||||||
error := errorCodeError(InvalidPolicyDocument)
|
error := errorCodeError(InvalidPolicyDocument)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -56,14 +56,14 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
{
|
{
|
||||||
error := errorCodeError(InvalidBucketName)
|
error := errorCodeError(InvalidBucketName)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketNotFound:
|
case mstorage.BucketNotFound:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchBucket)
|
error := errorCodeError(NoSuchBucket)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BackendCorrupted:
|
case mstorage.BackendCorrupted:
|
||||||
@ -72,7 +72,7 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ func (server *minioApi) putBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
// -----------------
|
// -----------------
|
||||||
// This implementation of the GET operation uses the policy subresource
|
// This implementation of the GET operation uses the policy subresource
|
||||||
// to return the policy of a specified bucket.
|
// to return the policy of a specified bucket.
|
||||||
func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http.Request) {
|
func (server *minioAPI) getBucketPolicyHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
bucket := vars["bucket"]
|
bucket := vars["bucket"]
|
||||||
acceptsContentType := getContentType(req)
|
acceptsContentType := getContentType(req)
|
||||||
@ -95,7 +95,7 @@ func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
if ret != nil {
|
if ret != nil {
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
writeCommonHeaders(w, getContentString(acceptsContentType))
|
writeCommonHeaders(w, getContentString(acceptsContentType))
|
||||||
@ -106,21 +106,21 @@ func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
{
|
{
|
||||||
error := errorCodeError(InvalidBucketName)
|
error := errorCodeError(InvalidBucketName)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketNotFound:
|
case mstorage.BucketNotFound:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchBucket)
|
error := errorCodeError(NoSuchBucket)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BucketPolicyNotFound:
|
case mstorage.BucketPolicyNotFound:
|
||||||
{
|
{
|
||||||
error := errorCodeError(NoSuchBucketPolicy)
|
error := errorCodeError(NoSuchBucketPolicy)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
case mstorage.BackendCorrupted:
|
case mstorage.BackendCorrupted:
|
||||||
@ -129,7 +129,7 @@ func (server *minioApi) getBucketPolicyHandler(w http.ResponseWriter, req *http.
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
error := errorCodeError(InternalError)
|
error := errorCodeError(InternalError)
|
||||||
errorResponse := getErrorResponse(error, bucket)
|
errorResponse := getErrorResponse(error, bucket)
|
||||||
w.WriteHeader(error.HttpStatusCode)
|
w.WriteHeader(error.HTTPStatusCode)
|
||||||
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
w.Write(writeErrorResponse(w, errorResponse, acceptsContentType))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,16 +54,16 @@ func generateBucketsListResult(buckets []mstorage.BucketMetadata) BucketListResp
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemKey []*Item
|
type itemKey []*Item
|
||||||
|
|
||||||
// Len
|
// Len
|
||||||
func (b ItemKey) Len() int { return len(b) }
|
func (b itemKey) Len() int { return len(b) }
|
||||||
|
|
||||||
// Swap
|
// Swap
|
||||||
func (b ItemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
func (b itemKey) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
|
|
||||||
// Less
|
// Less
|
||||||
func (b ItemKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
func (b itemKey) Less(i, j int) bool { return b[i].Key < b[j].Key }
|
||||||
|
|
||||||
// takes a set of objects and prepares the objects for serialization
|
// takes a set of objects and prepares the objects for serialization
|
||||||
// input:
|
// input:
|
||||||
@ -95,7 +95,7 @@ func generateObjectsListResult(bucket string, objects []mstorage.ObjectMetadata,
|
|||||||
content.Owner = owner
|
content.Owner = owner
|
||||||
contents = append(contents, content)
|
contents = append(contents, content)
|
||||||
}
|
}
|
||||||
sort.Sort(ItemKey(contents))
|
sort.Sort(itemKey(contents))
|
||||||
data.Name = bucket
|
data.Name = bucket
|
||||||
data.Contents = contents
|
data.Contents = contents
|
||||||
data.MaxKeys = bucketResources.Maxkeys
|
data.MaxKeys = bucketResources.Maxkeys
|
||||||
|
@ -29,10 +29,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DEFAULT_WEB = "polygon"
|
defaultWeb = "polygon"
|
||||||
)
|
)
|
||||||
|
|
||||||
type webUiApi struct {
|
type webAPI struct {
|
||||||
conf config.Config
|
conf config.Config
|
||||||
webPath string
|
webPath string
|
||||||
}
|
}
|
||||||
@ -42,16 +42,16 @@ type encoder interface {
|
|||||||
Encode(v interface{}) error
|
Encode(v interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Http wrapper handler
|
// HTTPHandler - http wrapper handler
|
||||||
func HttpHandler() http.Handler {
|
func HTTPHandler() http.Handler {
|
||||||
mux := mux.NewRouter()
|
mux := mux.NewRouter()
|
||||||
var api = webUiApi{}
|
var api = webAPI{}
|
||||||
|
|
||||||
if err := api.conf.SetupConfig(); err != nil {
|
if err := api.conf.SetupConfig(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
api.webPath = path.Join(api.conf.GetConfigPath(), DEFAULT_WEB)
|
api.webPath = path.Join(api.conf.GetConfigPath(), defaultWeb)
|
||||||
mux.Handle("/{polygon:.*}", http.FileServer(http.Dir(api.webPath))).Methods("GET")
|
mux.Handle("/{polygon:.*}", http.FileServer(http.Dir(api.webPath))).Methods("GET")
|
||||||
mux.HandleFunc("/access", api.accessHandler).Methods("POST")
|
mux.HandleFunc("/access", api.accessHandler).Methods("POST")
|
||||||
return mux
|
return mux
|
||||||
@ -68,7 +68,7 @@ func writeResponse(w http.ResponseWriter, response interface{}) []byte {
|
|||||||
return bytesBuffer.Bytes()
|
return bytesBuffer.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) {
|
func (web *webAPI) accessHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
var err error
|
var err error
|
||||||
var accesskey, secretkey []byte
|
var accesskey, secretkey []byte
|
||||||
username := req.FormValue("username")
|
username := req.FormValue("username")
|
||||||
|
@ -19,21 +19,22 @@ package httpserver
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
// "time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HttpServerConfig struct {
|
// Config - http server config
|
||||||
|
type Config struct {
|
||||||
Address string
|
Address string
|
||||||
TLS bool
|
TLS bool
|
||||||
CertFile string
|
CertFile string
|
||||||
KeyFile string
|
KeyFile string
|
||||||
Websocket bool // implement it - TODO
|
Websocket bool // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
type HttpServer struct{}
|
// Server - http server related
|
||||||
|
type Server struct{}
|
||||||
|
|
||||||
// Start http server
|
// Start http server
|
||||||
func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan error, *HttpServer) {
|
func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan error, *Server) {
|
||||||
ctrlChannel := make(chan string)
|
ctrlChannel := make(chan string)
|
||||||
errorChannel := make(chan error)
|
errorChannel := make(chan error)
|
||||||
server := HttpServer{}
|
server := HttpServer{}
|
||||||
@ -42,7 +43,7 @@ func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
func start(ctrlChannel <-chan string, errorChannel chan<- error,
|
func start(ctrlChannel <-chan string, errorChannel chan<- error,
|
||||||
router http.Handler, config HttpServerConfig, server *HttpServer) {
|
router http.Handler, config Config, server *Server) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Minio server config
|
// Minio server config
|
||||||
|
@ -30,31 +30,37 @@ import (
|
|||||||
"github.com/minio-io/minio/pkg/storage/inmemory"
|
"github.com/minio-io/minio/pkg/storage/inmemory"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerConfig struct {
|
// Config - http server parameters
|
||||||
|
type Config struct {
|
||||||
Domain string
|
Domain string
|
||||||
Address string
|
Address string
|
||||||
Tls bool
|
TLS bool
|
||||||
CertFile string
|
CertFile string
|
||||||
KeyFile string
|
KeyFile string
|
||||||
ApiType interface{}
|
APIType interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MinioApi struct {
|
// MinioAPI - storage type donut, fs, inmemory
|
||||||
|
type MinioAPI struct {
|
||||||
StorageType StorageType
|
StorageType StorageType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebUIApi - webui related
|
||||||
type WebUIApi struct {
|
type WebUIApi struct {
|
||||||
Websocket bool
|
Websocket bool // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StorageType - different storage types supported by minio
|
||||||
type StorageType int
|
type StorageType int
|
||||||
|
|
||||||
|
// Storage types
|
||||||
const (
|
const (
|
||||||
InMemoryStorage = iota
|
InMemory = iota
|
||||||
FileStorage
|
File
|
||||||
|
Donut
|
||||||
)
|
)
|
||||||
|
|
||||||
func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusChans []<-chan error) {
|
func getHTTPChannels(configs []Config) (ctrlChans []chan<- string, statusChans []<-chan error) {
|
||||||
// a pair of control channels, we use these primarily to add to the lists above
|
// a pair of control channels, we use these primarily to add to the lists above
|
||||||
var ctrlChan chan<- string
|
var ctrlChan chan<- string
|
||||||
var statusChan <-chan error
|
var statusChan <-chan error
|
||||||
@ -65,7 +71,7 @@ func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusC
|
|||||||
{
|
{
|
||||||
// configure web server
|
// configure web server
|
||||||
var storage mstorage.Storage
|
var storage mstorage.Storage
|
||||||
var httpConfig = httpserver.HttpServerConfig{}
|
var httpConfig = httpserver.Config{}
|
||||||
httpConfig.Address = config.Address
|
httpConfig.Address = config.Address
|
||||||
httpConfig.Websocket = false
|
httpConfig.Websocket = false
|
||||||
httpConfig.TLS = config.Tls
|
httpConfig.TLS = config.Tls
|
||||||
@ -87,7 +93,7 @@ func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusC
|
|||||||
}
|
}
|
||||||
case WebUIApi:
|
case WebUIApi:
|
||||||
{
|
{
|
||||||
var httpConfig = httpserver.HttpServerConfig{}
|
var httpConfig = httpserver.Config{}
|
||||||
httpConfig.Address = config.Address
|
httpConfig.Address = config.Address
|
||||||
httpConfig.TLS = config.Tls
|
httpConfig.TLS = config.Tls
|
||||||
httpConfig.CertFile = config.CertFile
|
httpConfig.CertFile = config.CertFile
|
||||||
@ -120,13 +126,13 @@ func getStorageChannels(storageType StorageType) (ctrlChans []chan<- string, sta
|
|||||||
// - ctrlChans has channel to communicate to storage
|
// - ctrlChans has channel to communicate to storage
|
||||||
// - statusChans has channel for messages coming from storage
|
// - statusChans has channel for messages coming from storage
|
||||||
switch {
|
switch {
|
||||||
case storageType == InMemoryStorage:
|
case storageType == InMemory:
|
||||||
{
|
{
|
||||||
ctrlChan, statusChan, storage = inmemory.Start()
|
ctrlChan, statusChan, storage = inmemory.Start()
|
||||||
ctrlChans = append(ctrlChans, ctrlChan)
|
ctrlChans = append(ctrlChans, ctrlChan)
|
||||||
statusChans = append(statusChans, statusChan)
|
statusChans = append(statusChans, statusChan)
|
||||||
}
|
}
|
||||||
case storageType == FileStorage:
|
case storageType == File:
|
||||||
{
|
{
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -143,10 +149,10 @@ func getStorageChannels(storageType StorageType) (ctrlChans []chan<- string, sta
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create channels
|
// Start - create channels
|
||||||
func Start(configs []ServerConfig) {
|
func Start(configs []Config) {
|
||||||
// reflected looping is necessary to remove dead channels from loop and not flood switch
|
// reflected looping is necessary to remove dead channels from loop and not flood switch
|
||||||
ctrlChans, statusChans := getHttpChannels(configs)
|
ctrlChans, statusChans := getHTTPChannels(configs)
|
||||||
cases := createSelectCases(statusChans)
|
cases := createSelectCases(statusChans)
|
||||||
for len(cases) > 0 {
|
for len(cases) > 0 {
|
||||||
chosen, value, recvOk := reflect.Select(cases)
|
chosen, value, recvOk := reflect.Select(cases)
|
||||||
|
@ -495,7 +495,7 @@ func (storage *storage) StoreObject(bucket, key, contentType string, data io.Rea
|
|||||||
if _, err := os.Stat(objectPath); !os.IsNotExist(err) {
|
if _, err := os.Stat(objectPath); !os.IsNotExist(err) {
|
||||||
return mstorage.ObjectExists{
|
return mstorage.ObjectExists{
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Key: key,
|
Object: key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,12 +78,12 @@ func (storage *storage) CopyObjectToWriter(w io.Writer, bucket string, object st
|
|||||||
|
|
||||||
// Not implemented
|
// Not implemented
|
||||||
func (storage *storage) StoreBucketPolicy(bucket string, policy interface{}) error {
|
func (storage *storage) StoreBucketPolicy(bucket string, policy interface{}) error {
|
||||||
return mstorage.ApiNotImplemented{Api: "PutBucketPolicy"}
|
return mstorage.APINotImplemented{API: "PutBucketPolicy"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not implemented
|
// Not implemented
|
||||||
func (storage *storage) GetBucketPolicy(bucket string) (interface{}, error) {
|
func (storage *storage) GetBucketPolicy(bucket string) (interface{}, error) {
|
||||||
return policy.BucketPolicy{}, mstorage.ApiNotImplemented{Api: "GetBucketPolicy"}
|
return policy.BucketPolicy{}, mstorage.APINotImplemented{API: "GetBucketPolicy"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT object to memory buffer
|
// PUT object to memory buffer
|
||||||
@ -98,7 +98,7 @@ func (storage *storage) StoreObject(bucket, key, contentType string, data io.Rea
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := storage.objectdata[objectKey]; ok == true {
|
if _, ok := storage.objectdata[objectKey]; ok == true {
|
||||||
return mstorage.ObjectExists{Bucket: bucket, Key: key}
|
return mstorage.ObjectExists{Bucket: bucket, Object: key}
|
||||||
}
|
}
|
||||||
|
|
||||||
if contentType == "" {
|
if contentType == "" {
|
||||||
|
@ -106,7 +106,7 @@ func (e ObjectNotFound) Error() string {
|
|||||||
|
|
||||||
// Return string an error formatted as the given text
|
// Return string an error formatted as the given text
|
||||||
func (e APINotImplemented) Error() string {
|
func (e APINotImplemented) Error() string {
|
||||||
return "Api not implemented: " + e.Api
|
return "Api not implemented: " + e.API
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return string an error formatted as the given text
|
// Return string an error formatted as the given text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user