diff --git a/cmd/idp-ldap-accesskey-create-with-login.go b/cmd/idp-ldap-accesskey-create-with-login.go index af9c290f2c..b6d7b19406 100644 --- a/cmd/idp-ldap-accesskey-create-with-login.go +++ b/cmd/idp-ldap-accesskey-create-with-login.go @@ -23,6 +23,7 @@ import ( "net/http" "net/url" "os" + "slices" "github.com/fatih/color" "github.com/minio/cli" @@ -33,12 +34,23 @@ import ( "golang.org/x/term" ) +var idpLdapAccesskeyCreateWithLoginFlags = []cli.Flag{ + cli.StringFlag{ + Name: "ldap-username", + Usage: "username to login as (prompt if empty)", + }, + cli.StringFlag{ + Name: "ldap-password", + Usage: "password for ldap-user (prompt if empty)", + }, +} + var idpLdapAccesskeyCreateWithLoginCmd = cli.Command{ Name: "create-with-login", Usage: "login using LDAP credentials to generate access key pair", Action: mainIDPLdapAccesskeyCreateWithLogin, Before: setGlobalsFromContext, - Flags: append(idpLdapAccesskeyCreateFlags, globalFlags...), + Flags: slices.Concat(idpLdapAccesskeyCreateWithLoginFlags, idpLdapAccesskeyCreateFlags, globalFlags), OnUsageError: onUsageError, CustomHelpTemplate: `NAME: {{.HelpName}} - {{.Usage}} @@ -97,16 +109,22 @@ func loginLDAPAccesskey(ctx *cli.Context) (*madmin.AdminClient, madmin.AddServic console.SetColor(cred, color.New(color.FgYellow, color.Italic)) reader := bufio.NewReader(os.Stdin) - fmt.Printf("%s", console.Colorize(cred, "Enter LDAP Username: ")) - value, _, e := reader.ReadLine() - fatalIf(probe.NewError(e), "unable to read username") - username := string(value) + username := ctx.String("ldap-username") + if username == "" { + fmt.Printf("%s", console.Colorize(cred, "Enter LDAP Username: ")) + value, _, e := reader.ReadLine() + fatalIf(probe.NewError(e), "unable to read username") + username = string(value) + } - fmt.Printf("%s", console.Colorize(cred, "Enter LDAP Password: ")) - bytePassword, e := term.ReadPassword(int(os.Stdin.Fd())) - fatalIf(probe.NewError(e), "unable to read password") - fmt.Printf("\n") - password := string(bytePassword) + password := ctx.String("ldap-password") + if password == "" { + fmt.Printf("%s", console.Colorize(cred, "Enter LDAP Password: ")) + bytePassword, e := term.ReadPassword(int(os.Stdin.Fd())) + fatalIf(probe.NewError(e), "unable to read password") + fmt.Printf("\n") + password = string(bytePassword) + } stsCreds, e := credentials.NewLDAPIdentity(urlStr, username, password) fatalIf(probe.NewError(e), "unable to initialize LDAP identity")