Skip to content

Commit 13f9f6c

Browse files
fix: do not use var to define global sets (#818)
console when imported cannot honor certain environment values, we need to make sure to read it directly from environment.
1 parent 03c24c6 commit 13f9f6c

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

restapi/client.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
306306
return s.stsAssumeRole.IsExpired()
307307
}
308308

309-
var (
310-
MinioEndpoint = getMinIOServer()
311-
MinioRegion = getMinIORegion()
312-
)
313-
314309
func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.Credentials, error) {
315310
// Future authentication methods can be added under this switch statement
316311
switch {
@@ -326,10 +321,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
326321
// LDAP authentication for Console
327322
case ldap.GetLDAPEnabled():
328323
{
329-
if MinioEndpoint == "" {
330-
return nil, errors.New("endpoint cannot be empty for AssumeRoleSTS")
331-
}
332-
creds, err := auth.GetCredentialsFromLDAP(GetConsoleSTSClient(), MinioEndpoint, accessKey, secretKey)
324+
creds, err := auth.GetCredentialsFromLDAP(GetConsoleSTSClient(), getMinIOServer(), accessKey, secretKey)
333325
if err != nil {
334326
return nil, err
335327
}
@@ -338,7 +330,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
338330
// default authentication for Console is via STS (Security Token Service) against MinIO
339331
default:
340332
{
341-
if MinioEndpoint == "" || accessKey == "" || secretKey == "" {
333+
if accessKey == "" || secretKey == "" {
342334
return nil, errors.New("credentials endpoint, access and secret key are mandatory for AssumeRoleSTS")
343335
}
344336
opts := credentials.STSAssumeRoleOptions{
@@ -349,7 +341,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
349341
}
350342
stsAssumeRole := &credentials.STSAssumeRole{
351343
Client: GetConsoleSTSClient(),
352-
STSEndpoint: MinioEndpoint,
344+
STSEndpoint: getMinIOServer(),
353345
Options: opts,
354346
}
355347
consoleSTSWrapper := consoleSTSAssumeRole{stsAssumeRole: stsAssumeRole}

restapi/user_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func getAccountPolicy(ctx context.Context, client MinioAdmin) (*iampolicy.Policy
114114

115115
// getConsoleCredentials will return consoleCredentials interface including the associated policy of the current account
116116
func getConsoleCredentials(ctx context.Context, accessKey, secretKey string) (*consoleCredentials, error) {
117-
creds, err := newConsoleCredentials(accessKey, secretKey, MinioRegion)
117+
creds, err := newConsoleCredentials(accessKey, secretKey, getMinIORegion())
118118
if err != nil {
119119
return nil, err
120120
}

0 commit comments

Comments
 (0)