Skip to content

Commit 884917d

Browse files
committed
feat: remove rest apis
1 parent a856e9c commit 884917d

File tree

13 files changed

+50
-787
lines changed

13 files changed

+50
-787
lines changed

swiftwave_service/main.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,56 @@ func StartServer(config *config.Config, manager *service_manager.ServiceManager,
116116
}
117117
})
118118

119+
// Add `authorized` & `username` key to the context
120+
echoServer.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
121+
return func(c echo.Context) error {
122+
if strings.Compare(c.Request().URL.Path, "/") == 0 ||
123+
strings.HasPrefix(c.Request().URL.Path, "/healthcheck") ||
124+
strings.HasPrefix(c.Request().URL.Path, "/.well-known") ||
125+
strings.HasPrefix(c.Request().URL.Path, "/auth") ||
126+
strings.HasPrefix(c.Request().URL.Path, "/webhook") ||
127+
strings.HasPrefix(c.Request().URL.Path, "/dashboard") ||
128+
strings.HasPrefix(c.Request().URL.Path, "/playground") {
129+
return next(c)
130+
}
131+
// check if a GET request at /graphql and a websocket upgrade request
132+
if strings.HasPrefix(c.Request().URL.Path, "/graphql") &&
133+
strings.Compare(c.Request().Method, http.MethodGet) == 0 &&
134+
strings.Compare(c.Request().URL.RawQuery, "") == 0 &&
135+
strings.Contains(strings.ToLower(c.Request().Header.Get("Connection")), "upgrade") &&
136+
strings.Compare(strings.ToLower(c.Request().Header.Get("Upgrade")), "websocket") == 0 {
137+
return next(c)
138+
}
139+
140+
// on console websocket connection allow without jwt, as auth will be handled by the console server
141+
if strings.HasPrefix(c.Request().URL.Path, "/console/ws") &&
142+
strings.Compare(c.Request().Method, http.MethodGet) == 0 &&
143+
strings.Compare(c.Request().URL.RawQuery, "") == 0 &&
144+
strings.Contains(strings.ToLower(c.Request().Header.Get("Connection")), "upgrade") &&
145+
strings.Compare(strings.ToLower(c.Request().Header.Get("Upgrade")), "websocket") == 0 {
146+
return next(c)
147+
}
148+
149+
// Whitelist console's HTML, JS, CSS
150+
if (strings.Compare(c.Request().URL.Path, "/console") == 0 ||
151+
strings.Compare(c.Request().URL.Path, "/console/main.js") == 0 ||
152+
strings.Compare(c.Request().URL.Path, "/console/xterm.js") == 0 ||
153+
strings.Compare(c.Request().URL.Path, "/console/xterm-addon-fit.js") == 0 ||
154+
strings.Compare(c.Request().URL.Path, "/console/xterm.css") == 0) &&
155+
strings.Compare(c.Request().Method, http.MethodGet) == 0 {
156+
return next(c)
157+
}
158+
159+
// Authenticate request
160+
161+
c.Set("authorized", false)
162+
c.Set("username", "")
163+
c.Set("hostname", "")
164+
165+
return next(c)
166+
}
167+
})
168+
119169
// Create GraphQL Server
120170
graphqlServer := graphql.Server{
121171
EchoServer: echoServer,

swiftwave_service/rest/analytics.go

Lines changed: 0 additions & 138 deletions
This file was deleted.

swiftwave_service/rest/auth.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

swiftwave_service/rest/auth_check.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

swiftwave_service/rest/healthcheck.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

swiftwave_service/rest/helpers.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

swiftwave_service/rest/log.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)