From bfabb4159b21bb27f92d39570afa46cc7b77e152 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 11 Jul 2020 09:11:15 -0700 Subject: [PATCH] refactoring --- weed/s3api/auth_credentials.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/weed/s3api/auth_credentials.go b/weed/s3api/auth_credentials.go index c1e8dff1e..30052878b 100644 --- a/weed/s3api/auth_credentials.go +++ b/weed/s3api/auth_credentials.go @@ -91,7 +91,13 @@ func (iam *IdentityAccessManagement) loadS3ApiConfiguration(fileName string) err return nil } +func (iam *IdentityAccessManagement) isEnabled() bool { + + return len(iam.identities) > 0 +} + func (iam *IdentityAccessManagement) lookupByAccessKey(accessKey string) (identity *Identity, cred *Credential, found bool) { + for _, ident := range iam.identities { for _, cred := range ident.Credentials { if cred.AccessKey == accessKey { @@ -104,7 +110,7 @@ func (iam *IdentityAccessManagement) lookupByAccessKey(accessKey string) (identi func (iam *IdentityAccessManagement) Auth(f http.HandlerFunc, action Action) http.HandlerFunc { - if len(iam.identities) == 0 { + if iam.isEnabled() { return f }