mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
s3: add RWMutex to iam, use RLock for concurrent reading
This commit is contained in:
parent
5018b22f36
commit
c683409e92
|
@ -24,7 +24,7 @@ type Iam interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type IdentityAccessManagement struct {
|
type IdentityAccessManagement struct {
|
||||||
m sync.Mutex
|
m sync.RWMutex
|
||||||
|
|
||||||
identities []*Identity
|
identities []*Identity
|
||||||
domain string
|
domain string
|
||||||
|
@ -135,21 +135,22 @@ func (iam *IdentityAccessManagement) loadS3ApiConfiguration(config *iam_pb.S3Api
|
||||||
identities = append(identities, t)
|
identities = append(identities, t)
|
||||||
}
|
}
|
||||||
iam.m.Lock()
|
iam.m.Lock()
|
||||||
|
|
||||||
// atomically switch
|
// atomically switch
|
||||||
iam.identities = identities
|
iam.identities = identities
|
||||||
|
|
||||||
iam.m.Unlock()
|
iam.m.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iam *IdentityAccessManagement) isEnabled() bool {
|
func (iam *IdentityAccessManagement) isEnabled() bool {
|
||||||
|
iam.m.RLock()
|
||||||
|
defer iam.m.RUnlock()
|
||||||
return len(iam.identities) > 0
|
return len(iam.identities) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iam *IdentityAccessManagement) lookupByAccessKey(accessKey string) (identity *Identity, cred *Credential, found bool) {
|
func (iam *IdentityAccessManagement) lookupByAccessKey(accessKey string) (identity *Identity, cred *Credential, found bool) {
|
||||||
|
|
||||||
|
iam.m.RLock()
|
||||||
|
defer iam.m.RUnlock()
|
||||||
for _, ident := range iam.identities {
|
for _, ident := range iam.identities {
|
||||||
for _, cred := range ident.Credentials {
|
for _, cred := range ident.Credentials {
|
||||||
// println("checking", ident.Name, cred.AccessKey)
|
// println("checking", ident.Name, cred.AccessKey)
|
||||||
|
@ -163,7 +164,8 @@ func (iam *IdentityAccessManagement) lookupByAccessKey(accessKey string) (identi
|
||||||
}
|
}
|
||||||
|
|
||||||
func (iam *IdentityAccessManagement) lookupAnonymous() (identity *Identity, found bool) {
|
func (iam *IdentityAccessManagement) lookupAnonymous() (identity *Identity, found bool) {
|
||||||
|
iam.m.RLock()
|
||||||
|
defer iam.m.RUnlock()
|
||||||
for _, ident := range iam.identities {
|
for _, ident := range iam.identities {
|
||||||
if ident.Name == "anonymous" {
|
if ident.Name == "anonymous" {
|
||||||
return ident, true
|
return ident, true
|
||||||
|
|
Loading…
Reference in a new issue