Skip to content

Commit

Permalink
fix: print updates/merge multiple policy for a user (#4691)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-scheele authored Oct 24, 2023
1 parent 39a57a1 commit 75e7222
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/admin-user-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ package cmd

import (
"fmt"
"os"
"strings"

"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/colorjson"
"github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/v2/console"
"github.com/minio/pkg/v2/policy"
)

var adminUserPolicyCmd = cli.Command{
Expand Down Expand Up @@ -76,12 +79,24 @@ func mainAdminUserPolicy(ctx *cli.Context) error {
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch user policy document")
}

policies := strings.Split(user.PolicyName, ",")
for _, policy := range policies {
pinfo, e := getPolicyInfo(client, policy)
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch user policy document for policy "+policy)
fmt.Println(string(pinfo.Policy))
policyNames := strings.Split(user.PolicyName, ",")

var policies []policy.Policy
for _, policyName := range policyNames {
if policyName == "" {
continue
}
policyInfo, e := getPolicyInfo(client, policyName)
fatalIf(probe.NewError(e).Trace(), "Unable to fetch user policy document for policy "+policyName)

var policyObj policy.Policy
if e := json.Unmarshal(policyInfo.Policy, &policyObj); e != nil {
fatalIf(probe.NewError(e).Trace(), "Unable to unmarshal policy")
}
policies = append(policies, policyObj)
}

mergedPolicy := policy.MergePolicies(policies...)
json.NewEncoder(os.Stdout).Encode(mergedPolicy)
return nil
}

0 comments on commit 75e7222

Please sign in to comment.