mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 14:26:38 +00:00
Merge pull request #1896 from Infisical/feat/removed-the-need-to-pass-api-for-cli-domain
feat: removed the need to pass /api for cli domain
This commit is contained in:
@@ -15,7 +15,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -257,19 +256,6 @@ func WriteBytesToFile(data *bytes.Buffer, outputPath string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendAPIEndpoint(address string) string {
|
|
||||||
// Ensure the address does not already end with "/api"
|
|
||||||
if strings.HasSuffix(address, "/api") {
|
|
||||||
return address
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the address ends with a slash and append accordingly
|
|
||||||
if address[len(address)-1] == '/' {
|
|
||||||
return address + "api"
|
|
||||||
}
|
|
||||||
return address + "/api"
|
|
||||||
}
|
|
||||||
|
|
||||||
func ParseAgentConfig(configFile []byte) (*Config, error) {
|
func ParseAgentConfig(configFile []byte) (*Config, error) {
|
||||||
var rawConfig struct {
|
var rawConfig struct {
|
||||||
Infisical InfisicalConfig `yaml:"infisical"`
|
Infisical InfisicalConfig `yaml:"infisical"`
|
||||||
@@ -290,7 +276,7 @@ func ParseAgentConfig(configFile []byte) (*Config, error) {
|
|||||||
rawConfig.Infisical.Address = DEFAULT_INFISICAL_CLOUD_URL
|
rawConfig.Infisical.Address = DEFAULT_INFISICAL_CLOUD_URL
|
||||||
}
|
}
|
||||||
|
|
||||||
config.INFISICAL_URL = appendAPIEndpoint(rawConfig.Infisical.Address)
|
config.INFISICAL_URL = util.AppendAPIEndpoint(rawConfig.Infisical.Address)
|
||||||
|
|
||||||
log.Info().Msgf("Infisical instance address set to %s", rawConfig.Infisical.Address)
|
log.Info().Msgf("Infisical instance address set to %s", rawConfig.Infisical.Address)
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ var loginCmd = &cobra.Command{
|
|||||||
//set domainQuery to false
|
//set domainQuery to false
|
||||||
if !overrideDomain {
|
if !overrideDomain {
|
||||||
domainQuery = false
|
domainQuery = false
|
||||||
config.INFISICAL_URL = config.INFISICAL_URL_MANUAL_OVERRIDE
|
config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL_MANUAL_OVERRIDE)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ func NewDomainPrompt() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return domain, nil
|
return util.AppendAPIEndpoint(domain), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoggedInUsersPrompt(profiles []string) (string, error) {
|
func LoggedInUsersPrompt(profiles []string) (string, error) {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func GetCurrentLoggedInUserDetails() (LoggedInUserDetails, error) {
|
|||||||
//configFile.LoggedInUserDomain
|
//configFile.LoggedInUserDomain
|
||||||
//if not empty set as infisical url
|
//if not empty set as infisical url
|
||||||
if configFile.LoggedInUserDomain != "" {
|
if configFile.LoggedInUserDomain != "" {
|
||||||
config.INFISICAL_URL = configFile.LoggedInUserDomain
|
config.INFISICAL_URL = AppendAPIEndpoint(configFile.LoggedInUserDomain)
|
||||||
}
|
}
|
||||||
|
|
||||||
isAuthenticated := api.CallIsAuthenticated(httpClient)
|
isAuthenticated := api.CallIsAuthenticated(httpClient)
|
||||||
|
|||||||
@@ -233,3 +233,16 @@ func getCurrentBranch() (string, error) {
|
|||||||
}
|
}
|
||||||
return path.Base(strings.TrimSpace(out.String())), nil
|
return path.Base(strings.TrimSpace(out.String())), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AppendAPIEndpoint(address string) string {
|
||||||
|
// Ensure the address does not already end with "/api"
|
||||||
|
if strings.HasSuffix(address, "/api") {
|
||||||
|
return address
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the address ends with a slash and append accordingly
|
||||||
|
if address[len(address)-1] == '/' {
|
||||||
|
return address + "api"
|
||||||
|
}
|
||||||
|
return address + "/api"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user