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.
This commit is contained in:
Harshavardhana
2021-06-17 00:50:56 -07:00
committed by GitHub
parent 03c24c6f14
commit 13f9f6c848
2 changed files with 4 additions and 12 deletions

View File

@@ -306,11 +306,6 @@ func (s consoleSTSAssumeRole) IsExpired() bool {
return s.stsAssumeRole.IsExpired() return s.stsAssumeRole.IsExpired()
} }
var (
MinioEndpoint = getMinIOServer()
MinioRegion = getMinIORegion()
)
func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.Credentials, error) { func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.Credentials, error) {
// Future authentication methods can be added under this switch statement // Future authentication methods can be added under this switch statement
switch { switch {
@@ -326,10 +321,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
// LDAP authentication for Console // LDAP authentication for Console
case ldap.GetLDAPEnabled(): case ldap.GetLDAPEnabled():
{ {
if MinioEndpoint == "" { creds, err := auth.GetCredentialsFromLDAP(GetConsoleSTSClient(), getMinIOServer(), accessKey, secretKey)
return nil, errors.New("endpoint cannot be empty for AssumeRoleSTS")
}
creds, err := auth.GetCredentialsFromLDAP(GetConsoleSTSClient(), MinioEndpoint, accessKey, secretKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -338,7 +330,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
// default authentication for Console is via STS (Security Token Service) against MinIO // default authentication for Console is via STS (Security Token Service) against MinIO
default: default:
{ {
if MinioEndpoint == "" || accessKey == "" || secretKey == "" { if accessKey == "" || secretKey == "" {
return nil, errors.New("credentials endpoint, access and secret key are mandatory for AssumeRoleSTS") return nil, errors.New("credentials endpoint, access and secret key are mandatory for AssumeRoleSTS")
} }
opts := credentials.STSAssumeRoleOptions{ opts := credentials.STSAssumeRoleOptions{
@@ -349,7 +341,7 @@ func newConsoleCredentials(accessKey, secretKey, location string) (*credentials.
} }
stsAssumeRole := &credentials.STSAssumeRole{ stsAssumeRole := &credentials.STSAssumeRole{
Client: GetConsoleSTSClient(), Client: GetConsoleSTSClient(),
STSEndpoint: MinioEndpoint, STSEndpoint: getMinIOServer(),
Options: opts, Options: opts,
} }
consoleSTSWrapper := consoleSTSAssumeRole{stsAssumeRole: stsAssumeRole} consoleSTSWrapper := consoleSTSAssumeRole{stsAssumeRole: stsAssumeRole}

View File

@@ -114,7 +114,7 @@ func getAccountPolicy(ctx context.Context, client MinioAdmin) (*iampolicy.Policy
// getConsoleCredentials will return consoleCredentials interface including the associated policy of the current account // getConsoleCredentials will return consoleCredentials interface including the associated policy of the current account
func getConsoleCredentials(ctx context.Context, accessKey, secretKey string) (*consoleCredentials, error) { func getConsoleCredentials(ctx context.Context, accessKey, secretKey string) (*consoleCredentials, error) {
creds, err := newConsoleCredentials(accessKey, secretKey, MinioRegion) creds, err := newConsoleCredentials(accessKey, secretKey, getMinIORegion())
if err != nil { if err != nil {
return nil, err return nil, err
} }