Skip to content

Commit

Permalink
Update admin policy/user commands with new policy info API
Browse files Browse the repository at this point in the history
  • Loading branch information
donatello committed Dec 2, 2021
1 parent 8a207df commit 77e9e91
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
15 changes: 9 additions & 6 deletions cmd/admin-policy-add.go
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/fatih/color"
"github.com/minio/cli"
json "github.com/minio/colorjson"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/console"
)
Expand Down Expand Up @@ -66,11 +67,11 @@ func checkAdminPolicyAddSyntax(ctx *cli.Context) {
// userPolicyMessage container for content message structure
type userPolicyMessage struct {
op string
Status string `json:"status"`
Policy string `json:"policy,omitempty"`
PolicyJSON json.RawMessage `json:"policyJSON,omitempty"`
UserOrGroup string `json:"userOrGroup,omitempty"`
IsGroup bool `json:"isGroup"`
Status string `json:"status"`
Policy string `json:"policy,omitempty"`
PolicyInfo madmin.PolicyInfo `json:"policyInfo,omitempty"`
UserOrGroup string `json:"userOrGroup,omitempty"`
IsGroup bool `json:"isGroup"`
}

func (u userPolicyMessage) accountType() string {
Expand All @@ -87,7 +88,9 @@ func (u userPolicyMessage) accountType() string {
func (u userPolicyMessage) String() string {
switch u.op {
case "info":
return string(u.PolicyJSON)
buf, err := json.MarshalIndent(u.PolicyInfo, "", " ")
fatalIf(probe.NewError(err), "Unable to marshal to JSON.")
return string(buf)
case "list":
policyFieldMaxLen := 20
// Create a new pretty table with cols configuration
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-policy-info.go
Expand Up @@ -72,13 +72,13 @@ func mainAdminPolicyInfo(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection")

buf, e := client.InfoCannedPolicy(globalContext, policyName)
pinfo, e := client.InfoCannedPolicyV2(globalContext, policyName)
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch policy")

printMsg(userPolicyMessage{
op: "info",
Policy: policyName,
PolicyJSON: buf,
PolicyInfo: *pinfo,
})

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-user-policy.go
Expand Up @@ -73,10 +73,10 @@ func mainAdminUserPolicy(ctx *cli.Context) error {
user, e := client.GetUserInfo(globalContext, args.Get(1))
fatalIf(probe.NewError(e).Trace(args...), "Unable to get user info")

buf, e := client.InfoCannedPolicy(globalContext, user.PolicyName)
pinfo, e := client.InfoCannedPolicyV2(globalContext, user.PolicyName)
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch user policy document")

fmt.Println(string(buf))
fmt.Println(string(pinfo.Policy))

return nil
}
3 changes: 3 additions & 0 deletions go.mod
Expand Up @@ -64,3 +64,6 @@ require (
gopkg.in/yaml.v2 v2.4.0
maze.io/x/duration v0.0.0-20160924141736-faac084b6075
)


replace github.com/minio/madmin-go => ../madmin-go

0 comments on commit 77e9e91

Please sign in to comment.