Skip to content

Commit a8c043c

Browse files
authored
Use redirect URL in share link if env variable set (#3334)
1 parent 978e02b commit a8c043c

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

api/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,7 @@ func getConsoleDevMode() bool {
303303
func getConsoleAnimatedLogin() bool {
304304
return strings.ToLower(env.Get(ConsoleAnimatedLogin, "on")) == "on"
305305
}
306+
307+
func getConsoleBrowserRedirectURL() string {
308+
return env.Get(ConsoleBrowserRedirectURL, "")
309+
}

api/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const (
5656
ConsoleMaxConcurrentDownloads = "CONSOLE_MAX_CONCURRENT_DOWNLOADS"
5757
ConsoleDevMode = "CONSOLE_DEV_MODE"
5858
ConsoleAnimatedLogin = "CONSOLE_ANIMATED_LOGIN"
59+
ConsoleBrowserRedirectURL = "CONSOLE_BROWSER_REDIRECT_URL"
5960
LogSearchQueryAuthToken = "LOGSEARCH_QUERY_AUTH_TOKEN"
6061
SlashSeparator = "/"
6162
LocalAddress = "127.0.0.1"

api/user_objects.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,11 @@ func getRequestURLWithScheme(r *http.Request) string {
11121112
scheme = "https"
11131113
}
11141114

1115+
redirectURL := getConsoleBrowserRedirectURL()
1116+
if redirectURL != "" {
1117+
return strings.TrimSuffix(redirectURL, "/")
1118+
}
1119+
11151120
return fmt.Sprintf("%s://%s", scheme, r.Host)
11161121
}
11171122

api/user_objects_test.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,10 +921,11 @@ func Test_shareObject(t *testing.T) {
921921
shareFunc func(ctx context.Context, versionID string, expires time.Duration) (string, *probe.Error)
922922
}
923923
tests := []struct {
924-
test string
925-
args args
926-
wantError error
927-
expected string
924+
test string
925+
args args
926+
setEnvVars func()
927+
wantError error
928+
expected string
928929
}{
929930
{
930931
test: "return sharefunc url base64 encoded with host name",
@@ -1023,11 +1024,52 @@ func Test_shareObject(t *testing.T) {
10231024
wantError: nil,
10241025
expected: "http://localhost:9090/api/v1/download-shared-object/aHR0cHM6Ly8xMjcuMC4wLjE6OTAwMC9jZXN0ZXN0L0F1ZGlvJTIwaWNvbi5zdmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTY=",
10251026
},
1027+
{
1028+
test: "returns redirect url with share link if redirect url env variable set",
1029+
setEnvVars: func() {
1030+
t.Setenv(ConsoleBrowserRedirectURL, "http://proxy-url.com:9012/console/subpath")
1031+
},
1032+
args: args{
1033+
r: &http.Request{
1034+
TLS: nil,
1035+
Host: "localhost:9090",
1036+
},
1037+
versionID: "2121434",
1038+
expires: "30s",
1039+
shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
1040+
return "http://someurl", nil
1041+
},
1042+
},
1043+
wantError: nil,
1044+
expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
1045+
},
1046+
{
1047+
test: "returns redirect url with share link if redirect url env variable set with trailing slash",
1048+
setEnvVars: func() {
1049+
t.Setenv(ConsoleBrowserRedirectURL, "http://proxy-url.com:9012/console/subpath/")
1050+
},
1051+
args: args{
1052+
r: &http.Request{
1053+
TLS: nil,
1054+
Host: "localhost:9090",
1055+
},
1056+
versionID: "2121434",
1057+
expires: "30s",
1058+
shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
1059+
return "http://someurl", nil
1060+
},
1061+
},
1062+
wantError: nil,
1063+
expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
1064+
},
10261065
}
10271066

10281067
for _, tt := range tests {
10291068
t.Run(tt.test, func(_ *testing.T) {
10301069
mcShareDownloadMock = tt.args.shareFunc
1070+
if tt.setEnvVars != nil {
1071+
tt.setEnvVars()
1072+
}
10311073
url, err := getShareObjectURL(ctx, client, tt.args.r, tt.args.versionID, tt.args.expires)
10321074
if tt.wantError != nil {
10331075
if !reflect.DeepEqual(err, tt.wantError) {

0 commit comments

Comments
 (0)