Skip to content

Commit

Permalink
fix(yolo): fix unknow job & Remove basic auth but keep token middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton committed Apr 30, 2019
1 parent be0027a commit b25d6f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ deploy:
--name yolo -d -p 80:3670 \
$(IMAGE) \
-t $(CIRCLE_TOKEN) serve \
--hostname $(HOSTNAME) -p $(PASSWORD)"
--hostname $(HOSTNAME)"

.PHONY: prod-logs
prod-logs:
Expand Down
8 changes: 4 additions & 4 deletions cmd/yolo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ var serveCmd = &cobra.Command{
return err
}
defer s.Close()
panic(s.Start())
return nil

return s.Start()
},
}

func init() {
serveCmd.PersistentFlags().StringVarP(&serverCfg.Addr, "listen", "l", ":3670", "Listen addr")
serveCmd.PersistentFlags().StringVarP(&serverCfg.Hostname, "hostname", "n", "localhost:3670", "hostname")
serveCmd.PersistentFlags().StringVarP(&serverCfg.Username, "username", "u", "berty", "user")
serveCmd.PersistentFlags().StringVarP(&serverCfg.Password, "password", "p", "", "password")
// serveCmd.PersistentFlags().StringVarP(&serverCfg.Username, "username", "u", "berty", "user")
// serveCmd.PersistentFlags().StringVarP(&serverCfg.Password, "password", "p", "", "password")
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")
Expand Down
2 changes: 1 addition & 1 deletion server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ func (s *Server) GetReleasesByDate(c echo.Context, job string) (*ReleasesByDate,
id := strconv.Itoa(build.BuildNum)
androidToken := s.getHash(id)
href = fmt.Sprintf(`%s/auth/apk/build/%s/%s`, s.hostUrl, androidToken, id)
case MAC_STAFF_JOB:
case MAC_STAFF_JOB, MAC_YOLO_JOB:
id := strconv.Itoa(build.BuildNum)
href = fmt.Sprintf(`%s/auth/dmg/build/%s/%s`, s.hostUrl, s.getHash(id), id)
default:
Expand Down
16 changes: 5 additions & 11 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ type ServerConfig struct {
Addr string
Hostname string

Username string
Password string

Debug bool
NoSlack bool
NoGa bool
Expand Down Expand Up @@ -163,7 +160,6 @@ func NewServer(cfg *ServerConfig) (*Server, error) {
e.GET("/", func(c echo.Context) error {
header := c.Request().Header
if agent := header.Get("User-Agent"); agent != "" {
fmt.Println(agent)
if reAndroidAgent.MatchString(agent) {
return c.Redirect(http.StatusTemporaryRedirect, "/release/android")
}
Expand Down Expand Up @@ -232,7 +228,7 @@ func NewServer(cfg *ServerConfig) (*Server, error) {

auth := e.Group("/auth")
tokenPaths := regexp.MustCompile("^/auth/ipa/build/.+$|^/auth/dmg/build/.+$|^/auth/apk/build/.+$|^/auth/itms/release/.+$")
auth.Use((s.basicAuth(cfg.Username, cfg.Password, tokenPaths)))
auth.Use(s.tokenMiddleware(tokenPaths))

auth.GET("/build/:build_id", s.Build)
auth.GET("/builds/*", s.Builds)
Expand All @@ -249,11 +245,7 @@ func NewServer(cfg *ServerConfig) (*Server, error) {
}

// Basic auth
func (s *Server) basicAuth(username, password string, tokenPaths *regexp.Regexp) func(next echo.HandlerFunc) echo.HandlerFunc {
auth := middleware.BasicAuth(func(u, p string, c echo.Context) (bool, error) {
return username == u && password == p, nil
})

func (s *Server) tokenMiddleware(tokenPaths *regexp.Regexp) func(next echo.HandlerFunc) echo.HandlerFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if tokenPaths.MatchString(c.Path()) {
Expand All @@ -263,9 +255,11 @@ func (s *Server) basicAuth(username, password string, tokenPaths *regexp.Regexp)
return next(c)
}
}

return echo.NewHTTPError(http.StatusUnauthorized)
}

return auth(next)(c)
return next(c)
}
}
}
Expand Down

0 comments on commit b25d6f7

Please sign in to comment.