From f198c45f757c412b30470065ab065248d6b37fc1 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Wed, 15 May 2019 22:27:36 -0400 Subject: [PATCH] api key --- main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/main.go b/main.go index 0bce5d5..76fd245 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ func main() { Aliases: []string{"s"}, Usage: "Scan a directory's manifests", Action: func(c *cli.Context) error { + everyCommand() directory := getDirectory(c) return scan(directory) @@ -33,6 +34,7 @@ func main() { Name: "verify", Usage: "Verify .tidelift.yml configuration", Action: func(c *cli.Context) error { + everyCommand() directory := getDirectory(c) return verify(directory) @@ -43,6 +45,7 @@ func main() { Aliases: []string{"c"}, Usage: "Configure the app", Action: func(c *cli.Context) error { + everyCommand() return cli.NewExitError("No Configuration provided", 4) }, }, @@ -63,6 +66,20 @@ func getDirectory(c *cli.Context) string { } return "." } +func checkAPIKey() error { + if os.Getenv("TIDELIFT_API_KEY") == "" { + return cli.NewExitError("please set TIDELIFT_API_KEY environment variable", 8) + } + return nil +} + +func everyCommand() error { + err := checkAPIKey() + if err != nil { + return err + } + return nil +} // Scan will scan a directory's manifests for all supported manifest files // then it will upload them to tidelift for scanning @@ -82,6 +99,7 @@ func scan(directory string) error { // in order to upload a manifest to Tidelift func verify(directory string) error { // Show error if no .tidelift.yml file + if !verifyTideliftYamlExists(directory) { return cli.NewExitError("no .tidelift.yml at supplied directory path", 6) } @@ -90,7 +108,10 @@ func verify(directory string) error { if missingKey != "" { errorMsg := fmt.Sprintf("Missing key '%s:' in .tidelift.yml", missingKey) return cli.NewExitError(errorMsg, 7) + } + if os.Getenv("TIDELIFT_API_KEY") == "" { + return cli.NewExitError("please set TIDELIFT_API_KEY environment variable", 8) } return nil