From 7ce3ab3193d5048709e4a6be0b8ee257698fbe70 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 18 Mar 2015 17:49:33 -0700 Subject: [PATCH] Restructure minio api, move signature checks from utils to Api. --- .gitignore | 4 +-- main.go | 2 +- ...ket_handlers.go => api_bucket_handlers.go} | 2 +- .../definitions.go => api_definitions.go} | 2 +- ...ic_handlers.go => api_generic_handlers.go} | 5 ++- .../object_handlers.go => api_object.go} | 2 +- .../policy_handlers.go => api_policy.go} | 2 +- .../{minioapi/response.go => api_response.go} | 2 +- pkg/api/{minioapi/router.go => api_router.go} | 2 +- .../signers.go => api/api_signature.go} | 2 +- pkg/api/{minioapi => }/api_test.go | 32 +++++++++---------- pkg/api/{minioapi => }/contenttype.go | 2 +- .../{minioapi/error_response.go => errors.go} | 2 +- pkg/api/{minioapi => }/headers.go | 2 +- pkg/api/{minioapi => }/range.go | 2 +- pkg/api/{minioapi => }/resources.go | 2 +- pkg/api/{webuiapi/webuiapi.go => web/web.go} | 2 +- pkg/server/server.go | 14 ++++---- 18 files changed, 41 insertions(+), 42 deletions(-) rename pkg/api/{minioapi/bucket_handlers.go => api_bucket_handlers.go} (99%) rename pkg/api/{minioapi/definitions.go => api_definitions.go} (99%) rename pkg/api/{minioapi/generic_handlers.go => api_generic_handlers.go} (97%) rename pkg/api/{minioapi/object_handlers.go => api_object.go} (99%) rename pkg/api/{minioapi/policy_handlers.go => api_policy.go} (99%) rename pkg/api/{minioapi/response.go => api_response.go} (99%) rename pkg/api/{minioapi/router.go => api_router.go} (99%) rename pkg/{utils/crypto/signers/signers.go => api/api_signature.go} (99%) rename pkg/api/{minioapi => }/api_test.go (94%) rename pkg/api/{minioapi => }/contenttype.go (98%) rename pkg/api/{minioapi/error_response.go => errors.go} (99%) rename pkg/api/{minioapi => }/headers.go (99%) rename pkg/api/{minioapi => }/range.go (99%) rename pkg/api/{minioapi => }/resources.go (98%) rename pkg/api/{webuiapi/webuiapi.go => web/web.go} (99%) diff --git a/.gitignore b/.gitignore index a65e9db87..17e37e08d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,10 @@ **/*.swp -site/ cover.out *~ minio +!*/ +site/ **/*.test **/*.sublime-workspace -verifier /.idea/ /Minio.iml diff --git a/main.go b/main.go index 1a4787d0f..b9605c5b0 100644 --- a/main.go +++ b/main.go @@ -68,7 +68,7 @@ func runCmd(c *cli.Context) { TLS: false, CertFile: "", KeyFile: "", - APIType: server.WebAPI{ + APIType: server.Web{ Websocket: false, }, } diff --git a/pkg/api/minioapi/bucket_handlers.go b/pkg/api/api_bucket_handlers.go similarity index 99% rename from pkg/api/minioapi/bucket_handlers.go rename to pkg/api/api_bucket_handlers.go index 8804a7483..c90410710 100644 --- a/pkg/api/minioapi/bucket_handlers.go +++ b/pkg/api/api_bucket_handlers.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "log" diff --git a/pkg/api/minioapi/definitions.go b/pkg/api/api_definitions.go similarity index 99% rename from pkg/api/minioapi/definitions.go rename to pkg/api/api_definitions.go index ac2a5d11b..bc42e4a99 100644 --- a/pkg/api/minioapi/definitions.go +++ b/pkg/api/api_definitions.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "encoding/xml" diff --git a/pkg/api/minioapi/generic_handlers.go b/pkg/api/api_generic_handlers.go similarity index 97% rename from pkg/api/minioapi/generic_handlers.go rename to pkg/api/api_generic_handlers.go index 78865de83..93ab2608e 100644 --- a/pkg/api/minioapi/generic_handlers.go +++ b/pkg/api/api_generic_handlers.go @@ -14,14 +14,13 @@ * limitations under the License. */ -package minioapi +package api import ( "net/http" "strings" "github.com/minio-io/minio/pkg/utils/config" - "github.com/minio-io/minio/pkg/utils/crypto/signers" ) type vHandler struct { @@ -70,7 +69,7 @@ func (h vHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.WriteHeader(error.HTTPStatusCode) w.Write(writeErrorResponse(w, errorResponse, acceptsContentType)) } else { - ok, _ = signers.ValidateRequest(user, r) + ok, _ = ValidateRequest(user, r) if ok { h.handler.ServeHTTP(w, r) } else { diff --git a/pkg/api/minioapi/object_handlers.go b/pkg/api/api_object.go similarity index 99% rename from pkg/api/minioapi/object_handlers.go rename to pkg/api/api_object.go index 5e46a5a94..5aafcb710 100644 --- a/pkg/api/minioapi/object_handlers.go +++ b/pkg/api/api_object.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "log" diff --git a/pkg/api/minioapi/policy_handlers.go b/pkg/api/api_policy.go similarity index 99% rename from pkg/api/minioapi/policy_handlers.go rename to pkg/api/api_policy.go index 526e5ca48..560a3ec13 100644 --- a/pkg/api/minioapi/policy_handlers.go +++ b/pkg/api/api_policy.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "encoding/json" diff --git a/pkg/api/minioapi/response.go b/pkg/api/api_response.go similarity index 99% rename from pkg/api/minioapi/response.go rename to pkg/api/api_response.go index 44ae9a7a8..bf69f74da 100644 --- a/pkg/api/minioapi/response.go +++ b/pkg/api/api_response.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "sort" diff --git a/pkg/api/minioapi/router.go b/pkg/api/api_router.go similarity index 99% rename from pkg/api/minioapi/router.go rename to pkg/api/api_router.go index bdd2f06b1..62343c4ba 100644 --- a/pkg/api/minioapi/router.go +++ b/pkg/api/api_router.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "log" diff --git a/pkg/utils/crypto/signers/signers.go b/pkg/api/api_signature.go similarity index 99% rename from pkg/utils/crypto/signers/signers.go rename to pkg/api/api_signature.go index 2692a6360..4c8fd6f63 100644 --- a/pkg/utils/crypto/signers/signers.go +++ b/pkg/api/api_signature.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package signers +package api import ( "bytes" diff --git a/pkg/api/minioapi/api_test.go b/pkg/api/api_test.go similarity index 94% rename from pkg/api/minioapi/api_test.go rename to pkg/api/api_test.go index 735fa04dc..519d83963 100644 --- a/pkg/api/minioapi/api_test.go +++ b/pkg/api/api_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi_test +package api_test import ( "bytes" @@ -28,7 +28,7 @@ import ( "testing" "time" - "github.com/minio-io/minio/pkg/api/minioapi" + "github.com/minio-io/minio/pkg/api" mstorage "github.com/minio-io/minio/pkg/storage" "github.com/minio-io/minio/pkg/storage/memory" @@ -43,7 +43,7 @@ var _ = Suite(&MySuite{}) func (s *MySuite) TestNonExistantObject(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -55,7 +55,7 @@ func (s *MySuite) TestNonExistantObject(c *C) { func (s *MySuite) TestEmptyObject(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -80,7 +80,7 @@ func (s *MySuite) TestEmptyObject(c *C) { func (s *MySuite) TestObject(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -103,7 +103,7 @@ func (s *MySuite) TestObject(c *C) { func (s *MySuite) TestMultipleObjects(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -183,7 +183,7 @@ func (s *MySuite) TestMultipleObjects(c *C) { func (s *MySuite) TestNotImplemented(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -194,7 +194,7 @@ func (s *MySuite) TestNotImplemented(c *C) { func (s *MySuite) TestHeader(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -217,7 +217,7 @@ func (s *MySuite) TestHeader(c *C) { func (s *MySuite) TestPutBucket(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -242,7 +242,7 @@ func (s *MySuite) TestPutBucket(c *C) { func (s *MySuite) TestPutObject(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -299,7 +299,7 @@ func (s *MySuite) TestPutObject(c *C) { func (s *MySuite) TestListBuckets(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -339,8 +339,8 @@ func (s *MySuite) TestListBuckets(c *C) { c.Assert(listResponse.Buckets.Bucket[1].Name, Equals, "foo") } -func readListBucket(reader io.Reader) (minioapi.BucketListResponse, error) { - var results minioapi.BucketListResponse +func readListBucket(reader io.Reader) (api.BucketListResponse, error) { + var results api.BucketListResponse decoder := xml.NewDecoder(reader) err := decoder.Decode(&results) return results, err @@ -378,7 +378,7 @@ func verifyHeaders(c *C, header http.Header, date time.Time, size int, contentTy func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -403,7 +403,7 @@ func (s *MySuite) TestXMLNameNotInBucketListJson(c *C) { func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() @@ -428,7 +428,7 @@ func (s *MySuite) TestXMLNameNotInObjectListJson(c *C) { func (s *MySuite) TestContentTypePersists(c *C) { _, _, storage := memory.Start() - httpHandler := minioapi.HTTPHandler("", storage) + httpHandler := api.HTTPHandler("", storage) testServer := httptest.NewServer(httpHandler) defer testServer.Close() diff --git a/pkg/api/minioapi/contenttype.go b/pkg/api/contenttype.go similarity index 98% rename from pkg/api/minioapi/contenttype.go rename to pkg/api/contenttype.go index efe0c1897..111fd560b 100644 --- a/pkg/api/minioapi/contenttype.go +++ b/pkg/api/contenttype.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "net/http" diff --git a/pkg/api/minioapi/error_response.go b/pkg/api/errors.go similarity index 99% rename from pkg/api/minioapi/error_response.go rename to pkg/api/errors.go index e175cf991..68da5e837 100644 --- a/pkg/api/minioapi/error_response.go +++ b/pkg/api/errors.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "encoding/xml" diff --git a/pkg/api/minioapi/headers.go b/pkg/api/headers.go similarity index 99% rename from pkg/api/minioapi/headers.go rename to pkg/api/headers.go index 0f51ce08e..0d1b9a8e5 100644 --- a/pkg/api/minioapi/headers.go +++ b/pkg/api/headers.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "bytes" diff --git a/pkg/api/minioapi/range.go b/pkg/api/range.go similarity index 99% rename from pkg/api/minioapi/range.go rename to pkg/api/range.go index 0c4f3793b..2f9c0e41c 100644 --- a/pkg/api/minioapi/range.go +++ b/pkg/api/range.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "errors" diff --git a/pkg/api/minioapi/resources.go b/pkg/api/resources.go similarity index 98% rename from pkg/api/minioapi/resources.go rename to pkg/api/resources.go index a38d2e53f..075529f4c 100644 --- a/pkg/api/minioapi/resources.go +++ b/pkg/api/resources.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package minioapi +package api import ( "net/url" diff --git a/pkg/api/webuiapi/webuiapi.go b/pkg/api/web/web.go similarity index 99% rename from pkg/api/webuiapi/webuiapi.go rename to pkg/api/web/web.go index d02b28981..5e2ae7931 100644 --- a/pkg/api/webuiapi/webuiapi.go +++ b/pkg/api/web/web.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package webuiapi +package web import ( "bytes" diff --git a/pkg/server/server.go b/pkg/server/server.go index 1d93d8685..2138865f6 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -22,8 +22,8 @@ import ( "path" "reflect" - "github.com/minio-io/minio/pkg/api/minioapi" - "github.com/minio-io/minio/pkg/api/webuiapi" + "github.com/minio-io/minio/pkg/api" + "github.com/minio-io/minio/pkg/api/web" "github.com/minio-io/minio/pkg/server/httpserver" mstorage "github.com/minio-io/minio/pkg/storage" "github.com/minio-io/minio/pkg/storage/file" @@ -45,8 +45,8 @@ type MinioAPI struct { StorageType StorageType } -// WebAPI - webui related -type WebAPI struct { +// Web - web related +type Web struct { Websocket bool // TODO } @@ -85,13 +85,13 @@ func getHTTPChannels(configs []Config) (ctrlChans []chan<- string, statusChans [ ctrlChans, statusChans, storage = getStorageChannels(k.StorageType) // start minio api in a web server, pass storage driver into it - ctrlChan, statusChan, _ = httpserver.Start(minioapi.HTTPHandler(config.Domain, storage), httpConfig) + ctrlChan, statusChan, _ = httpserver.Start(api.HTTPHandler(config.Domain, storage), httpConfig) ctrlChans = append(ctrlChans, ctrlChan) statusChans = append(statusChans, statusChan) } - case WebAPI: + case Web: { var httpConfig = httpserver.Config{} httpConfig.Address = config.Address @@ -100,7 +100,7 @@ func getHTTPChannels(configs []Config) (ctrlChans []chan<- string, statusChans [ httpConfig.KeyFile = config.KeyFile httpConfig.Websocket = k.Websocket - ctrlChan, statusChan, _ = httpserver.Start(webuiapi.HTTPHandler(), httpConfig) + ctrlChan, statusChan, _ = httpserver.Start(web.HTTPHandler(), httpConfig) ctrlChans = append(ctrlChans, ctrlChan) statusChans = append(statusChans, statusChan)