本文整理汇总了Golang中github.com/coreos/etcd-ca/Godeps/_workspace/src/github.com/codegangsta/cli.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getAuthFiles
func getAuthFiles(c *cli.Context) ([]*TarFile, error) {
name := "ca"
tarFiles := make([]*TarFile, 0)
crtFile, err := d.GetFile(depot.AuthCrtTag())
if err != nil {
return nil, errors.New("Get CA certificate error: " + err.Error())
}
crtTarFile, err := generateTarFile(crtFile, name+crtSuffix)
if err != nil {
return nil, errors.New("Generate certificate tar file error: " + err.Error())
}
tarFiles = append(tarFiles, crtTarFile)
keyFile, err := d.GetFile(depot.AuthPrivKeyTag())
if err != nil {
return nil, errors.New("Get CA key error: " + err.Error())
}
keyTarFile, err := generateTarFile(keyFile, name+keySuffix)
if err != nil {
return nil, errors.New("Generate key tar file error: " + err.Error())
}
if c.Bool("insecure") {
if keyTarFile, err = decryptEncryptedKeyTarFile(keyTarFile, getPassPhrase(c, name+" key")); err != nil {
return nil, errors.New("Get decrypted CA key error: " + err.Error())
}
}
tarFiles = append(tarFiles, keyTarFile)
return tarFiles, nil
}
开发者ID:hzy001,项目名称:etcd-ca,代码行数:31,代码来源:export.go
示例2: initAction
func initAction(c *cli.Context) {
if depot.CheckCertificateAuthority(d) || depot.CheckCertificateAuthorityInfo(d) || depot.CheckPrivateKeyAuthority(d) {
fmt.Fprintln(os.Stderr, "CA 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.Println("Created ca/key")
}
crt, info, err := pkix.CreateCertificateAuthority(key, c.Int("years"), c.String("organization"), c.String("country"))
if err != nil {
fmt.Fprintln(os.Stderr, "Create certificate error:", err)
os.Exit(1)
} else {
fmt.Println("Created ca/crt")
}
if err = depot.PutCertificateAuthority(d, crt); err != nil {
fmt.Fprintln(os.Stderr, "Save certificate error:", err)
}
if err = depot.PutCertificateAuthorityInfo(d, info); err != nil {
fmt.Fprintln(os.Stderr, "Save certificate info error:", err)
}
if err = depot.PutEncryptedPrivateKeyAuthority(d, key, passphrase); err != nil {
fmt.Fprintln(os.Stderr, "Save key error:", err)
}
}
开发者ID:hzy001,项目名称:etcd-ca,代码行数:44,代码来源:init.go
示例3: 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)
if isFileNotExist(err) {
fmt.Fprintln(os.Stderr, "Please run 'etcd-ca init' to initial the depot.")
}
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, c.Int("years"), c.Bool("server"), c.Bool("client"))
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)
}
}
开发者ID:mgit-at,项目名称:etcd-ca,代码行数:51,代码来源:sign.go
示例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)
}
if _, err := depot.GetCertificateAuthority(d); isFileNotExist(err) {
fmt.Fprintln(os.Stderr, "Please run 'etcd-ca init' to initial the depot.")
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)
}
}
开发者ID:hzy001,项目名称:etcd-ca,代码行数:30,代码来源:export.go
示例5: 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"), c.String("domain"), c.String("organization"), c.String("country"))
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)
}
}
开发者ID:hzy001,项目名称:etcd-ca,代码行数:47,代码来源:new_cert.go
注:本文中的github.com/coreos/etcd-ca/Godeps/_workspace/src/github.com/codegangsta/cli.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论