From e3c4cd59298ddbdec8187dde198d9b07699065fe Mon Sep 17 00:00:00 2001 From: "M. Stolze" Date: Fri, 6 Apr 2018 16:06:29 +0200 Subject: [PATCH] Adds out-name cli option --- cmd/init.go | 4 ++++ cmd/request_cert.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cmd/init.go b/cmd/init.go index 2050525..bfab059 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -46,6 +46,7 @@ func NewInitCommand() cli.Command { cli.StringFlag{"province, st", "", "CA state/province", ""}, cli.StringFlag{"locality, l", "", "CA locality", ""}, cli.StringFlag{"key", "", "Path to private key PEM file. If blank, will generate new keypair.", ""}, + cli.StringFlag{"out-name, on", "", "Name for output files without path and extension. If blank, CA common name will be used.", ""}, cli.BoolFlag{"stdout", "Print CA certificate to stdout in addition to saving file", ""}, }, Action: initAction, @@ -60,6 +61,9 @@ func initAction(c *cli.Context) { } formattedName := strings.Replace(c.String("common-name"), " ", "_", -1) + if c.IsSet("out-name") { + formattedName = strings.Replace(c.String("out-name"), " ", "_", -1) + } if depot.CheckCertificate(d, formattedName) || depot.CheckPrivateKey(d, formattedName) { fmt.Fprintln(os.Stderr, "CA with specified name already exists!") diff --git a/cmd/request_cert.go b/cmd/request_cert.go index 5bab3ca..f912ded 100644 --- a/cmd/request_cert.go +++ b/cmd/request_cert.go @@ -46,6 +46,7 @@ func NewCertRequestCommand() cli.Command { cli.StringFlag{"ip", "", "IP address entries for subject alt name (comma separated)", ""}, cli.StringFlag{"domain", "", "DNS entries for subject alt name (comma separated)", ""}, cli.StringFlag{"key", "", "Path to private key PEM file. If blank, will generate new keypair.", ""}, + cli.StringFlag{"out-name, on", "", "Name for output files without path and extension. If blank, Common name will be used.", ""}, cli.BoolFlag{"stdout", "Print signing request to stdout in addition to saving file", ""}, }, Action: newCertAction, @@ -82,6 +83,9 @@ func newCertAction(c *cli.Context) { } formattedName := strings.Replace(name, " ", "_", -1) + if c.IsSet("out-name") { + formattedName = strings.Replace(c.String("out-name"), " ", "_", -1) + } if depot.CheckCertificateSigningRequest(d, formattedName) || depot.CheckPrivateKey(d, formattedName) { fmt.Fprintln(os.Stderr, "Certificate request has existed!")