diff options
author | Gibheer <gibheer@gmail.com> | 2015-04-10 21:29:28 +0200 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2015-04-10 21:29:28 +0200 |
commit | 38c320124cf4c1a8bc777972cc74271888bc8d54 (patch) | |
tree | b7895e34baffd9028aa1b90feca2f719d0071249 /flags.go | |
parent | 560929efaa0f756ac7a7355c087b8f0a16a12a0d (diff) |
add ca load option
This commit changes to API a bit. The following renames were done:
* csr-path => csr
* ca => is-ca
The following option was added
* ca
With that option it is now possible to add a certificate to sign the
newly created certificate.
Diffstat (limited to 'flags.go')
-rw-r--r-- | flags.go | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -28,7 +28,7 @@ type ( certificateFlags certiticateRequestRawFlags // container for certificate related flags signature string // a base64 encoded signature certGeneration certGenerationRaw // all certificate generation flags - certificatePath string // path to a certificate + caPath string // path to a certificate authority } flagCheck func() error @@ -90,6 +90,8 @@ certificate requests and certificates and sign/verify messages.`, FlagCertificateRequestData *pki.CertificateData // the certificate sign request FlagCertificateSignRequest *pki.CertificateRequest + // the ca/certificate to use + FlagCertificate *pki.Certificate ) func InitFlags() { @@ -123,12 +125,14 @@ func InitFlags() { InitFlagOutput(CmdCreateSignRequest) InitFlagCertificateFields(CmdCreateSignRequest) // create-certificate - InitFlagPrivateKey(CmdCreateCert) - InitFlagOutput(CmdCreateCert) + InitFlagCA(CmdCreateCert) InitFlagCert(CmdCreateCert) InitFlagCSR(CmdCreateCert) + InitFlagOutput(CmdCreateCert) + InitFlagPrivateKey(CmdCreateCert) } +// check if all checks are successful func checkFlags(checks ...flagCheck) error { for _, check := range checks { if err := check(); err != nil { @@ -138,6 +142,23 @@ func checkFlags(checks ...flagCheck) error { return nil } +// check if either of the inserted checks is successful +func checkFlagsEither(checks ...flagCheck) flagCheck { + return func() error { + errors := make([]error, 0) + for _, check := range checks { + if err := check(); err != nil { + errors = append(errors, err) + } + } + // it is a success, if any check is successful + if len(checks)-len(errors) > 0 { + return nil + } + return errors[0] + } +} + // add the public key flag func InitFlagPublicKey(cmd *Command) { cmd.Flags().StringVar(&flagContainer.publicKeyPath, "public-key", "", "path to the public key (required)") |