-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.go
More file actions
48 lines (40 loc) · 1.07 KB
/
server.go
File metadata and controls
48 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"net/http"
"github.com/byuoitav/auth/middleware"
"github.com/byuoitav/auth/wso2"
"github.com/byuoitav/common"
"github.com/byuoitav/common/log"
"github.com/byuoitav/flight-deck/handlers"
"github.com/labstack/echo"
)
func main() {
port := ":8008"
router := common.NewRouter()
router.GET("/healthz", func(c echo.Context) error {
return c.String(http.StatusOK, "Ready for takeoff!")
})
client := wso2.New("", "", "https://api.byu.edu", "")
secure := router.Group(
"",
echo.WrapMiddleware(client.JWTValidationMiddleware()),
func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if middleware.Authenticated(c.Request()) {
next(c)
return nil
}
return c.JSON(http.StatusForbidden, map[string]string{"error": "Unauthorized"})
}
},
)
/* secure routes */
secure.GET("/webhook_device/:hostname", handlers.DeployByHostname)
err := router.StartServer(&http.Server{
Addr: port,
MaxHeaderBytes: 1024 * 10,
})
if err != nil {
log.L.Errorf("failed to start http server: %v", err)
}
}