Skip to content

Commit

Permalink
rewrtie accesskeys list command
Browse files Browse the repository at this point in the history
  • Loading branch information
taran-p committed May 28, 2024
1 parent 6537d84 commit 43a9388
Showing 1 changed file with 44 additions and 19 deletions.
63 changes: 44 additions & 19 deletions cmd/idp-ldap-accesskey-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ var idpLdapAccesskeyListFlags = []cli.Flag{
},
cli.BoolFlag{
Name: "self",
Usage: "list access keys for the authenticated user if admin",
Usage: "list access keys for the authenticated user",
},
cli.BoolFlag{
Name: "all",
Usage: "list all access keys for all LDAP users",
},
}

Expand Down Expand Up @@ -130,34 +134,55 @@ func mainIDPLdapAccesskeyList(ctx *cli.Context) error {
}

usersOnly := ctx.Bool("users-only")
tempOnly := ctx.Bool("sts-only")
permanentOnly := ctx.Bool("svcacc-only")
isSelf := ctx.Bool("self")
listType := ""

if (usersOnly && permanentOnly) || (usersOnly && tempOnly) || (permanentOnly && tempOnly) {
e := errors.New("only one of --users-only, --temp-only, or --permanent-only can be specified")
fatalIf(probe.NewError(e), "Invalid flags.")
}
if tempOnly {
listType = "sts-only"
} else if permanentOnly {
listType = "svcacc-only"
}
stsOnly := ctx.Bool("temp-only")
svcaccOnly := ctx.Bool("svcacc-only")
selfFlag := ctx.Bool("self")
allFlag := ctx.Bool("all")

args := ctx.Args()
aliasedURL := args.Get(0)
userArg := args.Tail()
users := args.Tail()

var e error
if (usersOnly && svcaccOnly) || (usersOnly && stsOnly) || (svcaccOnly && stsOnly) {
e = errors.New("only one of --users-only, --temp-only, or --permanent-only can be specified")
} else if selfFlag && allFlag {
e = errors.New("only one of --self or --all can be specified")
} else if (selfFlag || allFlag) && len(users) > 0 {
e = errors.New("user DNs cannot be specified with --self or --all")
}
fatalIf(probe.NewError(e), "Invalid flags.")

// If no users/self/all flags are specified, tentatively assume --all
// If access is denied on tentativeAll, retry with self
// This is to maintain compatibility with the previous behavior
tentativeAll := false
if !selfFlag && !allFlag && len(users) == 0 {
tentativeAll = true
allFlag = true
}

var listType string
switch {
case usersOnly:
listType = madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListUsersOnly

Check failure on line 168 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListUsersOnly
case stsOnly:
listType = madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListSTSOnly

Check failure on line 170 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListSTSOnly
case svcaccOnly:
listType = madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListSvcaccOnly

Check failure on line 172 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListSvcaccOnly
default:
listType = madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

undefined: madmin.AccessKeyListAll

Check failure on line 174 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

undefined: madmin.AccessKeyListAll
}

// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")

accessKeysMap, e := client.ListAccessKeysLDAP(globalContext, userArg, listType, isSelf)
accessKeysMap, e := client.ListAccessKeysLDAPv2(globalContext, users, listType, allFlag)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 181 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)
if e != nil {
if e.Error() == "Access Denied." && !isSelf {
if e.Error() == "Access Denied." && tentativeAll {
// retry with self
accessKeysMap, e = client.ListAccessKeysLDAP(globalContext, userArg, listType, true)
accessKeysMap, e = client.ListAccessKeysLDAPv2(globalContext, users, listType, false)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Analysis

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Test on Go 1.22.x and macos-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / vetchecks

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.22.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)

Check failure on line 185 in cmd/idp-ldap-accesskey-list.go

View workflow job for this annotation

GitHub Actions / Build Tests with Go 1.21.x on ubuntu-latest

client.ListAccessKeysLDAPv2 undefined (type *madmin.AdminClient has no field or method ListAccessKeysLDAPv2)
}
fatalIf(probe.NewError(e), "Unable to list access keys.")
}
Expand Down

0 comments on commit 43a9388

Please sign in to comment.