Skip to content

Commit

Permalink
Merge pull request #116 from cloudwan/improve_webui_integration
Browse files Browse the repository at this point in the history
Improve webui integration
  • Loading branch information
nati committed Mar 28, 2016
2 parents 7c7672f + 2ccd9a8 commit e0206e5
Show file tree
Hide file tree
Showing 41 changed files with 818 additions and 63 deletions.
4 changes: 4 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ deps:

format:
@echo "$(OK_COLOR)==> Formatting$(NO_COLOR)"
go-bindata -pkg util -o util/go-bindata.go etc/schema/... etc/extensions/... etc/templates/...
go-bindata -pkg util -o util/go-bindata.go etc/schema/... etc/extensions/... etc/templates/... public/...
go fmt ./...

test:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ see more [document](./docs/source/installation.rst)

## WebUI client
```
https://localhost:9443/webui/ (or https://$APPNAME.herokuapp.com/webui/ )
https://localhost:9443/ (or https://$APPNAME.herokuapp.com/ )
```

Login with this ID/password
Expand Down
4 changes: 2 additions & 2 deletions etc/gohan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ tls:
key_file: ./keys/key.pem
cert_file: ./keys/cert.pem
# document root of gohan API server
# Note: only static and schema directoriy will be served
document_root: "."
# embedded webui get served if you use "embed" here
document_root: "embed"
# list of etcd backend servers
#etcd:
# - "http://127.0.0.1:4001"
Expand Down
3 changes: 1 addition & 2 deletions etc/heroku.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ tls:
key_file: ./key.pem
cert_file: ./cert.pem
# document root of gohan API server
# Note: only static and schema directoriy will be served
document_root: "."
document_root: "embed"
# list of etcd backend servers
#etcd:
# - "http://127.0.0.1:4001"
Expand Down
80 changes: 40 additions & 40 deletions extension/gohanscript/autogen/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,46 @@ import (
)

