Skip to content

Commit 2d096e3

Browse files
authored
Merge pull request #42 from smallstep/ui-improvements
UI improvements
2 parents edb0afc + 3d70e7f commit 2d096e3

39 files changed

+203
-163
lines changed

Gopkg.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

command/ca/bootstrap.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/smallstep/cli/crypto/pki"
1414
"github.com/smallstep/cli/errs"
1515
"github.com/smallstep/cli/flags"
16+
"github.com/smallstep/cli/ui"
1617
"github.com/smallstep/cli/utils"
1718
"github.com/urfave/cli"
1819
)
@@ -80,6 +81,7 @@ func bootstrapAction(ctx *cli.Context) error {
8081
if err != nil {
8182
return err
8283
}
84+
ui.Printf("The root certificate has been saved in %s.\n", rootFile)
8385

8486
// make sure to store the url with https
8587
caURL, err = completeURL(caURL)
@@ -97,5 +99,10 @@ func bootstrapAction(ctx *cli.Context) error {
9799
return errors.Wrap(err, "error marshaling defaults.json")
98100
}
99101

100-
return utils.WriteFile(configFile, b, 0644)
102+
if err := utils.WriteFile(configFile, b, 0644); err != nil {
103+
return err
104+
}
105+
106+
ui.Printf("Your configuration has been saved in %s.\n", configFile)
107+
return nil
101108
}

command/ca/certificate.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ func newCertificateAction(ctx *cli.Context) error {
222222
return err
223223
}
224224

225+
ui.PrintSelected("Certificate", crtFile)
226+
ui.PrintSelected("Private Key", keyFile)
225227
return nil
226228
}
227229

@@ -254,7 +256,12 @@ func signCertificateAction(ctx *cli.Context) error {
254256
}
255257
}
256258

257-
return signCertificateRequest(ctx, token, api.NewCertificateRequest(csr), crtFile)
259+
if err := signCertificateRequest(ctx, token, api.NewCertificateRequest(csr), crtFile); err != nil {
260+
return err
261+
}
262+
263+
ui.PrintSelected("Certificate", crtFile)
264+
return nil
258265
}
259266

260267
type tokenClaims struct {
@@ -469,5 +476,6 @@ func renewCertificateAction(ctx *cli.Context) error {
469476
return errs.FileError(err, outFile)
470477
}
471478

479+
ui.Printf("Your certificate has been saved in %s.\n", outFile)
472480
return nil
473481
}

command/ca/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func initAction(ctx *cli.Context) error {
110110
p.SetDNSNames(dnsNames)
111111
}
112112

113-
pass, err := ui.PromptPasswordGenerate("What do you want your password to be? [leave empty and we'll generate one]")
113+
pass, err := ui.PromptPasswordGenerate("What do you want your password to be? [leave empty and we'll generate one]", ui.WithRichPrompt())
114114
if err != nil {
115115
return err
116116
}

command/ca/root.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/smallstep/cli/crypto/pemutil"
1212
"github.com/smallstep/cli/errs"
1313
"github.com/smallstep/cli/flags"
14+
"github.com/smallstep/cli/ui"
1415
"github.com/urfave/cli"
1516
)
1617

@@ -85,8 +86,12 @@ func rootAction(ctx *cli.Context) error {
8586
return errors.Wrap(err, "error downloading root certificate")
8687
}
8788

88-
_, err = pemutil.Serialize(resp.RootPEM.Certificate, pemutil.ToFile(rootFile, 0600))
89-
return err
89+
if _, err := pemutil.Serialize(resp.RootPEM.Certificate, pemutil.ToFile(rootFile, 0600)); err != nil {
90+
return err
91+
}
92+
93+
ui.Printf("The root certificate has been saved in %s.\n", rootFile)
94+
return nil
9095
}
9196

