honor client context in IAM user/policy listing calls (#14682)

This commit is contained in:
polaris-megrez 2022-04-20 00:00:19 +08:00 committed by GitHub
parent 598ce1e354
commit 6bc3c74c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 21 deletions

View File

@ -90,7 +90,7 @@ func (a adminAPIHandlers) ListBucketUsers(w http.ResponseWriter, r *http.Request
password := cred.SecretKey
allCredentials, err := globalIAMSys.ListBucketUsers(bucket)
allCredentials, err := globalIAMSys.ListBucketUsers(ctx, bucket)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
@ -124,7 +124,7 @@ func (a adminAPIHandlers) ListUsers(w http.ResponseWriter, r *http.Request) {
password := cred.SecretKey
allCredentials, err := globalIAMSys.ListUsers()
allCredentials, err := globalIAMSys.ListUsers(ctx)
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return

View File

@ -538,9 +538,12 @@ func (sys *IAMSys) ListPolicies(ctx context.Context, bucketName string) (map[str
return nil, errServerNotInitialized
}
<-sys.configLoaded
return sys.store.ListPolicies(ctx, bucketName)
select {
case <-sys.configLoaded:
return sys.store.ListPolicies(ctx, bucketName)
case <-ctx.Done():
return nil, ctx.Err()
}
}
// SetPolicy - sets a new named policy.
@ -673,25 +676,30 @@ func (sys *IAMSys) SetTempUser(ctx context.Context, accessKey string, cred auth.
}
// ListBucketUsers - list all users who can access this 'bucket'
func (sys *IAMSys) ListBucketUsers(bucket string) (map[string]madmin.UserInfo, error) {
func (sys *IAMSys) ListBucketUsers(ctx context.Context, bucket string) (map[string]madmin.UserInfo, error) {
if !sys.Initialized() {
return nil, errServerNotInitialized
}
<-sys.configLoaded
return sys.store.GetBucketUsers(bucket)
select {
case <-sys.configLoaded:
return sys.store.GetBucketUsers(bucket)
case <-ctx.Done():
return nil, ctx.Err()
}
}
// ListUsers - list all users.
func (sys *IAMSys) ListUsers() (map[string]madmin.UserInfo, error) {
func (sys *IAMSys) ListUsers(ctx context.Context) (map[string]madmin.UserInfo, error) {
if !sys.Initialized() {
return nil, errServerNotInitialized
}
<-sys.configLoaded
return sys.store.GetUsers(), nil
select {
case <-sys.configLoaded:
return sys.store.GetUsers(), nil
case <-ctx.Done():
return nil, ctx.Err()
}
}
// ListLDAPUsers - list LDAP users which has
@ -909,9 +917,12 @@ func (sys *IAMSys) ListServiceAccounts(ctx context.Context, accessKey string) ([
return nil, errServerNotInitialized
}
<-sys.configLoaded
return sys.store.ListServiceAccounts(ctx, accessKey)
select {
case <-sys.configLoaded:
return sys.store.ListServiceAccounts(ctx, accessKey)
case <-ctx.Done():
return nil, ctx.Err()
}
}
// GetServiceAccount - wrapper method to get information about a service account
@ -1311,9 +1322,12 @@ func (sys *IAMSys) ListGroups(ctx context.Context) (r []string, err error) {
return r, errServerNotInitialized
}
<-sys.configLoaded
return sys.store.ListGroups(ctx)
select {
case <-sys.configLoaded:
return sys.store.ListGroups(ctx)
case <-ctx.Done():
return nil, ctx.Err()
}
}
// PolicyDBSet - sets a policy for a user or group in the PolicyDB.

View File

@ -2892,7 +2892,7 @@ func (c *SiteReplicationSys) SiteReplicationMetaInfo(ctx context.Context, objAPI
}
} else {
// get users/group info on local.
userInfoMap, errU := globalIAMSys.ListUsers()
userInfoMap, errU := globalIAMSys.ListUsers(ctx)
if errU != nil {
return info, errSRBackendIssue(errU)
}