Skip to content

Commit

Permalink
feat(yolo): add a way of disabling authentication '--no-auth'
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jun 3, 2019
1 parent b25d6f7 commit bb76864
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ HOST ?= [email protected]
HOSTNAME ?= yolo.berty.io
CIRCLE_TOKEN ?= ***REMOVED***
PASSWORD ?= 'xor+=cool'
RUN_OPTS ?= --no-slack --no-ga --no-auth


.PHONY: run
run: install
yolo -t $(CIRCLE_TOKEN) serve --debug --no-slack --no-ga
yolo -t $(CIRCLE_TOKEN) serve --debug $(RUN_OPTS)

.PHONY: install
install:
Expand Down
1 change: 1 addition & 0 deletions cmd/yolo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func init() {
serveCmd.PersistentFlags().BoolVarP(&serverCfg.Debug, "debug", "", false, "debug mode")
serveCmd.PersistentFlags().BoolVarP(&serverCfg.NoSlack, "no-slack", "", false, "disable slack")
serveCmd.PersistentFlags().BoolVarP(&serverCfg.NoGa, "no-ga", "", false, "disable google analytics")
serveCmd.PersistentFlags().BoolVarP(&serverCfg.NoAuth, "no-auth", "", false, "disable auth")
serveCmd.PersistentFlags().StringVarP(&serverCfg.SqlConn, "sql-conn", "", "./yolo.sqlite", "sql connection url")

rootCmd.AddCommand(serveCmd)
Expand Down
43 changes: 25 additions & 18 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type ServerConfig struct {
Debug bool
NoSlack bool
NoGa bool
NoAuth bool

SqlConn string
}
Expand Down Expand Up @@ -83,6 +84,7 @@ type Server struct {
Debug bool
NoSlack bool
NoGa bool
NoAuth bool

// templates/static
funcmap *ctxFuncmap
Expand Down Expand Up @@ -139,6 +141,7 @@ func NewServer(cfg *ServerConfig) (*Server, error) {
Debug: cfg.Debug,
NoSlack: cfg.NoSlack,
NoGa: cfg.NoGa,
NoAuth: cfg.NoAuth,
}
e.HTTPErrorHandler = func(err error, c echo.Context) {
s.sendUserErrorToSlack(c, err)
Expand Down Expand Up @@ -177,19 +180,21 @@ func NewServer(cfg *ServerConfig) (*Server, error) {
oauth.GET("/logout", o.LogoutHandler(s.hostUrl))

release := e.Group("release")
release.Use(o.ProtectMiddleware("/oauth/login", func(profile map[string]interface{}) bool {
if v, ok := profile["https://yolo.berty.io/groups"]; ok {
if groups, ok := v.([]interface{}); ok {
for _, group := range groups {
if g, ok := group.(string); ok && g == "yolo" {
return true
if !cfg.NoAuth {
release.Use(o.ProtectMiddleware("/oauth/login", func(profile map[string]interface{}) bool {
if v, ok := profile["https://yolo.berty.io/groups"]; ok {
if groups, ok := v.([]interface{}); ok {
for _, group := range groups {
if g, ok := group.(string); ok && g == "yolo" {
return true
}
}
}
}
}

return false
}))
return false
}))
}

release.GET("/ios", s.ListReleaseIOSBeta)
release.GET("/android", s.ListReleaseAndroidBeta)
Expand All @@ -207,19 +212,21 @@ func NewServer(cfg *ServerConfig) (*Server, error) {

desktop.GET("/mac.json", s.ListReleaseDMGJson)
staffRelease := e.Group("/release/staff")
staffRelease.Use(o.ProtectMiddleware("/oauth/login", func(profile map[string]interface{}) bool {
if v, ok := profile["https://yolo.berty.io/groups"]; ok {
if groups, ok := v.([]interface{}); ok {
for _, group := range groups {
if g, ok := group.(string); ok && g == "staff" {
return true
if !cfg.NoAuth {
staffRelease.Use(o.ProtectMiddleware("/oauth/login", func(profile map[string]interface{}) bool {
if v, ok := profile["https://yolo.berty.io/groups"]; ok {
if groups, ok := v.([]interface{}); ok {
for _, group := range groups {
if g, ok := group.(string); ok && g == "staff" {
return true
}
}
}
}
}

return false
}))
return false
}))
}
staffRelease.GET("/ios/*", s.ReleaseIOS)
staffRelease.GET("/ios", s.ListReleaseIOS)
staffRelease.GET("/mac", s.ListReleaseDMG)
Expand Down

0 comments on commit bb76864

Please sign in to comment.