Service a new WebUI server at port 8081.

It is provided to avoid the router clutter on the Object API
end. This is just a first cut sample we are going to build on
top of this the new management console UI.

General interest comes from subsequently writing a small UI to
generate `AccessKey` and `SecretKey` to build authorization
layer.
master
Harshavardhana 10 years ago
parent 392ca7451f
commit e1b3836c60
  1. 95
      main.go
  2. 0
      pkg/api/minioapi/definitions.go
  3. 0
      pkg/api/minioapi/minioapi.go
  4. 0
      pkg/api/minioapi/minioapi_test.go
  5. 46
      pkg/api/webuiapi/webuiapi.go
  6. 4
      pkg/httpserver/httpserver.go
  7. 69
      pkg/server/server.go

@ -8,15 +8,70 @@ import (
"github.com/minio-io/minio/pkg/server" "github.com/minio-io/minio/pkg/server"
) )
func getStorageType(input string) server.StorageType {
switch {
case input == "file":
return server.FileStorage
case input == "inmemory":
return server.InMemoryStorage
default:
{
log.Println("Unknown storage type:", input)
log.Println("Choosing default storage type as 'file'..")
return server.FileStorage
}
}
}
func runCmd(c *cli.Context) {
storageTypeStr := c.String("storage-type")
apiaddress := c.String("api-address")
webaddress := c.String("web-address")
certFile := c.String("cert")
keyFile := c.String("key")
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
log.Fatal("Both certificate and key must be provided to enable https")
}
tls := (certFile != "" && keyFile != "")
storageType := getStorageType(storageTypeStr)
var serverConfigs []server.ServerConfig
apiServerConfig := server.ServerConfig{
Address: apiaddress,
Tls: tls,
CertFile: certFile,
KeyFile: keyFile,
ApiType: server.MinioApi{
StorageType: storageType,
},
}
webUiServerConfig := server.ServerConfig{
Address: webaddress,
Tls: false,
CertFile: "",
KeyFile: "",
ApiType: server.WebUIApi{
Websocket: false,
},
}
serverConfigs = append(serverConfigs, apiServerConfig)
serverConfigs = append(serverConfigs, webUiServerConfig)
server.Start(serverConfigs)
}
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "minio" app.Name = "minio"
app.Usage = "" app.Usage = ""
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "http-address,a", Name: "api-address,a",
Value: ":8080", Value: ":8080",
Usage: "http address to listen on", Usage: "address for incoming API requests",
},
cli.StringFlag{
Name: "web-address,w",
Value: ":8081",
Usage: "address for incoming Management UI requests",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "cert,c", Name: "cert,c",
@ -34,40 +89,6 @@ func main() {
Usage: "valid entries: file,inmemory", Usage: "valid entries: file,inmemory",
}, },
} }
app.Action = func(c *cli.Context) { app.Action = runCmd
storageTypeStr := c.String("storage-type")
address := c.String("http-address")
log.Println(address)
certFile := c.String("cert")
keyFile := c.String("key")
if (certFile != "" && keyFile == "") || (certFile == "" && keyFile != "") {
log.Fatal("Both certificate and key must be provided to enable https")
}
tls := (certFile != "" && keyFile != "")
storageType := getStorageType(storageTypeStr)
serverConfig := server.ServerConfig{
Address: address,
Tls: tls,
CertFile: certFile,
KeyFile: keyFile,
StorageType: storageType,
}
server.Start(serverConfig)
}
app.Run(os.Args) app.Run(os.Args)
} }
func getStorageType(input string) server.StorageType {
switch {
case input == "file":
return server.FileStorage
case input == "inmemory":
return server.InMemoryStorage
default:
{
log.Println("Unknown storage type:", input)
log.Println("Choosing default storage type as 'file'..")
return server.FileStorage
}
}
}

@ -0,0 +1,46 @@
/*
* Mini Object Storage, (C) 2014 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package webuiapi
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
type webUiApi struct {
}
func HttpHandler() http.Handler {
mux := mux.NewRouter()
var api = webUiApi{}
mux.HandleFunc("/", api.homeHandler).Methods("GET")
/*
mux.HandleFunc("/{bucket}/", api.listObjectsHandler).Methods("GET")
mux.HandleFunc("/{bucket}/", api.putBucketHandler).Methods("PUT")
mux.HandleFunc("/{bucket}/{object:.*}", api.getObjectHandler).Methods("GET")
mux.HandleFunc("/{bucket}/{object:.*}", api.headObjectHandler).Methods("HEAD")
mux.HandleFunc("/{bucket}/{object:.*}", api.putObjectHandler).Methods("PUT")
*/
return mux
}
func (web *webUiApi) homeHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Server", "Minio Management Console")
fmt.Fprintln(w, "Welcome!")
}

