本文整理匯總了Golang中github.com/dorzheh/deployer/ui/dialog_ui.DialogUi.GetPasswordFromInput方法的典型用法代碼示例。如果您正苦於以下問題:Golang DialogUi.GetPasswordFromInput方法的具體用法?Golang DialogUi.GetPasswordFromInput怎麽用?Golang DialogUi.GetPasswordFromInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dorzheh/deployer/ui/dialog_ui.DialogUi
的用法示例。
在下文中一共展示了DialogUi.GetPasswordFromInput方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UiSshConfig
func UiSshConfig(ui *gui.DialogUi) (*sshconf.Config, error) {
cfg := new(sshconf.Config)
cfg.Port = "22"
cfg.User = "root"
origlist := []string{"IP : ", "1", "1", "", "1", "10", "22", "0", "0",
"SSH Port: ", "2", "1", cfg.Port, "2", "10", "22", "0", "0",
"Username: ", "3", "1", cfg.User, "3", "10", "22", "0", "0"}
MainLoop:
for {
ui.HelpButton(true)
ui.SetHelpLabel("Back")
reslist, err := ui.Mixedform("Remote session configuration", false, origlist[0:]...)
if err != nil {
return nil, err
}
if len(reslist) < 3 {
continue
}
if net.ParseIP(reslist[0]) == nil {
continue
}
cfg.Host = reslist[0]
portDig, err := strconv.Atoi(reslist[1])
if err != nil {
return nil, utils.FormatError(err)
}
if portDig > 65535 {
continue
}
AuthLoop:
for {
ui.SetTitle("Authentication method")
ui.SetSize(9, 18)
ui.HelpButton(true)
ui.SetHelpLabel("Back")
val, err := ui.Menu(2, "1", "Password", "2", "Private key")
if err != nil {
switch err.Error() {
case gui.DialogMoveBack:
continue MainLoop
case gui.DialogExit:
os.Exit(1)
}
}
switch val {
case "1":
cfg.Password, err = ui.GetPasswordFromInput(cfg.Host, cfg.User, "Back", "", false)
case "2":
cfg.PrvtKeyFile, err = ui.GetPathToFileFromInput("Path to ssh private key file", "Back", "")
}
if err != nil {
switch err.Error() {
case gui.DialogMoveBack:
continue AuthLoop
case gui.DialogExit:
os.Exit(1)
}
}
break MainLoop
}
}
run := utils.RunFunc(cfg)
errCh := make(chan error)
defer close(errCh)
go func() {
// verifying that user is able execute a command by using sudo
_, err := run("uname")
errCh <- err
}()
if err := ui.Wait("Trying to establish SSH connection to remote host.\nPlease wait...", time.Second*1, time.Second*5, errCh); err != nil {
ui.Output(gui.Warning, "Unable to establish SSH connection.", "Press <OK> to return to menu.")
goto MainLoop
}
return cfg, nil
}