always indent and reply policy JSON (#12399)

This commit is contained in:
Harshavardhana 2021-05-29 09:22:22 -07:00 committed by GitHub
parent 81d5688d56
commit 3350dbc50d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -784,7 +784,7 @@ func (a adminAPIHandlers) InfoServiceAccount(w http.ResponseWriter, r *http.Requ
svcAccountPolicy = svcAccountPolicy.Merge(globalIAMSys.GetCombinedPolicy(policiesNames...))
}
policyJSON, err := json.Marshal(svcAccountPolicy)
policyJSON, err := json.MarshalIndent(svcAccountPolicy, "", " ")
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
@ -1057,8 +1057,7 @@ func (a adminAPIHandlers) AccountInfoHandler(w http.ResponseWriter, r *http.Requ
return
}
p := globalIAMSys.GetCombinedPolicy(policies...)
buf, err := json.Marshal(p)
buf, err := json.MarshalIndent(globalIAMSys.GetCombinedPolicy(policies...), "", " ")
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
@ -1115,11 +1114,12 @@ func (a adminAPIHandlers) InfoCannedPolicy(w http.ResponseWriter, r *http.Reques
return
}
if err = json.NewEncoder(w).Encode(policy); err != nil {
buf, err := json.MarshalIndent(policy, "", " ")
if err != nil {
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
return
}
w.(http.Flusher).Flush()
w.Write(buf)
}
// ListBucketPolicies - GET /minio/admin/v3/list-canned-policies?bucket={bucket}

View File

@ -738,12 +738,18 @@ func (sys *IAMSys) InfoPolicy(policyName string) (iampolicy.Policy, error) {
sys.store.rlock()
defer sys.store.runlock()
v, ok := sys.iamPolicyDocsMap[policyName]
if !ok {
return iampolicy.Policy{}, errNoSuchPolicy
var combinedPolicy iampolicy.Policy
for _, policy := range strings.Split(policyName, ",") {
if policy == "" {
continue
}
v, ok := sys.iamPolicyDocsMap[policy]
if !ok {
return iampolicy.Policy{}, errNoSuchPolicy
}
combinedPolicy = combinedPolicy.Merge(v)
}
return v, nil
return combinedPolicy, nil
}
// ListPolicies - lists all canned policies.