Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2nd try: Adds out-name cli option #54

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/init.go
Expand Up @@ -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,
Expand All @@ -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!")
Expand Down
4 changes: 4 additions & 0 deletions cmd/request_cert.go
Expand Up @@ -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.", ""},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer out to on

cli.BoolFlag{"stdout", "Print signing request to stdout in addition to saving file", ""},
},
Action: newCertAction,
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the string replace is potentially confusing and we should omit it. Just do formattedName = out-name. If the user specifies an out-name, we should use it directly.

}

if depot.CheckCertificateSigningRequest(d, formattedName) || depot.CheckPrivateKey(d, formattedName) {
fmt.Fprintln(os.Stderr, "Certificate request has existed!")
Expand Down