-
Notifications
You must be signed in to change notification settings - Fork 599
Update to print skipped entities during IAM import #5032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8790195
Update to print skipped entities during IAM import
shtripat 651cd26
use v2 version of API ImportIAM
shtripat eb7c183
print missing list conditionally if exists
shtripat 1ae641e
align with latest madmin-go changes
shtripat ec1f36f
new structure of ImportIAMResult
shtripat e99eedf
gofumt
shtripat ff251f7
correct usages of IAMErrPolicyEntity
shtripat 97a32d5
incorporate suggestions
shtripat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,13 @@ import ( | |
"io" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/klauspost/compress/zip" | ||
"github.com/minio/cli" | ||
json "github.com/minio/colorjson" | ||
"github.com/minio/madmin-go/v3" | ||
"github.com/minio/mc/pkg/probe" | ||
"github.com/minio/pkg/v3/console" | ||
) | ||
|
||
var adminClusterIAMImportCmd = cli.Command{ | ||
|
@@ -54,6 +56,123 @@ EXAMPLES: | |
`, | ||
} | ||
|
||
type iamImportInfo madmin.ImportIAMResult | ||
|
||
func (i iamImportInfo) JSON() string { | ||
bs, e := json.MarshalIndent(madmin.ImportIAMResult(i), "", " ") | ||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.") | ||
return string(bs) | ||
} | ||
|
||
func (i iamImportInfo) String() string { | ||
var messages []string | ||
info := madmin.ImportIAMResult(i) | ||
messages = append(messages, processIAMEntities(info.Skipped, "Skipped")...) | ||
messages = append(messages, processIAMEntities(info.Removed, "Removed")...) | ||
messages = append(messages, processIAMEntities(info.Added, "Added")...) | ||
messages = append(messages, processErrIAMEntities(info.Failed)...) | ||
return strings.Join(messages, "\n") | ||
} | ||
|
||
func processIAMEntities(entities madmin.IAMEntities, action string) []string { | ||
var messages []string | ||
if len(entities.Policies) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s policies: %v", action, strings.Join(entities.Policies, ", "))) | ||
} | ||
if len(entities.Users) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s users: %v", action, strings.Join(entities.Users, ", "))) | ||
} | ||
if len(entities.Groups) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s groups: %v", action, strings.Join(entities.Groups, ", "))) | ||
} | ||
if len(entities.ServiceAccounts) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s service accounts: %v", action, strings.Join(entities.ServiceAccounts, ", "))) | ||
} | ||
var users []string | ||
for _, pol := range entities.UserPolicies { | ||
for name := range pol { | ||
users = append(users, name) | ||
} | ||
} | ||
if len(users) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s policies for users: %v", action, strings.Join(users, ", "))) | ||
} | ||
var groups []string | ||
for _, pol := range entities.GroupPolicies { | ||
for name := range pol { | ||
groups = append(groups, name) | ||
} | ||
} | ||
if len(groups) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s policies for groups: %v", action, strings.Join(groups, ", "))) | ||
} | ||
var stsarr []string | ||
for _, pol := range entities.STSPolicies { | ||
for name := range pol { | ||
stsarr = append(stsarr, name) | ||
} | ||
} | ||
if len(stsarr) > 0 { | ||
messages = append(messages, fmt.Sprintf("%s policies for sts: %v", action, strings.Join(stsarr, ", "))) | ||
} | ||
return messages | ||
} | ||
|
||
func processErrIAMEntities(entities madmin.IAMErrEntities) []string { | ||
var messages []string | ||
|
||
var policies []string | ||
for _, entry := range entities.Policies { | ||
policies = append(policies, entry.Name) | ||
} | ||
if len(policies) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add policies: %v", strings.Join(policies, ", "))) | ||
} | ||
var users []string | ||
for _, entry := range entities.Users { | ||
users = append(users, entry.Name) | ||
} | ||
if len(users) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add users: %v", strings.Join(users, ", "))) | ||
} | ||
var groups []string | ||
for _, entry := range entities.Groups { | ||
groups = append(groups, entry.Name) | ||
} | ||
if len(groups) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add groups: %v", strings.Join(groups, ", "))) | ||
} | ||
var sas []string | ||
for _, entry := range entities.ServiceAccounts { | ||
sas = append(sas, entry.Name) | ||
} | ||
if len(sas) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add service accounts: %v", strings.Join(sas, ", "))) | ||
} | ||
var polusers []string | ||
for _, pol := range entities.UserPolicies { | ||
polusers = append(polusers, pol.Name) | ||
} | ||
if len(polusers) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add policies for users: %v", strings.Join(polusers, ", "))) | ||
} | ||
var polgroups []string | ||
for _, pol := range entities.GroupPolicies { | ||
polgroups = append(polgroups, pol.Name) | ||
} | ||
if len(polgroups) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add policies for groups: %v", strings.Join(polgroups, ", "))) | ||
} | ||
var polsts []string | ||
for _, pol := range entities.STSPolicies { | ||
polsts = append(polsts, pol.Name) | ||
} | ||
if len(polsts) > 0 { | ||
messages = append(messages, fmt.Sprintf("Failed to add policies for sts: %v", strings.Join(polsts, ", "))) | ||
} | ||
return messages | ||
} | ||
|
||
func checkIAMImportSyntax(ctx *cli.Context) { | ||
if len(ctx.Args()) != 2 { | ||
showCommandHelpAndExit(ctx, 1) // last argument is exit code | ||
|
@@ -95,11 +214,13 @@ func mainClusterIAMImport(ctx *cli.Context) error { | |
return nil | ||
} | ||
|
||
e = client.ImportIAM(context.Background(), f) | ||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to import IAM info.") | ||
|
||
if !globalJSON { | ||
console.Infof("IAM info imported to %s from %s\n", aliasedURL, args.Get(1)) | ||
iamr, e := client.ImportIAMV2(context.Background(), f) | ||
if e != nil { | ||
e = client.ImportIAM(context.Background(), f) | ||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to import IAM info.") | ||
} else { | ||
Comment on lines
+218
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please test this with previous minio versions, so that this fallback works properly. |
||
printMsg(iamImportInfo(iamr)) | ||
} | ||
|
||
return nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.