From 522a03c2ad5d2661e961de04f4ca046dc70e2700 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:05:33 +0100 Subject: [PATCH] Fix: Helper function for getting service token --- cli/packages/util/helper.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cli/packages/util/helper.go b/cli/packages/util/helper.go index 043db468e..413afb2b8 100644 --- a/cli/packages/util/helper.go +++ b/cli/packages/util/helper.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/Infisical/infisical-merge/packages/models" + "github.com/spf13/cobra" ) type DecodedSymmetricEncryptionDetails = struct { @@ -63,6 +64,20 @@ func IsSecretTypeValid(s string) bool { return false } +func GetInfisicalServiceToken(cmd *cobra.Command) (serviceToken string, err error) { + infisicalToken, err := cmd.Flags().GetString("token") + + if infisicalToken == "" { + infisicalToken = os.Getenv(INFISICAL_TOKEN_NAME) + } + + if err != nil { + return "", err + } + + return infisicalToken, nil +} + // Checks if the passed in email already exists in the users slice func ConfigContainsEmail(users []models.LoggedInUser, email string) bool { for _, value := range users {