Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions cmd/idp-ldap-accesskey-create-with-login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"net/url"
"os"
"slices"

"github.com/fatih/color"
"github.com/minio/cli"
Expand All @@ -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}}
Expand Down Expand Up @@ -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")
Expand Down
Loading