From 4b7fa2524d25b609a4f6401ee62d772f73fbc3b3 Mon Sep 17 00:00:00 2001 From: Carl Tashian Date: Tue, 31 Jan 2023 12:10:59 -0800 Subject: [PATCH 1/4] Closes #1248 --- authority/config/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/authority/config/config.go b/authority/config/config.go index 556f5407..fb4d52f9 100644 --- a/authority/config/config.go +++ b/authority/config/config.go @@ -213,6 +213,9 @@ func (c *AuthConfig) Validate(audiences provisioner.Audiences) error { func LoadConfiguration(filename string) (*Config, error) { f, err := os.Open(filename) if err != nil { + fmt.Println("step-ca can't find or open the configuration file for your CA.") + fmt.Println("You may need to create a CA first by running `step ca init`.") + fmt.Println("Documentation: https://u.step.sm/docs/ca\n") return nil, errors.Wrapf(err, "error opening %s", filename) } defer f.Close() From 50b4011b032affae266ef2cda9f72b1bb3bd7bd2 Mon Sep 17 00:00:00 2001 From: Carl Tashian Date: Tue, 31 Jan 2023 12:32:56 -0800 Subject: [PATCH 2/4] Move to commands/app.go --- authority/config/config.go | 3 --- commands/app.go | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/authority/config/config.go b/authority/config/config.go index fb4d52f9..556f5407 100644 --- a/authority/config/config.go +++ b/authority/config/config.go @@ -213,9 +213,6 @@ func (c *AuthConfig) Validate(audiences provisioner.Audiences) error { func LoadConfiguration(filename string) (*Config, error) { f, err := os.Open(filename) if err != nil { - fmt.Println("step-ca can't find or open the configuration file for your CA.") - fmt.Println("You may need to create a CA first by running `step ca init`.") - fmt.Println("Documentation: https://u.step.sm/docs/ca\n") return nil, errors.Wrapf(err, "error opening %s", filename) } defer f.Close() diff --git a/commands/app.go b/commands/app.go index 31d62f87..3c07120c 100644 --- a/commands/app.go +++ b/commands/app.go @@ -141,6 +141,9 @@ func appAction(ctx *cli.Context) error { cfg, err := config.LoadConfiguration(configFile) if err != nil && token == "" { + fmt.Println("step-ca can't find or open the configuration file for your CA.") + fmt.Println("You may need to create a CA first by running `step ca init`.") + fmt.Println("Documentation: https://u.step.sm/docs/ca\n") fatal(err) } From 1c59b3f1326c5974e54a543878ea6ac95bf84232 Mon Sep 17 00:00:00 2001 From: Carl Tashian Date: Tue, 31 Jan 2023 12:38:46 -0800 Subject: [PATCH 3/4] Fix linting error --- commands/app.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/app.go b/commands/app.go index 3c07120c..cf58c37e 100644 --- a/commands/app.go +++ b/commands/app.go @@ -143,7 +143,8 @@ func appAction(ctx *cli.Context) error { if err != nil && token == "" { fmt.Println("step-ca can't find or open the configuration file for your CA.") fmt.Println("You may need to create a CA first by running `step ca init`.") - fmt.Println("Documentation: https://u.step.sm/docs/ca\n") + fmt.Println("Documentation: https://u.step.sm/docs/ca") + fmt.Println("") fatal(err) } From b76028f3ba43f37cd4f3a6cf804d3340befbbef4 Mon Sep 17 00:00:00 2001 From: Carl Tashian Date: Tue, 31 Jan 2023 14:39:29 -0800 Subject: [PATCH 4/4] Update commands/app.go Co-authored-by: Mariano Cano --- commands/app.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/commands/app.go b/commands/app.go index cf58c37e..daa5aa21 100644 --- a/commands/app.go +++ b/commands/app.go @@ -141,10 +141,13 @@ func appAction(ctx *cli.Context) error { cfg, err := config.LoadConfiguration(configFile) if err != nil && token == "" { - fmt.Println("step-ca can't find or open the configuration file for your CA.") - fmt.Println("You may need to create a CA first by running `step ca init`.") - fmt.Println("Documentation: https://u.step.sm/docs/ca") - fmt.Println("") + var pathErr *os.PathError + if errors.As(err, &pathErr) { + fmt.Println("step-ca can't find or open the configuration file for your CA.") + fmt.Println("You may need to create a CA first by running `step ca init`.") + fmt.Println("Documentation: https://u.step.sm/docs/ca") + os.Exit(1) + } fatal(err) }