本文整理匯總了Golang中github.com/hashicorp/otto/ui.Ui.Header方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ui.Header方法的具體用法?Golang Ui.Header怎麽用?Golang Ui.Header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hashicorp/otto/ui.Ui
的用法示例。
在下文中一共展示了Ui.Header方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: guessAndLoadPrivateKey
// guessAndLoadPrivateKey takes a path to a public key and determines if a
// private key exists by just stripping ".pub" from the end of it. if so,
// it attempts to load that key into the agent.
func guessAndLoadPrivateKey(ui ui.Ui, pubKeyPath string) (bool, error) {
fullPath, err := homedir.Expand(pubKeyPath)
if err != nil {
return false, err
}
if !strings.HasSuffix(fullPath, ".pub") {
return false, fmt.Errorf("No .pub suffix, cannot guess path.")
}
privKeyGuess := strings.TrimSuffix(fullPath, ".pub")
if _, err := os.Stat(privKeyGuess); os.IsNotExist(err) {
return false, fmt.Errorf("No file at guessed path.")
}
ui.Header("Loading key into SSH Agent")
ui.Message(fmt.Sprintf(
"The key you provided (%s) was not found in your SSH Agent.", pubKeyPath))
ui.Message(fmt.Sprintf(
"However, Otto found a private key here: %s", privKeyGuess))
ui.Message(fmt.Sprintf(
"Automatically running 'ssh-add %s'.", privKeyGuess))
ui.Message("If your SSH key has a passphrase, you will be prompted for it.")
ui.Message("")
if err := sshagent.Add(ui, privKeyGuess); err != nil {
return false, err
}
return true, nil
}
示例2: guestAndLoadPrivateKey
// guestAndLoadPrivateKey 獲得private key路徑,隻是依賴判斷去除.pub部分的內容
// 如果存在則直接裝在agent
func guestAndLoadPrivateKey(ui ui.Ui, pubKeyPath string) (bool, error) {
fullPath, err := homedir.Expand(pubKeyPath)
if err != nil {
return false, err
}
if !strings.HasSuffix(fullPath, ".pub") {
return false, fmt.Errorf("沒有找到.pub後綴的文件")
}
privKeyGuess := strings.TrimSuffix(fullPath, ".pub")
if _, err := os.Stat(privKeyGuess); os.IsNotExist(err) {
return false, fmt.Errorf("文件不存在!")
}
ui.Header("裝載key到SSH Agent")
ui.Message(fmt.Sprintf(
"在SSH Agent中沒有你提供的key (%s)", pubKeyPath))
ui.Message(fmt.Sprintf(
"然而,Otto在這裏:%s 找的了一個private key", privKeyGuess))
ui.Message(fmt.Sprintf(
"自動運行'ssh-add %s'.", privKeyGuess))
ui.Message("如果你的SSH key有密碼,你會看到如下提示")
ui.Message("")
if err := sshagent.Add(ui, privKeyGuess); err != nil {
return false, err
}
return true, nil
}