Refactor to move config handling into api/

master
Harshavardhana 10 years ago
parent b61daa0f87
commit a1baed3bbc
  1. 2
      pkg/api/api_generic_handlers.go
  2. 0
      pkg/api/api_object_handlers.go
  3. 0
      pkg/api/api_policy_handlers.go
  4. 14
      pkg/api/api_router.go
  5. 13
      pkg/api/api_signature.go
  6. 0
      pkg/api/config/config.go
  7. 11
      pkg/api/config/config_test.go
  8. 2
      pkg/api/web/web.go

@ -20,7 +20,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/minio-io/minio/pkg/utils/config" "github.com/minio-io/minio/pkg/api/config"
) )
type vHandler struct { type vHandler struct {

@ -20,9 +20,9 @@ import (
"log" "log"
"net/http" "net/http"
x "github.com/gorilla/mux" router "github.com/gorilla/mux"
"github.com/minio-io/minio/pkg/api/config"
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
"github.com/minio-io/minio/pkg/utils/config"
) )
// private use // private use
@ -32,7 +32,7 @@ type minioAPI struct {
} }
// Path based routing // Path based routing
func pathMux(api minioAPI, mux *x.Router) *x.Router { func pathMux(api minioAPI, mux *router.Router) *router.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 *router.Router) *router.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 *router.Router) *router.Router {
switch true { switch true {
case api.domain == "": case api.domain == "":
return pathMux(api, mux) return pathMux(api, mux)
@ -73,12 +73,12 @@ func getMux(api minioAPI, mux *x.Router) *x.Router {
// HTTPHandler - 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 *router.Router
var api = minioAPI{} var api = minioAPI{}
api.storage = storage api.storage = storage
api.domain = domain api.domain = domain
r := x.NewRouter() r := router.NewRouter()
mux = getMux(api, r) mux = getMux(api, r)
var conf = config.Config{} var conf = config.Config{}

@ -18,20 +18,21 @@ package api
import ( import (
"bytes" "bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"errors" "errors"
"fmt" "fmt"
"io" "io"
"net" "net"
"net/http"
"net/url"
"sort" "sort"
"strings" "strings"
"time" "time"
"github.com/minio-io/minio/pkg/utils/config" "crypto/hmac"
"crypto/sha1"
"encoding/base64"
"net/http"
"net/url"
"github.com/minio-io/minio/pkg/api/config"
) )
// SignRequest - a given http request using HMAC style signatures // SignRequest - a given http request using HMAC style signatures

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package config_test package config
import ( import (
"io/ioutil" "io/ioutil"
@ -23,7 +23,6 @@ import (
"sync" "sync"
"testing" "testing"
"github.com/minio-io/minio/pkg/utils/config"
"github.com/minio-io/minio/pkg/utils/crypto/keys" "github.com/minio-io/minio/pkg/utils/crypto/keys"
. "gopkg.in/check.v1" . "gopkg.in/check.v1"
) )
@ -35,7 +34,8 @@ var _ = Suite(&MySuite{})
func Test(t *testing.T) { TestingT(t) } func Test(t *testing.T) { TestingT(t) }
func (s *MySuite) TestConfig(c *C) { func (s *MySuite) TestConfig(c *C) {
conf := config.Config{} conf := Config{}
conf.ConfigLock = new(sync.RWMutex)
conf.ConfigPath, _ = ioutil.TempDir("/tmp", "minio-test-") conf.ConfigPath, _ = ioutil.TempDir("/tmp", "minio-test-")
defer os.RemoveAll(conf.ConfigPath) defer os.RemoveAll(conf.ConfigPath)
conf.ConfigFile = path.Join(conf.ConfigPath, "config.json") conf.ConfigFile = path.Join(conf.ConfigPath, "config.json")
@ -45,12 +45,11 @@ func (s *MySuite) TestConfig(c *C) {
c.Fatal(err) c.Fatal(err)
} }
} }
conf.ConfigLock = new(sync.RWMutex)
accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID) accesskey, _ := keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
secretkey, _ := keys.GenerateRandomBase64(keys.MinioSecretID) secretkey, _ := keys.GenerateRandomBase64(keys.MinioSecretID)
user := config.User{ user := User{
Name: "gnubot", Name: "gnubot",
AccessKey: string(accesskey), AccessKey: string(accesskey),
SecretKey: string(secretkey), SecretKey: string(secretkey),
@ -65,7 +64,7 @@ func (s *MySuite) TestConfig(c *C) {
accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID) accesskey, _ = keys.GenerateRandomAlphaNumeric(keys.MinioAccessID)
secretkey, _ = keys.GenerateRandomBase64(keys.MinioSecretID) secretkey, _ = keys.GenerateRandomBase64(keys.MinioSecretID)
user = config.User{ user = User{
Name: "minio", Name: "minio",
AccessKey: string(accesskey), AccessKey: string(accesskey),
SecretKey: string(secretkey), SecretKey: string(secretkey),

@ -24,7 +24,7 @@ import (
"path" "path"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/minio-io/minio/pkg/utils/config" "github.com/minio-io/minio/pkg/api/config"
"github.com/minio-io/minio/pkg/utils/crypto/keys" "github.com/minio-io/minio/pkg/utils/crypto/keys"
) )

Loading…
Cancel
Save