本文整理匯總了Golang中github.com/coreos/etcd-ca/third_party/github.com/codegangsta/cli.Context.Args方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Args方法的具體用法?Golang Context.Args怎麽用?Golang Context.Args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/etcd-ca/third_party/github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Args方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newChainAction
func newChainAction(c *cli.Context) {
crt, err := depot.GetCertificateAuthority(d)
if err != nil {
fmt.Fprintln(os.Stderr, "Get CA certificate error:", err)
os.Exit(1)
}
// Should not fail if creating from depot
crtBytes, _ := crt.Export()
if len(c.Args()) == 0 {
fmt.Printf("%s", crtBytes)
return
}
name := c.Args()[0]
crtHost, err := depot.GetCertificateHost(d, name)
if err != nil {
fmt.Fprintln(os.Stderr, "Get certificate error:", err)
os.Exit(1)
}
crtHostBytes, _ := crtHost.Export()
if err = crt.VerifyHost(crtHost, name); err != nil {
fmt.Fprintln(os.Stderr, "Verify certificate chain error:", err)
os.Exit(1)
}
fmt.Printf("%s%s", crtBytes, crtHostBytes)
}
示例2: newSignAction
func newSignAction(c *cli.Context) {
if len(c.Args()) != 1 {
fmt.Fprintln(os.Stderr, "One host name must be provided.")
os.Exit(1)
}
name := c.Args()[0]
if depot.CheckCertificateHost(d, name) {
fmt.Fprintln(os.Stderr, "Certificate has existed!")
os.Exit(1)
}
csr, err := depot.GetCertificateSigningRequest(d, name)
if err != nil {
fmt.Fprintln(os.Stderr, "Get certificate request error:", err)
os.Exit(1)
}
crt, err := depot.GetCertificateAuthority(d)
if err != nil {
fmt.Fprintln(os.Stderr, "Get CA certificate error:", err)
os.Exit(1)
}
info, err := depot.GetCertificateAuthorityInfo(d)
if err != nil {
fmt.Fprintln(os.Stderr, "Get CA certificate info error:", err)
os.Exit(1)
}
key, err := depot.GetEncryptedPrivateKeyAuthority(d, getPassPhrase(c, "CA key"))
if err != nil {
fmt.Fprintln(os.Stderr, "Get CA key error:", err)
os.Exit(1)
}
crtHost, err := pkix.CreateCertificateHost(crt, info, key, csr)
if err != nil {
fmt.Fprintln(os.Stderr, "Create certificate error:", err)
os.Exit(1)
} else {
fmt.Printf("Created %s/crt from %s/csr signed by ca/key\n", name, name)
}
if err = depot.PutCertificateHost(d, name, crtHost); err != nil {
fmt.Fprintln(os.Stderr, "Save certificate error:", err)
}
if err = depot.UpdateCertificateAuthorityInfo(d, info); err != nil {
fmt.Fprintln(os.Stderr, "Update CA info error:", err)
}
}
示例3: newCertAction
func newCertAction(c *cli.Context) {
if len(c.Args()) != 1 {
fmt.Fprintln(os.Stderr, "One host name must be provided.")
os.Exit(1)
}
name := c.Args()[0]
if depot.CheckCertificateSigningRequest(d, name) || depot.CheckPrivateKeyHost(d, name) {
fmt.Fprintln(os.Stderr, "Certificate request has existed!")
os.Exit(1)
}
var passphrase []byte
var err error
if c.IsSet("passphrase") {
passphrase = []byte(c.String("passphrase"))
} else {
passphrase, err = createPassPhrase()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
key, err := pkix.CreateRSAKey(c.Int("key-bits"))
if err != nil {
fmt.Fprintln(os.Stderr, "Create RSA Key error:", err)
os.Exit(1)
} else {
fmt.Printf("Created %s/key\n", name)
}
csr, err := pkix.CreateCertificateSigningRequest(key, name, c.String("ip"))
if err != nil {
fmt.Fprintln(os.Stderr, "Create certificate request error:", err)
os.Exit(1)
} else {
fmt.Printf("Created %s/crt\n", name)
}
if err = depot.PutCertificateSigningRequest(d, name, csr); err != nil {
fmt.Fprintln(os.Stderr, "Save certificate request error:", err)
}
if err = depot.PutEncryptedPrivateKeyHost(d, name, key, passphrase); err != nil {
fmt.Fprintln(os.Stderr, "Save key error:", err)
}
}
示例4: newExportAction
func newExportAction(c *cli.Context) {
if len(c.Args()) > 1 {
fmt.Fprintln(os.Stderr, "At most one host name could be provided.")
os.Exit(1)
}
var files []*TarFile
var err error
if len(c.Args()) == 0 {
files, err = getAuthFiles(c)
} else {
files, err = getHostFiles(c, c.Args()[0])
}
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
w := tar.NewWriter(os.Stdout)
defer w.Close()
if err = outputTarFiles(w, files); err != nil {
fmt.Fprintln(os.Stderr, "Save tar error:", err)
os.Exit(1)
}
}