@ -27,6 +27,7 @@ type HttpServerConfig struct {
TLS bool TLS bool
CertFile string CertFile string
KeyFile string KeyFile string
Websocket bool
} }
type HttpServer struct{} type HttpServer struct{}
@ -39,7 +40,8 @@ func Start(handler http.Handler, config HttpServerConfig) (chan<- string, <-chan
return ctrlChannel, errorChannel, &server return ctrlChannel, errorChannel, &server
} }
func start(ctrlChannel <-chan string, errorChannel chan<- error, router http.Handler, config HttpServerConfig, server *HttpServer) { func start(ctrlChannel <-chan string, errorChannel chan<- error,
router http.Handler, config HttpServerConfig, server *HttpServer) {
var err error var err error
// Minio server config // Minio server config

@ -23,11 +23,12 @@ import (
"path" "path"
"reflect" "reflect"
"github.com/minio-io/minio/pkg/api/minioapi"
"github.com/minio-io/minio/pkg/api/webuiapi"
"github.com/minio-io/minio/pkg/httpserver" "github.com/minio-io/minio/pkg/httpserver"
mstorage "github.com/minio-io/minio/pkg/storage" mstorage "github.com/minio-io/minio/pkg/storage"
"github.com/minio-io/minio/pkg/storage/fs" "github.com/minio-io/minio/pkg/storage/fs"
"github.com/minio-io/minio/pkg/storage/inmemory" "github.com/minio-io/minio/pkg/storage/inmemory"
"github.com/minio-io/minio/pkg/webapi/minioapi"
) )
type ServerConfig struct { type ServerConfig struct {
@ -35,9 +36,17 @@ type ServerConfig struct {
Tls bool Tls bool
CertFile string CertFile string
KeyFile string KeyFile string
ApiType interface{}
}
type MinioApi struct {
StorageType StorageType StorageType StorageType
} }
type WebUIApi struct {
Websocket bool
}
type StorageType int type StorageType int
const ( const (
@ -45,19 +54,20 @@ const (
FileStorage FileStorage
) )
func Start(config ServerConfig) { func getHttpChannels(configs []ServerConfig) (ctrlChans []chan<- string, statusChans []<-chan error) {
// maintain a list of input and output channels for communicating with services
var ctrlChans []chan<- string
var 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
for _, config := range configs {
switch k := config.ApiType.(type) {
case MinioApi:
{
// configure web server // configure web server
var storage mstorage.Storage var storage mstorage.Storage
var httpConfig = httpserver.HttpServerConfig{} var httpConfig = httpserver.HttpServerConfig{}
httpConfig.Address = config.Address httpConfig.Address = config.Address
httpConfig.Websocket = false
httpConfig.TLS = config.Tls httpConfig.TLS = config.Tls
if config.CertFile != "" { if config.CertFile != "" {
@ -67,6 +77,40 @@ func Start(config ServerConfig) {
httpConfig.KeyFile = config.KeyFile httpConfig.KeyFile = config.KeyFile
} }
ctrlChans, statusChans, storage = getStorageChannels(k.StorageType)
// start minio api in a web server, pass storage driver into it
ctrlChan, statusChan, _ = httpserver.Start(minioapi.HttpHandler(storage), httpConfig)
ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan)
}
case WebUIApi:
{
var httpConfig = httpserver.HttpServerConfig{}
httpConfig.Address = config.Address
httpConfig.TLS = config.Tls
httpConfig.CertFile = config.CertFile
httpConfig.KeyFile = config.KeyFile
httpConfig.Websocket = k.Websocket
ctrlChan, statusChan, _ = httpserver.Start(webuiapi.HttpHandler(), httpConfig)
ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan)
}
default:
log.Fatal("Invalid api type")
}
}
return
}
func getStorageChannels(storageType StorageType) (ctrlChans []chan<- string, statusChans []<-chan error, storage mstorage.Storage) {
// a pair of control channels, we use these primarily to add to the lists above
var ctrlChan chan<- string
var statusChan <-chan error
// instantiate storage // instantiate storage
// preconditions: // preconditions:
// - storage type specified // - storage type specified
@ -76,13 +120,13 @@ func Start(config ServerConfig) {
// - 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 config.StorageType == InMemoryStorage: case storageType == InMemoryStorage:
{ {
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 config.StorageType == FileStorage: case storageType == FileStorage:
{ {
// TODO Replace this with a more configurable and robust version // TODO Replace this with a more configurable and robust version
currentUser, err := user.Current() currentUser, err := user.Current()
@ -103,15 +147,14 @@ func Start(config ServerConfig) {
default: // should never happen default: // should never happen
log.Fatal("No storage driver found") log.Fatal("No storage driver found")
} }
return
}
// start minio api in a web server, pass storage driver into it func Start(configs []ServerConfig) {
ctrlChan, statusChan, _ = httpserver.Start(minioapi.HttpHandler(storage), httpConfig)
ctrlChans = append(ctrlChans, ctrlChan)
statusChans = append(statusChans, statusChan)
// listen for critical errors // listen for critical errors
// TODO Handle critical errors appropriately when they arise // TODO Handle critical errors appropriately when they arise
// 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
_, 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)

Loading…
Cancel
Save