mirror of
https://github.com/minio/minio.git
synced 2025-04-08 05:35:33 -04:00
Merge pull request #112 from harshavardhana/pr_out_service_a_new_webui_server_at_port_8081
This commit is contained in:
commit
3ed884e495
95
main.go
95
main.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
46
pkg/api/webuiapi/webuiapi.go
Normal file
46
pkg/api/webuiapi/webuiapi.go
Normal file
@ -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!")
|
||||||
|
}
|
@ -23,10 +23,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type HttpServerConfig struct {
|
type HttpServerConfig struct {
|
||||||
Address string
|
Address string
|
||||||
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,21 +23,30 @@ 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 {
|
||||||
Address string
|
Address string
|
||||||
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,27 +54,62 @@ 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
|
||||||
|
|
||||||
// configure web server
|
for _, config := range configs {
|
||||||
var storage mstorage.Storage
|
switch k := config.ApiType.(type) {
|
||||||
var httpConfig = httpserver.HttpServerConfig{}
|
case MinioApi:
|
||||||
httpConfig.Address = config.Address
|
{
|
||||||
httpConfig.TLS = config.Tls
|
// configure web server
|
||||||
|
var storage mstorage.Storage
|
||||||
|
var httpConfig = httpserver.HttpServerConfig{}
|
||||||
|
httpConfig.Address = config.Address
|
||||||
|
httpConfig.Websocket = false
|
||||||
|
httpConfig.TLS = config.Tls
|
||||||
|
|
||||||
if config.CertFile != "" {
|
if config.CertFile != "" {
|
||||||
httpConfig.CertFile = config.CertFile
|
httpConfig.CertFile = config.CertFile
|
||||||
}
|
}
|
||||||
if config.KeyFile != "" {
|
if config.KeyFile != "" {
|
||||||
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:
|
||||||
@ -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…
x
Reference in New Issue
Block a user