@@ -23,6 +23,7 @@ import (
2323 "net/http"
2424 "net/url"
2525 "os"
26+ "slices"
2627
2728 "github.com/fatih/color"
2829 "github.com/minio/cli"
@@ -33,12 +34,23 @@ import (
3334 "golang.org/x/term"
3435)
3536
37+ var idpLdapAccesskeyCreateWithLoginFlags = []cli.Flag {
38+ cli.StringFlag {
39+ Name : "ldap-username" ,
40+ Usage : "username to login as (prompt if empty)" ,
41+ },
42+ cli.StringFlag {
43+ Name : "ldap-password" ,
44+ Usage : "password for ldap-user (prompt if empty)" ,
45+ },
46+ }
47+
3648var idpLdapAccesskeyCreateWithLoginCmd = cli.Command {
3749 Name : "create-with-login" ,
3850 Usage : "login using LDAP credentials to generate access key pair" ,
3951 Action : mainIDPLdapAccesskeyCreateWithLogin ,
4052 Before : setGlobalsFromContext ,
41- Flags : append ( idpLdapAccesskeyCreateFlags , globalFlags ... ),
53+ Flags : slices . Concat ( idpLdapAccesskeyCreateWithLoginFlags , idpLdapAccesskeyCreateFlags , globalFlags ),
4254 OnUsageError : onUsageError ,
4355 CustomHelpTemplate : `NAME:
4456 {{.HelpName}} - {{.Usage}}
@@ -97,16 +109,22 @@ func loginLDAPAccesskey(ctx *cli.Context) (*madmin.AdminClient, madmin.AddServic
97109 console .SetColor (cred , color .New (color .FgYellow , color .Italic ))
98110 reader := bufio .NewReader (os .Stdin )
99111
100- fmt .Printf ("%s" , console .Colorize (cred , "Enter LDAP Username: " ))
101- value , _ , e := reader .ReadLine ()
102- fatalIf (probe .NewError (e ), "unable to read username" )
103- username := string (value )
112+ username := ctx .String ("ldap-username" )
113+ if username == "" {
114+ fmt .Printf ("%s" , console .Colorize (cred , "Enter LDAP Username: " ))
115+ value , _ , e := reader .ReadLine ()
116+ fatalIf (probe .NewError (e ), "unable to read username" )
117+ username = string (value )
118+ }
104119
105- fmt .Printf ("%s" , console .Colorize (cred , "Enter LDAP Password: " ))
106- bytePassword , e := term .ReadPassword (int (os .Stdin .Fd ()))
107- fatalIf (probe .NewError (e ), "unable to read password" )
108- fmt .Printf ("\n " )
109- password := string (bytePassword )
120+ password := ctx .String ("ldap-password" )
121+ if password == "" {
122+ fmt .Printf ("%s" , console .Colorize (cred , "Enter LDAP Password: " ))
123+ bytePassword , e := term .ReadPassword (int (os .Stdin .Fd ()))
124+ fatalIf (probe .NewError (e ), "unable to read password" )
125+ fmt .Printf ("\n " )
126+ password = string (bytePassword )
127+ }
110128
111129 stsCreds , e := credentials .NewLDAPIdentity (urlStr , username , password )
112130 fatalIf (probe .NewError (e ), "unable to initialize LDAP identity" )
0 commit comments