fix: ldap commands don't accept config name (#4499)

This commit is contained in:
Aditya Manthramurthy
2023-03-18 16:38:27 -07:00
committed by GitHub
parent 5d334f4960
commit 0e97683460
6 changed files with 78 additions and 34 deletions
+8 -2
View File
@@ -18,6 +18,7 @@
package cmd
import (
"errors"
"strings"
"github.com/minio/cli"
@@ -36,13 +37,13 @@ var adminIDPLdapAddCmd = cli.Command{
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
{{.HelpName}} TARGET [CFG_PARAMS...]
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Create a default LDAP IDP configuration (CFG_NAME is omitted).
1. Create LDAP IDentity Provider configuration.
{{.Prompt}} {{.HelpName}} myminio/ \
server_addr=myldapserver:636 \
lookup_bind_dn=cn=admin,dc=min,dc=io \
@@ -74,6 +75,11 @@ func mainAdminIDPLDAPAdd(ctx *cli.Context) error {
input = args[2:]
}
if cfgName != madmin.Default {
fatalIf(probe.NewError(errors.New("all config parameters must be of the form \"key=value\"")),
"Bad LDAP IDP configuration")
}
inputCfg := strings.Join(input, " ")
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, false)
+6 -4
View File
@@ -32,20 +32,22 @@ var adminIDPLdapDisableCmd = cli.Command{
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET [CFG_NAME]
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Disable the default LDAP IDP configuration (CFG_NAME is omitted).
1. Disable the default LDAP IDP configuration.
{{.Prompt}} {{.HelpName}} play/
2. Disable LDAP IDP configuration named "dex_test".
{{.Prompt}} {{.HelpName}} play/ dex_test
`,
}
func mainAdminIDPLDAPDisable(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
showCommandHelpAndExit(ctx, 1)
}
isOpenID, enable := false, false
return adminIDPEnableDisable(ctx, isOpenID, enable)
}
+6 -4
View File
@@ -32,20 +32,22 @@ var adminIDPLdapEnableCmd = cli.Command{
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET [CFG_NAME]
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Enable the default LDAP IDP configuration (CFG_NAME is omitted).
1. Enable the LDAP IDP configuration.
{{.Prompt}} {{.HelpName}} play/
2. Enable LDAP IDP configuration named "dex_test".
{{.Prompt}} {{.HelpName}} play/ dex_test
`,
}
func mainAdminIDPLDAPEnable(ctx *cli.Context) error {
if len(ctx.Args()) != 1 {
showCommandHelpAndExit(ctx, 1)
}
isOpenID, enable := false, true
return adminIDPEnableDisable(ctx, isOpenID, enable)
}
+5 -11
View File
@@ -19,6 +19,7 @@ package cmd
import (
"github.com/minio/cli"
"github.com/minio/madmin-go/v2"
)
var adminIDPLdapInfoCmd = cli.Command{
@@ -32,29 +33,22 @@ var adminIDPLdapInfoCmd = cli.Command{
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET [CFG_NAME]
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Get configuration info on the default LDAP IDP configuration (CFG_NAME is omitted).
1. Get configuration info on the LDAP IDP configuration.
{{.Prompt}} {{.HelpName}} play/
2. Get configuration info on LDAP IDP configuration named "dex_test".
{{.Prompt}} {{.HelpName}} play/ dex_test
`,
}
func mainAdminIDPLDAPInfo(ctx *cli.Context) error {
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
if len(ctx.Args()) != 1 {
showCommandHelpAndExit(ctx, 1)
}
args := ctx.Args()
var cfgName string
if len(args) == 2 {
cfgName = args.Get(1)
}
var cfgName string = madmin.Default
return adminIDPInfo(ctx, false, cfgName)
}
+8 -10
View File
@@ -17,7 +17,10 @@
package cmd
import "github.com/minio/cli"
import (
"github.com/minio/cli"
"github.com/minio/madmin-go/v2"
)
var adminIDPLdapRemoveCmd = cli.Command{
Name: "remove",
@@ -30,27 +33,22 @@ var adminIDPLdapRemoveCmd = cli.Command{
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET [CFG_NAME]
{{.HelpName}} TARGET
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Remove the default LDAP IDP configuration (CFG_NAME is omitted).
1. Remove the default LDAP IDP configuration.
{{.Prompt}} {{.HelpName}} play/
`,
}
func mainAdminIDPLDAPRemove(ctx *cli.Context) error {
if len(ctx.Args()) < 1 || len(ctx.Args()) > 2 {
if len(ctx.Args()) != 1 {
showCommandHelpAndExit(ctx, 1)
}
args := ctx.Args()
var cfgName string
if len(args) == 2 {
cfgName = args.Get(1)
}
var cfgName string = madmin.Default
return adminIDPRemove(ctx, false, cfgName)
}
+45 -3
View File
@@ -17,7 +17,14 @@
package cmd
import "github.com/minio/cli"
import (
"errors"
"strings"
"github.com/minio/cli"
"github.com/minio/madmin-go/v2"
"github.com/minio/mc/pkg/probe"
)
var adminIDPLdapUpdateCmd = cli.Command{
Name: "update",
@@ -30,13 +37,13 @@ var adminIDPLdapUpdateCmd = cli.Command{
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} TARGET [CFG_NAME] [CFG_PARAMS...]
{{.HelpName}} TARGET [CFG_PARAMS...]
FLAGS:
{{range .VisibleFlags}}{{.}}
{{end}}
EXAMPLES:
1. Create/Update the default LDAP IDP configuration (CFG_NAME is omitted).
1. Update the LDAP IDP configuration.
{{.Prompt}} {{.HelpName}} play/ \
lookup_bind_dn=cn=admin,dc=min,dc=io \
lookup_bind_password=somesecret
@@ -44,5 +51,40 @@ EXAMPLES:
}
func mainAdminIDPLDAPUpdate(ctx *cli.Context) error {
if len(ctx.Args()) < 2 {
showCommandHelpAndExit(ctx, 1)
}
args := ctx.Args()
aliasedURL := args.Get(0)
// Create a new MinIO Admin Client
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
cfgName := madmin.Default
input := args[1:]
if !strings.Contains(args.Get(1), "=") {
cfgName = args.Get(1)
input = args[2:]
}
if cfgName != madmin.Default {
fatalIf(probe.NewError(errors.New("all config parameters must be of the form \"key=value\"")),
"Bad LDAP IDP configuration")
}
inputCfg := strings.Join(input, " ")
restart, e := client.AddOrUpdateIDPConfig(globalContext, madmin.LDAPIDPCfg, cfgName, inputCfg, true)
fatalIf(probe.NewError(e), "Unable to update LDAP IDP configuration")
// Print set config result
printMsg(configSetMessage{
targetAlias: aliasedURL,
restart: restart,
})
return nil
}