diff --git a/api/config.go b/api/config.go index 327c9144ec..f6f2a2435a 100644 --- a/api/config.go +++ b/api/config.go @@ -303,3 +303,7 @@ func getConsoleDevMode() bool { func getConsoleAnimatedLogin() bool { return strings.ToLower(env.Get(ConsoleAnimatedLogin, "on")) == "on" } + +func getConsoleBrowserRedirectURL() string { + return env.Get(ConsoleBrowserRedirectURL, "") +} diff --git a/api/consts.go b/api/consts.go index 012c1d4b6e..1048e375c3 100644 --- a/api/consts.go +++ b/api/consts.go @@ -56,6 +56,7 @@ const ( ConsoleMaxConcurrentDownloads = "CONSOLE_MAX_CONCURRENT_DOWNLOADS" ConsoleDevMode = "CONSOLE_DEV_MODE" ConsoleAnimatedLogin = "CONSOLE_ANIMATED_LOGIN" + ConsoleBrowserRedirectURL = "CONSOLE_BROWSER_REDIRECT_URL" LogSearchQueryAuthToken = "LOGSEARCH_QUERY_AUTH_TOKEN" SlashSeparator = "/" LocalAddress = "127.0.0.1" diff --git a/api/user_objects.go b/api/user_objects.go index 11929a584d..06d0389618 100644 --- a/api/user_objects.go +++ b/api/user_objects.go @@ -1112,6 +1112,11 @@ func getRequestURLWithScheme(r *http.Request) string { scheme = "https" } + redirectURL := getConsoleBrowserRedirectURL() + if redirectURL != "" { + return strings.TrimSuffix(redirectURL, "/") + } + return fmt.Sprintf("%s://%s", scheme, r.Host) } diff --git a/api/user_objects_test.go b/api/user_objects_test.go index a6368e6cae..22a1f5730a 100644 --- a/api/user_objects_test.go +++ b/api/user_objects_test.go @@ -921,10 +921,11 @@ func Test_shareObject(t *testing.T) { shareFunc func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error) } tests := []struct { - test string - args args - wantError error - expected string + test string + args args + setEnvVars func() + wantError error + expected string }{ { test: "return sharefunc url base64 encoded with host name", @@ -1023,11 +1024,52 @@ func Test_shareObject(t *testing.T) { wantError: nil, expected: "http://localhost:9090/api/v1/download-shared-object/aHR0cHM6Ly8xMjcuMC4wLjE6OTAwMC9jZXN0ZXN0L0F1ZGlvJTIwaWNvbi5zdmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTY=", }, + { + test: "returns redirect url with share link if redirect url env variable set", + setEnvVars: func() { + t.Setenv(ConsoleBrowserRedirectURL, "http://proxy-url.com:9012/console/subpath") + }, + args: args{ + r: &http.Request{ + TLS: nil, + Host: "localhost:9090", + }, + versionID: "2121434", + expires: "30s", + shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) { + return "http://someurl", nil + }, + }, + wantError: nil, + expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=", + }, + { + test: "returns redirect url with share link if redirect url env variable set with trailing slash", + setEnvVars: func() { + t.Setenv(ConsoleBrowserRedirectURL, "http://proxy-url.com:9012/console/subpath/") + }, + args: args{ + r: &http.Request{ + TLS: nil, + Host: "localhost:9090", + }, + versionID: "2121434", + expires: "30s", + shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) { + return "http://someurl", nil + }, + }, + wantError: nil, + expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=", + }, } for _, tt := range tests { t.Run(tt.test, func(_ *testing.T) { mcShareDownloadMock = tt.args.shareFunc + if tt.setEnvVars != nil { + tt.setEnvVars() + } url, err := getShareObjectURL(ctx, client, tt.args.r, tt.args.versionID, tt.args.expires) if tt.wantError != nil { if !reflect.DeepEqual(err, tt.wantError) {