From 3350dbc50d8f428b8ee3a54f0e0d6fe4a53393e5 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 29 May 2021 09:22:22 -0700 Subject: [PATCH] always indent and reply policy JSON (#12399) --- cmd/admin-handlers-users.go | 10 +++++----- cmd/iam.go | 16 +++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/cmd/admin-handlers-users.go b/cmd/admin-handlers-users.go index 6d3893d7a..0d615a72d 100644 --- a/cmd/admin-handlers-users.go +++ b/cmd/admin-handlers-users.go @@ -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} diff --git a/cmd/iam.go b/cmd/iam.go index 816defb0b..b427e1578 100644 --- a/cmd/iam.go +++ b/cmd/iam.go @@ -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.