Requested changes

This commit is contained in:
Daniel Hougaard
2024-09-18 12:50:28 +04:00
parent e7278c4cd9
commit 9234213c62
3 changed files with 24 additions and 25 deletions
+22 -3
View File
@@ -4,6 +4,7 @@ Copyright (c) 2023 Infisical Inc.
package cmd package cmd
import ( import (
"fmt"
"os" "os"
"strings" "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.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) { rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
silent, err := cmd.Flags().GetBool("silent") silent, err := cmd.Flags().GetBool("silent")
config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL)
if err != nil { if err != nil {
util.HandleError(err) util.HandleError(err)
} }
config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL)
if !util.IsRunningInDocker() && !silent { if !util.IsRunningInDocker() && !silent {
util.CheckForUpdate() 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 // if config.INFISICAL_URL is set to the default value, check if INFISICAL_URL is set in the environment
-1
View File
@@ -1,6 +1,5 @@
package config package config
var INFISICAL_SILENT_MODE bool
var INFISICAL_URL string var INFISICAL_URL string
var INFISICAL_URL_MANUAL_OVERRIDE string var INFISICAL_URL_MANUAL_OVERRIDE string
var INFISICAL_LOGIN_URL string var INFISICAL_LOGIN_URL string
+2 -21
View File
@@ -1,9 +1,6 @@
package util package util
import ( import (
"fmt"
"github.com/Infisical/infisical-merge/packages/config"
"github.com/Infisical/infisical-merge/packages/models" "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 { func ShouldUseInfisicalToken(token *models.TokenDetails, validTokenTypes []string) bool {
if token == nil { if token == nil {
return false return false
} }
@@ -63,24 +59,9 @@ func ShouldUseInfisicalToken(token *models.TokenDetails, validTokenTypes []strin
} }
for _, tokenType := range validTokenTypes { for _, tokenType := range validTokenTypes {
if token.Type != tokenType { if token.Type == tokenType {
continue 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 return false