9297
func getInsecureTransport() *http.Transport {

command/ca/token.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,12 @@ func newTokenFlow(ctx *cli.Context, subject, caURL, root, kid, issuer, passwordF
335335
return "", err
336336
}
337337

338-
decrypted, err := jose.Decrypt("Please enter the password to decrypt the provisioner key:", []byte(encrypted), opts...)
338+
// Add template with check mark
339+
opts = append(opts, jose.WithUIOptions(
340+
ui.WithPromptTemplates(ui.PromptTemplates()),
341+
))
342+
343+
decrypted, err := jose.Decrypt("Please enter the password to decrypt the provisioner key", []byte(encrypted), opts...)
339344
if err != nil {
340345
return "", err
341346
}

command/certificate/bundle.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/smallstep/cli/command"
99
"github.com/smallstep/cli/errs"
1010
"github.com/smallstep/cli/flags"
11+
"github.com/smallstep/cli/ui"
1112
"github.com/smallstep/cli/utils"
1213
"github.com/urfave/cli"
1314
)
@@ -76,8 +77,9 @@ func bundleAction(ctx *cli.Context) error {
7677
chainFile := ctx.Args().Get(2)
7778
if err := utils.WriteFile(chainFile,
7879
append(pem.EncodeToMemory(crtBlock), pem.EncodeToMemory(caBlock)...), 0600); err != nil {
79-
return errs.FileError(err, chainFile)
80+
return err
8081
}
8182

83+
ui.Printf("Your certificate has been saved in %s.\n", chainFile)
8284
return nil
8385
}

command/certificate/create.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/smallstep/cli/errs"
1414
"github.com/smallstep/cli/flags"
1515
x509 "github.com/smallstep/cli/pkg/x509"
16+
"github.com/smallstep/cli/ui"
1617
"github.com/smallstep/cli/utils"
1718
"github.com/urfave/cli"
1819
)
@@ -332,7 +333,7 @@ func createAction(ctx *cli.Context) error {
332333
return errors.WithStack(err)
333334
}
334335
} else {
335-
pass, err := utils.ReadPassword("Please enter the password to encrypt the private key: ")
336+
pass, err := ui.PromptPassword("Please enter the password to encrypt the private key")
336337
if err != nil {
337338
return errors.Wrap(err, "error reading password")
338339
}
@@ -342,6 +343,10 @@ func createAction(ctx *cli.Context) error {
342343
return errors.WithStack(err)
343344
}
344345
}
346+
347+
ui.Printf("Your certificate has been saved in %s.\n", crtFile)
348+
ui.Printf("Your private key has been saved in %s.\n", keyFile)
349+
345350
return nil
346351
}
347352

command/certificate/format.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/smallstep/cli/command"
1111
"github.com/smallstep/cli/errs"
1212
"github.com/smallstep/cli/flags"
13+
"github.com/smallstep/cli/ui"
1314
"github.com/smallstep/cli/utils"
1415
"github.com/urfave/cli"
1516
)
@@ -117,11 +118,10 @@ func formatAction(ctx *cli.Context) error {
117118
if err != nil {
118119
return err
119120
}
120-
m := info.Mode()
121-
err = utils.WriteFile(out, ob, m)
122-
if err != nil {
121+
if err := utils.WriteFile(out, ob, info.Mode()); err != nil {
123122
return err
124123
}
124+
ui.Printf("Your certificate has been saved in %s.\n", out)
125125
}
126126

127127
return nil

command/crypto/change-pass.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/smallstep/cli/errs"
1515
"github.com/smallstep/cli/flags"
1616
"github.com/smallstep/cli/jose"
17+
"github.com/smallstep/cli/ui"
1718
"github.com/smallstep/cli/utils"
1819
)
1920

@@ -88,7 +89,7 @@ func changePassAction(ctx *cli.Context) error {
8889
if err != nil {
8990
return err
9091
}
91-
pass, err := utils.ReadPassword(fmt.Sprintf("Please enter the password to encrypt %s: ", newKeyPath))
92+
pass, err := ui.PromptPassword(fmt.Sprintf("Please enter the password to encrypt %s", newKeyPath))
9293
if err != nil {
9394
return errors.Wrap(err, "error reading password")
9495
}
@@ -113,5 +114,6 @@ func changePassAction(ctx *cli.Context) error {
113114
}
114115
}
115116

117+
ui.Printf("Your key has been saved in %s.\n", newKeyPath)
116118
return nil
117119
}

0 commit comments

Comments
 (0)