-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
General refactor of the cmd package #3328
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
Changes from 2 commits
81c27eb
bbb3929
5cd459b
24ccbc1
5ab4396
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,16 +90,16 @@ func pemBlockForKey(priv interface{}) *pem.Block { | |
} | ||
} | ||
|
||
func runCert(ctx *cli.Context) error { | ||
if len(ctx.String("host")) == 0 { | ||
log.Fatal("Missing required --host parameter") | ||
func runCert(c *cli.Context) error { | ||
if err := argsSet(c, "host"); err != nil { | ||
return err | ||
} | ||
|
||
var priv interface{} | ||
var err error | ||
switch ctx.String("ecdsa-curve") { | ||
switch c.String("ecdsa-curve") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would generally agree, however the entire package refers to c *cli.Context instead of ctx *cli.Context. Shall I change everything to use ctx? |
||
case "": | ||
priv, err = rsa.GenerateKey(rand.Reader, ctx.Int("rsa-bits")) | ||
priv, err = rsa.GenerateKey(rand.Reader, c.Int("rsa-bits")) | ||
case "P224": | ||
priv, err = ecdsa.GenerateKey(elliptic.P224(), rand.Reader) | ||
case "P256": | ||
|
@@ -109,23 +109,23 @@ func runCert(ctx *cli.Context) error { | |
case "P521": | ||
priv, err = ecdsa.GenerateKey(elliptic.P521(), rand.Reader) | ||
default: | ||
log.Fatalf("Unrecognized elliptic curve: %q", ctx.String("ecdsa-curve")) | ||
log.Fatalf("Unrecognized elliptic curve: %q", c.String("ecdsa-curve")) | ||
} | ||
if err != nil { | ||
log.Fatalf("Failed to generate private key: %v", err) | ||
} | ||
|
||
var notBefore time.Time | ||
if len(ctx.String("start-date")) == 0 { | ||
notBefore = time.Now() | ||
} else { | ||
notBefore, err = time.Parse("Jan 2 15:04:05 2006", ctx.String("start-date")) | ||
if startDate := c.String("start-date"); startDate != "" { | ||
notBefore, err = time.Parse("Jan 2 15:04:05 2006", startDate) | ||
if err != nil { | ||
log.Fatalf("Failed to parse creation date: %v", err) | ||
} | ||
} else { | ||
notBefore = time.Now() | ||
} | ||
|
||
notAfter := notBefore.Add(ctx.Duration("duration")) | ||
notAfter := notBefore.Add(c.Duration("duration")) | ||
|
||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128) | ||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit) | ||
|
@@ -147,7 +147,7 @@ func runCert(ctx *cli.Context) error { | |
BasicConstraintsValid: true, | ||
} | ||
|
||
hosts := strings.Split(ctx.String("host"), ",") | ||
hosts := strings.Split(c.String("host"), ",") | ||
for _, h := range hosts { | ||
if ip := net.ParseIP(h); ip != nil { | ||
template.IPAddresses = append(template.IPAddresses, ip) | ||
|
@@ -156,7 +156,7 @@ func runCert(ctx *cli.Context) error { | |
} | ||
} | ||
|
||
if ctx.Bool("ca") { | ||
if c.Bool("ca") { | ||
template.IsCA = true | ||
template.KeyUsage |= x509.KeyUsageCertSign | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move these two functions into
cmd/common.go
or similarThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done