@@ -6,13 +6,13 @@ import (
66 "io"
77 "strings"
88
9- "github.com/smallstep/cli/crypto/pemutil"
10-
119 "github.com/smallstep/cli/command"
10+ "github.com/smallstep/cli/crypto/pemutil"
1211 "github.com/smallstep/cli/crypto/pki"
1312 "github.com/smallstep/cli/errs"
1413 stepx509 "github.com/smallstep/cli/pkg/x509"
1514 "github.com/smallstep/cli/ui"
15+ "github.com/smallstep/cli/utils"
1616 "github.com/urfave/cli"
1717)
1818
@@ -38,7 +38,31 @@ func initCommand() cli.Command {
3838 },
3939 cli.BoolFlag {
4040 Name : "pki" ,
41- Usage : "Generate only the PKI without the CA configuration" ,
41+ Usage : "Generate only the PKI without the CA configuration." ,
42+ },
43+ cli.StringFlag {
44+ Name : "name" ,
45+ Usage : "The <name> of the new PKI." ,
46+ },
47+ cli.StringFlag {
48+ Name : "dns" ,
49+ Usage : "The comma sepparated DNS <names> or IP addresses of the new CA." ,
50+ },
51+ cli.StringFlag {
52+ Name : "address" ,
53+ Usage : "The <address> that the new CA will listen at." ,
54+ },
55+ cli.StringFlag {
56+ Name : "provisioner" ,
57+ Usage : "The <name> of the first provisioner." ,
58+ },
59+ cli.StringFlag {
60+ Name : "password-file" ,
61+ Usage : `The path to the <file> containing the password to encrypt the keys.` ,
62+ },
63+ cli.StringFlag {
64+ Name : "with-ca-url" ,
65+ Usage : `<URI> of the Step Certificate Authority to write in defaults.json` ,
4266 },
4367 },
4468 }
@@ -49,12 +73,14 @@ func initAction(ctx *cli.Context) error {
4973 return err
5074 }
5175
76+ var password string
5277 var rootCrt * stepx509.Certificate
5378 var rootKey interface {}
5479
5580 root := ctx .String ("root" )
5681 key := ctx .String ("key" )
5782 configure := ! ctx .Bool ("pki" )
83+ caURL := ctx .String ("with-ca-url" )
5884 switch {
5985 case len (root ) > 0 && len (key ) == 0 :
6086 return errs .RequiredWithFlag (ctx , "root" , "key" )
@@ -70,18 +96,29 @@ func initAction(ctx *cli.Context) error {
7096 }
7197 }
7298
99+ passwordFile := ctx .String ("password-file" )
100+ if passwordFile != "" {
101+ b , err := utils .ReadPasswordFromFile (passwordFile )
102+ if err != nil {
103+ return err
104+ }
105+ password = string (b )
106+ }
107+
73108 p , err := pki .New (pki .GetPublicPath (), pki .GetSecretsPath (), pki .GetConfigPath ())
74109 if err != nil {
75110 return err
76111 }
77112
78- name , err := ui .Prompt ("What would you like to name your new PKI? (e.g. Smallstep)" , ui .WithValidateNotEmpty ())
113+ name , err := ui .Prompt ("What would you like to name your new PKI? (e.g. Smallstep)" ,
114+ ui .WithValidateNotEmpty (), ui .WithValue (ctx .String ("name" )))
79115 if err != nil {
80116 return err
81117 }
82118
83119 if configure {
84- names , err := ui .Prompt ("What DNS names or IP addresses would you like to add to your new CA? (e.g. ca.smallstep.com[,1.1.1.1,etc.])" , ui .WithValidateFunc (ui .DNS ()))
120+ names , err := ui .Prompt ("What DNS names or IP addresses would you like to add to your new CA? (e.g. ca.smallstep.com[,1.1.1.1,etc.])" ,
121+ ui .WithValidateFunc (ui .DNS ()), ui .WithValue (ctx .String ("dns" )))
85122 if err != nil {
86123 return err
87124 }
@@ -95,22 +132,26 @@ func initAction(ctx *cli.Context) error {
95132 dnsNames = append (dnsNames , strings .TrimSpace (name ))
96133 }
97134
98- address , err := ui .Prompt ("What address will your new CA listen at? (e.g. :443)" , ui .WithValidateFunc (ui .Address ()))
135+ address , err := ui .Prompt ("What address will your new CA listen at? (e.g. :443)" ,
136+ ui .WithValidateFunc (ui .Address ()), ui .WithValue (ctx .String ("address" )))
99137 if err != nil {
100138 return err
101139 }
102140
103- provisioner ,
err := ui .
Prompt (
"What would you like to name the first provisioner for your new CA? (e.g. [email protected] )" ,
ui .
WithValidateNotEmpty ())
141+ provisioner ,
err := ui .
Prompt (
"What would you like to name the first provisioner for your new CA? (e.g. [email protected] )" ,
142+ ui .WithValidateNotEmpty (), ui .WithValue (ctx .String ("provisioner" )))
104143 if err != nil {
105144 return err
106145 }
107146
108147 p .SetProvisioner (provisioner )
109148 p .SetAddress (address )
110149 p .SetDNSNames (dnsNames )
150+ p .SetCAURL (caURL )
111151 }
112152
113- pass , err := ui .PromptPasswordGenerate ("What do you want your password to be? [leave empty and we'll generate one]" , ui .WithRichPrompt ())
153+ pass , err := ui .PromptPasswordGenerate ("What do you want your password to be? [leave empty and we'll generate one]" ,
154+ ui .WithRichPrompt (), ui .WithValue (password ))
114155 if err != nil {
115156 return err
116157 }
0 commit comments