Skip to content

Commit 0db91f5

Browse files
authored
feat: replace notebooks with data service (#750)
1 parent 9525b00 commit 0db91f5

File tree

6 files changed

+36
-38
lines changed

6 files changed

+36
-38
lines changed

internal/config/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestInvalidLoginConfig(t *testing.T) {
4848

4949
func TestInvalidRevproxyConfig(t *testing.T) {
5050
config := getValidConfig(t)
51-
config.Revproxy.RenkuServices.Notebooks = nil
51+
config.Revproxy.RenkuServices.KG = nil
5252

5353
err := config.Validate()
5454

internal/config/revproxy.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
)
77

88
type RenkuServicesConfig struct {
9-
Notebooks *url.URL
109
KG *url.URL
1110
Webhook *url.URL
1211
Core CoreSvcConfig
@@ -30,9 +29,6 @@ type CoreSvcConfig struct {
3029
}
3130

3231
func (r *RevproxyConfig) Validate() error {
33-
if r.RenkuServices.Notebooks == nil {
34-
return fmt.Errorf("the proxy config is missing the url to the notebook service")
35-
}
3632
if r.RenkuServices.KG == nil {
3733
return fmt.Errorf("the proxy config is missing the url to the knowledge graph service")
3834
}

internal/config/revproxy_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ func getValidRevproxyConfig(t *testing.T) RevproxyConfig {
2222
}
2323

2424
func getValidRenkuServicesConfig(t *testing.T) RenkuServicesConfig {
25-
notebooksURL, err := url.Parse("http://notebooks")
26-
require.NoError(t, err)
2725
kgURL, err := url.Parse("http://kg")
2826
require.NoError(t, err)
2927
webhookURL, err := url.Parse("http://kg")
@@ -37,7 +35,6 @@ func getValidRenkuServicesConfig(t *testing.T) RenkuServicesConfig {
3735
searchURL, err := url.Parse("http://ui")
3836
require.NoError(t, err)
3937
return RenkuServicesConfig{
40-
Notebooks: notebooksURL,
4138
KG: kgURL,
4239
Webhook: webhookURL,
4340
DataService: dataServiceURL,
@@ -55,15 +52,6 @@ func TestValidRevproxyConfig(t *testing.T) {
5552
assert.NoError(t, err)
5653
}
5754

58-
func TestInvalidNotebooksURL(t *testing.T) {
59-
config := getValidRevproxyConfig(t)
60-
config.RenkuServices.Notebooks = nil
61-
62-
err := config.Validate()
63-
64-
assert.ErrorContains(t, err, "the proxy config is missing the url to the notebook service")
65-
}
66-
6755
func TestInvalidKGURL(t *testing.T) {
6856
config := getValidRevproxyConfig(t)
6957
config.RenkuServices.KG = nil

internal/revproxy/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func (r *Revproxy) RegisterHandlers(e *echo.Echo, commonMiddlewares ...echo.Midd
4242
gitlabProxy = fallbackProxy
4343
gitlabProxyHost = setHost(r.config.RenkuBaseURL.Host)
4444
}
45-
notebooksProxy := proxyFromURL(r.config.RenkuServices.Notebooks)
4645
kgProxy := proxyFromURL(r.config.RenkuServices.KG)
4746
webhookProxy := proxyFromURL(r.config.RenkuServices.Webhook)
4847
keycloakProxy := proxyFromURL(r.config.RenkuServices.Keycloak)
@@ -56,18 +55,17 @@ func (r *Revproxy) RegisterHandlers(e *echo.Echo, commonMiddlewares ...echo.Midd
5655
dataGitlabAccessToken := r.dataGitlabAccessTokenAuth.Middleware()
5756
gitlabToken := r.gitlabTokenAuth.Middleware()
5857
gitlabCliToken := r.gitlabCliTokenAuth.Middleware()
59-
notebooksRenkuAccessToken := r.notebooksRenkuAccessTokenAuth.Middleware()
6058
notebooksRenkuRefreshToken := r.notebooksRenkuRefreshTokenAuth.Middleware()
6159
notebooksRenkuIDToken := r.notebooksRenkuIDTokenAuth.Middleware()
62-
notebooksGitlabAccessToken := r.notebooksGitlabAccessTokenAuth.Middleware()
6360
renkuAccessToken := r.renkuAccessTokenAuth.Middleware()
6461

6562
// Deny rules
6663
sk := e.Group("/api/data/user/secret_key", commonMiddlewares...)
6764
sk.GET("/", echo.NotFoundHandler)
6865

6966
// Routing for Renku services
70-
e.Group("/api/notebooks", append(commonMiddlewares, notebooksRenkuAccessToken, notebooksRenkuRefreshToken, notebooksRenkuIDToken, notebooksGitlabAccessToken, notebooksAnonymousID(r.sessions), noCookies, stripPrefix("/api"), notebooksProxy)...)
67+
// Notebooks is being routed to data service now
68+
e.Group("/api/notebooks", append(commonMiddlewares, renkuAccessToken, dataGitlabAccessToken, notebooksRenkuRefreshToken, notebooksAnonymousID(r.sessions), regexRewrite("^/api/notebooks(.*)", "/api/data/notebooks$1"), dataServiceProxy)...)
7169
// /api/projects/:projectID/graph will is being deprecated in favour of /api/kg/webhooks, the old endpoint will remain for some time for backward compatibility
7270
e.Group("/api/projects/:projectID/graph", append(commonMiddlewares, gitlabToken, noCookies, kgProjectsGraphRewrites, webhookProxy)...)
7371
e.Group("/knowledge-graph", append(commonMiddlewares, gitlabToken, coreSvcIdToken, noCookies, kgProxy)...)

internal/revproxy/main_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ func ParametrizedRouteTest(scenario TestCase) func(*testing.T) {
233233
rpConfig := config.RevproxyConfig{
234234
RenkuBaseURL: upstreamURL,
235235
RenkuServices: config.RenkuServicesConfig{
236-
Notebooks: upstreamURL,
237236
Core: config.CoreSvcConfig{
238237
ServiceNames: []string{upstreamURL.String(), upstreamURL.String(), upstreamURL2.String()},
239238
ServicePaths: []string{"/api/renku", "/api/renku/10", "/api/renku/9"},
@@ -389,11 +388,11 @@ func TestInternalSvcRoutes(t *testing.T) {
389388
Expected: TestResults{
390389
VisitedServerIDs: []string{"upstream"},
391390
UpstreamRequestHeaders: []map[string]string{{
392-
"Authorization": "",
393-
"Renku-Auth-Id-Token": "",
394-
"Renku-Auth-Access-Token": "",
395-
"Renku-Auth-Refresh-Token": "",
396-
"Renku-Auth-Anon-Id": "anon-sessionID",
391+
echo.HeaderAuthorization: "",
392+
"Gitlab-Access-Token": "",
393+
"Gitlab-Access-Token-Expires-At": "",
394+
"Renku-Auth-Refresh-Token": "",
395+
"Renku-Auth-Anon-Id": "anon-sessionID",
397396
}},
398397
},
399398
Sessions: []models.Session{
@@ -404,13 +403,14 @@ func TestInternalSvcRoutes(t *testing.T) {
404403
{
405404
Path: "/api/notebooks/test/acceptedAuth",
406405
Expected: TestResults{
407-
Path: "/notebooks/test/acceptedAuth",
406+
Path: "/api/data/notebooks/test/acceptedAuth",
408407
VisitedServerIDs: []string{"upstream"},
409408
UpstreamRequestHeaders: []map[string]string{{
410-
"Renku-Auth-Id-Token": "idTokenValue",
411-
"Renku-Auth-Access-Token": "accessTokenValue",
412-
"Renku-Auth-Refresh-Token": "refreshTokenValue",
413-
"Renku-Auth-Anon-Id": "",
409+
echo.HeaderAuthorization: "Bearer accessTokenValue",
410+
"Gitlab-Access-Token": "gitlabAccessTokenValue",
411+
"Gitlab-Access-Token-Expires-At": "16746525971",
412+
"Renku-Auth-Refresh-Token": "refreshTokenValue",
413+
"Renku-Auth-Anon-Id": "",
414414
}},
415415
},
416416
Tokens: []models.AuthToken{
@@ -427,20 +427,21 @@ func TestInternalSvcRoutes(t *testing.T) {
427427
tokenProviderID("renku"),
428428
),
429429
newTestToken(
430-
models.IDTokenType,
431-
tokenID("renku:myToken"),
432-
tokenPlainValue("idTokenValue"),
433-
tokenProviderID("renku"),
430+
models.AccessTokenType,
431+
tokenID("gitlab:otherToken"),
432+
tokenPlainValue("gitlabAccessTokenValue"),
433+
tokenProviderID("gitlab"),
434+
tokenExpiresAt(time.Unix(16746525971, 0)),
434435
),
435436
},
436437
Sessions: []models.Session{
437-
newTestSesssion(sessionID("sessionID"), withTokenIDs(map[string]string{"renku": "renku:myToken"})),
438+
newTestSesssion(sessionID("sessionID"), withTokenIDs(map[string]string{"renku": "renku:myToken", "gitlab": "gitlab:otherToken"})),
438439
},
439440
RequestCookie: &http.Cookie{Name: sessions.SessionCookieName, Value: "sessionID"},
440441
},
441442
{
442443
Path: "/api/notebooks",
443-
Expected: TestResults{Path: "/notebooks", VisitedServerIDs: []string{"upstream"}},
444+
Expected: TestResults{Path: "/api/data/notebooks", VisitedServerIDs: []string{"upstream"}},
444445
},
445446
{
446447
Path: "/api/search/test/rejectedAuth",

internal/revproxy/middlewares.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ func UiServerPathRewrite() echo.MiddlewareFunc {
215215
c.Request().RequestURI = newUrl.String()
216216
slog.Debug("PATH REWRITE", "message", "matched /ui-server/auth", "originalURL", originalURL, "newUrl", newUrl.String(), "requestID", utils.GetRequestID(c))
217217
}
218+
// For notebooks rewrite to go to the data service
219+
if strings.HasPrefix(path, "/ui-server/api/notebooks") {
220+
originalURL := c.Request().URL.String()
221+
c.Request().URL.Path = strings.TrimPrefix(path, "/ui-server/api/notebooks")
222+
c.Request().URL.RawPath = strings.TrimPrefix(c.Request().URL.RawPath, "/ui-server/api/notebooks")
223+
c.Request().URL.Path = "/api/data/notebooks" + c.Request().URL.Path
224+
c.Request().URL.RawPath = "/api/data/notebooks" + c.Request().URL.RawPath
225+
newUrl, err := url.Parse(c.Request().URL.String())
226+
if err != nil {
227+
return err
228+
}
229+
c.Request().URL = newUrl
230+
c.Request().RequestURI = newUrl.String()
231+
slog.Debug("PATH REWRITE", "message", "matched /ui-server/api/notebooks", "originalURL", originalURL, "newUrl", newUrl.String(), "requestID", utils.GetRequestID(c))
232+
}
218233
// For all other endpoints the gateway will fully bypass the UI server routing things directly to the proper
219234
// Renku component.
220235
if strings.HasPrefix(path, "/ui-server/api") {

0 commit comments

Comments
 (0)