本文整理汇总了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
}