From 60a03cad98f541da1feabe6cb3dc5e3f4dbcc387 Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Mon, 9 Jan 2023 19:28:22 -0500 Subject: [PATCH] Add error for when no login/no token --- cli/packages/util/errors.go | 38 ------------------------------------ cli/packages/util/secrets.go | 4 +++- 2 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 cli/packages/util/errors.go diff --git a/cli/packages/util/errors.go b/cli/packages/util/errors.go deleted file mode 100644 index 1761d6f7b1..0000000000 --- a/cli/packages/util/errors.go +++ /dev/null @@ -1,38 +0,0 @@ -package util - -import ( - "fmt" - "os" - - "github.com/fatih/color" -) - -func HandleError(err error, messages ...string) { - PrintErrorAndExit(1, err, messages...) -} - -func PrintErrorAndExit(exitCode int, err error, messages ...string) { - printError(err) - - if len(messages) > 0 { - for _, message := range messages { - fmt.Println(message) - } - } - - os.Exit(exitCode) -} - -func PrintMessageAndExit(messages ...string) { - if len(messages) > 0 { - for _, message := range messages { - fmt.Println(message) - } - } - - os.Exit(1) -} - -func printError(e error) { - color.Red("Hmm, we ran into an error: %v", e) -} diff --git a/cli/packages/util/secrets.go b/cli/packages/util/secrets.go index 131a8e66db..c0a3ad9526 100644 --- a/cli/packages/util/secrets.go +++ b/cli/packages/util/secrets.go @@ -117,9 +117,11 @@ func GetAllEnvironmentVariables(envName string) ([]models.SingleEnvironmentVaria secrets, err := GetPlainTextSecretsViaJTW(loggedInUserDetails.UserCredentials.JTWToken, loggedInUserDetails.UserCredentials.PrivateKey, workspaceFile.WorkspaceId, envName) return secrets, err - } else { + } else if infisicalToken != "" { log.Debug("Trying to fetch secrets using service token") return GetPlainTextSecretsViaServiceToken(infisicalToken) + } else { + return nil, fmt.Errorf("unable to fetch secrets because we could not find a service token or a logged in user") } }