diff --git a/cli/packages/cmd/root.go b/cli/packages/cmd/root.go index 2f6b4cefc..586c47e38 100644 --- a/cli/packages/cmd/root.go +++ b/cli/packages/cmd/root.go @@ -4,6 +4,7 @@ Copyright (c) 2023 Infisical Inc. package cmd import ( + "fmt" "os" "strings" @@ -43,17 +44,35 @@ func init() { rootCmd.PersistentFlags().Bool("silent", false, "Disable output of tip/info messages. Useful when running in scripts or CI/CD pipelines.") rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) { silent, err := cmd.Flags().GetBool("silent") - config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL) - if err != nil { util.HandleError(err) } + config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL) + if !util.IsRunningInDocker() && !silent { util.CheckForUpdate() } - config.INFISICAL_SILENT_MODE = silent + loggedInDetails, err := util.GetCurrentLoggedInUserDetails() + + // If the user is logged in and their session is not expired, then we check if token auth is also being used concurrently. + if err == nil && loggedInDetails.IsUserLoggedIn && !loggedInDetails.LoginExpired { + token, err := util.GetInfisicalToken(cmd) + + // If token auth is being used concurrently, we warn the user that the token will be used instead of the logged in user's credentials. + if err == nil && token != nil { + var usingFrom string + if token.PassedAsFlag { + usingFrom = "--token flag" + } else { + usingFrom = "INFISICAL_TOKEN environment variable" + } + util.PrintWarning(fmt.Sprintf("You are currently logged in, but the command will be using the token provided from the %s.", usingFrom)) + + } + } + } // if config.INFISICAL_URL is set to the default value, check if INFISICAL_URL is set in the environment diff --git a/cli/packages/config/config.go b/cli/packages/config/config.go index a9640236e..c5e162c92 100644 --- a/cli/packages/config/config.go +++ b/cli/packages/config/config.go @@ -1,6 +1,5 @@ package config -var INFISICAL_SILENT_MODE bool var INFISICAL_URL string var INFISICAL_URL_MANUAL_OVERRIDE string var INFISICAL_LOGIN_URL string diff --git a/cli/packages/util/auth.go b/cli/packages/util/auth.go index 8333d2427..257d647a3 100644 --- a/cli/packages/util/auth.go +++ b/cli/packages/util/auth.go @@ -1,9 +1,6 @@ package util import ( - "fmt" - - "github.com/Infisical/infisical-merge/packages/config" "github.com/Infisical/infisical-merge/packages/models" ) @@ -52,7 +49,6 @@ func IsAuthMethodValid(authMethod string, allowUserAuth bool) (isValid bool, str } func ShouldUseInfisicalToken(token *models.TokenDetails, validTokenTypes []string) bool { - if token == nil { return false } @@ -63,24 +59,9 @@ func ShouldUseInfisicalToken(token *models.TokenDetails, validTokenTypes []strin } for _, tokenType := range validTokenTypes { - if token.Type != tokenType { - continue + if token.Type == tokenType { + return true } - - details, err := GetCurrentLoggedInUserDetails() - if err == nil && details.IsUserLoggedIn && !details.LoginExpired && !config.INFISICAL_SILENT_MODE { - - var usingFrom string - if token.PassedAsFlag { - usingFrom = "--token flag" - } else { - usingFrom = "INFISICAL_TOKEN environment variable" - } - PrintWarning(fmt.Sprintf("You are currently logged in, but the command will be using the token provided from the %s.", usingFrom)) - - } - - return true } return false