Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to disable the share redirect feature #3351

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,7 @@ func getConsoleAnimatedLogin() bool {
func getConsoleBrowserRedirectURL() string {
return env.Get(ConsoleBrowserRedirectURL, "")
}

func getConsoleBrowserRedirect() bool {
return strings.ToLower(env.Get(ConsoleBrowserRedirect, "on")) == "on"
}
1 change: 1 addition & 0 deletions api/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
ConsoleDevMode = "CONSOLE_DEV_MODE"
ConsoleAnimatedLogin = "CONSOLE_ANIMATED_LOGIN"
ConsoleBrowserRedirectURL = "CONSOLE_BROWSER_REDIRECT_URL"
ConsoleBrowserRedirect = "CONSOLE_BROWSER_REDIRECT"
LogSearchQueryAuthToken = "LOGSEARCH_QUERY_AUTH_TOKEN"
SlashSeparator = "/"
LocalAddress = "127.0.0.1"
Expand Down
12 changes: 8 additions & 4 deletions api/user_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,10 +1100,14 @@ func getShareObjectURL(ctx context.Context, client MCClient, r *http.Request, ve
return nil, pErr.Cause
}

encodedMinIOURL := b64.URLEncoding.EncodeToString([]byte(minioURL))
requestURL := getRequestURLWithScheme(r)
objURL := fmt.Sprintf("%s/api/v1/download-shared-object/%s", requestURL, encodedMinIOURL)
return &objURL, nil
if getConsoleBrowserRedirect() {
encodedMinIOURL := b64.URLEncoding.EncodeToString([]byte(minioURL))
requestURL := getRequestURLWithScheme(r)
objURL := fmt.Sprintf("%s/api/v1/download-shared-object/%s", requestURL, encodedMinIOURL)
return &objURL, nil
}

return &minioURL, nil
}

func getRequestURLWithScheme(r *http.Request) string {
Expand Down
19 changes: 19 additions & 0 deletions api/user_objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,25 @@ func Test_shareObject(t *testing.T) {
wantError: nil,
expected: "http://proxy-url.com:9012/console/subpath/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
},
{
test: "returns minio url without share link if redirect env variable set to off",
setEnvVars: func() {
t.Setenv(ConsoleBrowserRedirect, "off")
},
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://someurl",
},
}

for _, tt := range tests {
Expand Down