本文整理匯總了Golang中github.com/drone/drone-go/drone.Client.RepoKey方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.RepoKey方法的具體用法?Golang Client.RepoKey怎麽用?Golang Client.RepoKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/drone/drone-go/drone.Client
的用法示例。
在下文中一共展示了Client.RepoKey方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SecureYamlCmd
func SecureYamlCmd(c *cli.Context, client drone.Client) error {
var (
repo = c.String("repo")
inFile = c.String("in")
outFile = c.String("out")
ymlFile = c.String("yaml")
checksum = c.BoolT("checksum")
)
owner, name, err := parseRepo(repo)
if err != nil {
return err
}
keypair, err := client.RepoKey(owner, name)
if err != nil {
return err
}
key, err := toPublicKey(keypair.Public)
if err != nil {
return err
}
// read the .drone.sec.yml file (plain text)
plaintext, err := readInput(inFile)
if err != nil {
return err
}
// parse the .drone.sec.yml file
sec := new(secure.Secure)
err = yaml.Unmarshal(plaintext, sec)
if err != nil {
return err
}
// read the .drone.yml file and caclulate the
// checksum. add to the .drone.sec.yml file.
yml, err := ioutil.ReadFile(ymlFile)
if err == nil && checksum {
sec.Checksum = sha256sum(string(yml))
}
// re-marshal the .drone.sec.yml file since we've
// added the checksum
plaintext, err = yaml.Marshal(sec)
if err != nil {
return err
}
// encrypt the .drone.sec.yml file
ciphertext, err := encrypt(plaintext, key)
if err != nil {
return err
}
// write the encrypted .drone.sec.yml file to .drone.sec
return writeOutput(outFile, ciphertext)
}