mirror of
https://github.com/minio/minio.git
synced 2025-01-13 16:03:21 -05:00
Merge pull request #137 from harshavardhana/pr_out_reply_back_accesskey_secretkey_through_json
This commit is contained in:
commit
829be023d2
@ -17,6 +17,8 @@
|
||||
package webuiapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
@ -35,6 +37,11 @@ type webUiApi struct {
|
||||
webPath string
|
||||
}
|
||||
|
||||
// No encoder interface exists, so we create one.
|
||||
type encoder interface {
|
||||
Encode(v interface{}) error
|
||||
}
|
||||
|
||||
func HttpHandler() http.Handler {
|
||||
mux := mux.NewRouter()
|
||||
var api = webUiApi{}
|
||||
@ -49,6 +56,17 @@ func HttpHandler() http.Handler {
|
||||
return mux
|
||||
}
|
||||
|
||||
func writeResponse(w http.ResponseWriter, response interface{}) []byte {
|
||||
var bytesBuffer bytes.Buffer
|
||||
var encoder encoder
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
encoder = json.NewEncoder(&bytesBuffer)
|
||||
w.Header().Set("Server", "Minio Management Console")
|
||||
w.Header().Set("Connection", "close")
|
||||
encoder.Encode(response)
|
||||
return bytesBuffer.Bytes()
|
||||
}
|
||||
|
||||
func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) {
|
||||
var err error
|
||||
var accesskey, secretkey []byte
|
||||
@ -58,6 +76,18 @@ func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = web.conf.ReadConfig()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if web.conf.IsUserExists(username) {
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
return
|
||||
}
|
||||
|
||||
var user = config.User{}
|
||||
user.Name = username
|
||||
|
||||
@ -92,5 +122,7 @@ func (web *webUiApi) accessHandler(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Config:", web.conf.Users)
|
||||
// Get user back for sending it over HTTP reply
|
||||
user = web.conf.GetUser(username)
|
||||
w.Write(writeResponse(w, user))
|
||||
}
|
||||
|
@ -45,6 +45,24 @@ func (c *Config) GetConfigPath() string {
|
||||
return c.configPath
|
||||
}
|
||||
|
||||
func (c *Config) IsUserExists(username string) bool {
|
||||
for _, user := range c.Users {
|
||||
if user.Name == username {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Config) GetUser(username string) User {
|
||||
for _, user := range c.Users {
|
||||
if user.Name == username {
|
||||
return user
|
||||
}
|
||||
}
|
||||
return User{}
|
||||
}
|
||||
|
||||
func (c *Config) AddUser(user User) {
|
||||
var currentUsers map[string]User
|
||||
if len(c.Users) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user