func init() {
gohanscript.RegisterStmtParser("split",
func(stmt *gohanscript.Stmt) (func(*gohanscript.VM, *gohanscript.Context) (interface{}, error), error) {
return func(vm *gohanscript.VM, context *gohanscript.Context) (interface{}, error) {
value, _ := stmt.Arg("value", context).(string)
sep, _ := stmt.Arg("sep", context).(string)
var err error
result1, err := lib.Split(value, sep)
return result1, err
}, nil
})
gohanscript.RegisterMiniGoFunc("Split",
func(vm *gohanscript.VM, args []interface{}) []interface{} {
i := 0
value, _ := args[i].(string)
i++
sep, _ := args[i].(string)
i++
result1, result2 := lib.Split(value, sep)
return []interface{}{result1, result2}
})
gohanscript.RegisterStmtParser("join",
func(stmt *gohanscript.Stmt) (func(*gohanscript.VM, *gohanscript.Context) (interface{}, error), error) {
return func(vm *gohanscript.VM, context *gohanscript.Context) (interface{}, error) {
value, _ := stmt.Arg("value", context).([]interface{})
sep, _ := stmt.Arg("sep", context).(string)
var err error
result1, err := lib.Join(value, sep)
return result1, err
}, nil
})
gohanscript.RegisterMiniGoFunc("Join",
func(vm *gohanscript.VM, args []interface{}) []interface{} {
i := 0
value, _ := args[i].([]interface{})
i++
sep, _ := args[i].(string)
i++
result1, result2 := lib.Join(value, sep)
return []interface{}{result1, result2}
})
gohanscript.RegisterStmtParser("uuid",
func(stmt *gohanscript.Stmt) (func(*gohanscript.VM, *gohanscript.Context) (interface{}, error), error) {
return func(vm *gohanscript.VM, context *gohanscript.Context) (interface{}, error) {
Expand Down Expand Up @@ -929,44 +969,4 @@ func init() {
result1, result2 := lib.OpenstackEndpoint(client, endpointType, name, region, availability)
return []interface{}{result1, result2}
})
gohanscript.RegisterStmtParser("split",
func(stmt *gohanscript.Stmt) (func(*gohanscript.VM, *gohanscript.Context) (interface{}, error), error) {
return func(vm *gohanscript.VM, context *gohanscript.Context) (interface{}, error) {
value, _ := stmt.Arg("value", context).(string)
sep, _ := stmt.Arg("sep", context).(string)
var err error
result1, err := lib.Split(value, sep)
return result1, err
}, nil
})
gohanscript.RegisterMiniGoFunc("Split",
func(vm *gohanscript.VM, args []interface{}) []interface{} {
i := 0
value, _ := args[i].(string)
i++
sep, _ := args[i].(string)
i++
result1, result2 := lib.Split(value, sep)
return []interface{}{result1, result2}
})
gohanscript.RegisterStmtParser("join",
func(stmt *gohanscript.Stmt) (func(*gohanscript.VM, *gohanscript.Context) (interface{}, error), error) {
return func(vm *gohanscript.VM, context *gohanscript.Context) (interface{}, error) {
value, _ := stmt.Arg("value", context).([]interface{})
sep, _ := stmt.Arg("sep", context).(string)
var err error
result1, err := lib.Join(value, sep)
return result1, err
}, nil
})
gohanscript.RegisterMiniGoFunc("Join",
func(vm *gohanscript.VM, args []interface{}) []interface{} {
i := 0
value, _ := args[i].([]interface{})
i++
sep, _ := args[i].(string)
i++
result1, result2 := lib.Join(value, sep)
return []interface{}{result1, result2}
})
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 7 additions & 1 deletion server/middleware/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ func Authentication() martini.Handler {
return
}
//TODO(nati) make this configureable
if strings.HasPrefix(req.URL.Path, "/webui/") {
if strings.HasPrefix(req.URL.Path, "/webui") {
c.Next()
return
}

if req.URL.Path == "/" || req.URL.Path == "/webui" {
http.Redirect(res, req, "/webui/", http.StatusTemporaryRedirect)
return
}

if req.URL.Path == "/v2.0/tokens" {
c.Next()
return
Expand Down
20 changes: 13 additions & 7 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/cloudwan/gohan/sync/etcd"
"github.com/cloudwan/gohan/util"
"github.com/go-martini/martini"
//Import gohan extension buildins
"github.com/martini-contrib/staticbin"
)

type tls struct {
Expand Down Expand Up @@ -266,12 +266,18 @@ func NewServer(configFile string) (*Server, error) {
rw.Header().Add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE")
})
}
server.timelimit = config.GetInt("extention/timelimit", 30)
documentRoot := config.GetString("document_root", "./")
log.Info("Static file serving from %s", documentRoot)
documentRootABS, err := filepath.Abs(documentRoot)
server.martini.Use(martini.Static(documentRootABS))

server.timelimit = config.GetInt("extension/timelimit", 30)
documentRoot := config.GetString("document_root", "embed")
if documentRoot == "embed" {
m.Use(staticbin.Static("public", util.Asset))
} else {
log.Info("Static file serving from %s", documentRoot)
documentRootABS, err := filepath.Abs(documentRoot)
if err != nil {
return nil, err
}
server.martini.Use(martini.Static(documentRootABS))
}
server.mapRoutes()
return server, nil
}
Expand Down
6 changes: 3 additions & 3 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ var _ = Describe("Server package test", func() {
})

Context("getting from baseURL", func() {
It("should return 404(Not Found)", func() {
testURL("GET", baseURL, adminTokenID, nil, http.StatusNotFound)
It("should return 200", func() {
testURL("GET", baseURL, adminTokenID, nil, http.StatusOK)
})
})

Expand Down Expand Up @@ -314,7 +314,7 @@ var _ = Describe("Server package test", func() {
It("should work", func() {
network := getNetwork("red", "red")

testURL("GET", baseURL, memberTokenID, nil, http.StatusNotFound)
testURL("GET", baseURL, memberTokenID, nil, http.StatusOK)
testURL("GET", networkPluralURL, memberTokenID, nil, http.StatusOK)
testURL("GET", networkPluralURL, "", nil, http.StatusUnauthorized)
testURL("GET", schemaURL, memberTokenID, nil, http.StatusOK)
Expand Down
2 changes: 1 addition & 1 deletion server/server_test_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ schemas:
- "embed://etc/schema/gohan.json"
- "../tests/test_schema.yaml"
address: ":19090"
document_root: "../etc/"
document_root: "embed"
etcd:
- "http://127.0.0.1:4001"
keystone:
Expand Down
2 changes: 1 addition & 1 deletion server/server_test_mysql_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ schemas:
- "../etc/schema/gohan.json"
- "../tests/test_schema.yaml"
address: ":19090"
document_root: "../etc/"
document_root: "embed"
etcd:
- "http://127.0.0.1:4001"
keystone:
Expand Down
403 changes: 399 additions & 4 deletions util/go-bindata.go

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/consts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/martini.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/martini-contrib/staticbin/martini_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e0206e5

Please sign in to comment.