fix(cli): resolved not printing the url on api override

This commit is contained in:
=
2024-07-25 15:28:54 +05:30
parent a30e06e392
commit 08d7dead8c
+4 -8
View File
@@ -24,7 +24,6 @@ import (
"github.com/Infisical/infisical-merge/packages/models" "github.com/Infisical/infisical-merge/packages/models"
"github.com/Infisical/infisical-merge/packages/srp" "github.com/Infisical/infisical-merge/packages/srp"
"github.com/Infisical/infisical-merge/packages/util" "github.com/Infisical/infisical-merge/packages/util"
"github.com/chzyer/readline"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/manifoldco/promptui" "github.com/manifoldco/promptui"
@@ -205,6 +204,7 @@ var loginCmd = &cobra.Command{
if !overrideDomain { if !overrideDomain {
domainQuery = false domainQuery = false
config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL_MANUAL_OVERRIDE) config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL_MANUAL_OVERRIDE)
config.INFISICAL_LOGIN_URL = fmt.Sprintf("%s/login", strings.TrimSuffix(config.INFISICAL_URL, "/api"))
} }
} }
@@ -713,7 +713,7 @@ func askForMFACode() string {
return mfaVerifyCode return mfaVerifyCode
} }
func askToPasteJwtToken(stdin *readline.CancelableStdin, success chan models.UserCredentials, failure chan error) { func askToPasteJwtToken(success chan models.UserCredentials, failure chan error) {
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
fmt.Println("\n\nOnce login is completed via browser, the CLI should be authenticated automatically.") fmt.Println("\n\nOnce login is completed via browser, the CLI should be authenticated automatically.")
fmt.Println("However, if browser fails to communicate with the CLI, please paste the token from the browser below.") fmt.Println("However, if browser fails to communicate with the CLI, please paste the token from the browser below.")
@@ -807,26 +807,22 @@ func browserCliLogin() (models.UserCredentials, error) {
log.Debug().Msgf("Callback server listening on port %d", callbackPort) log.Debug().Msgf("Callback server listening on port %d", callbackPort)
stdin := readline.NewCancelableStdin(os.Stdin)
go http.Serve(listener, corsHandler) go http.Serve(listener, corsHandler)
go askToPasteJwtToken(stdin, success, failure) go askToPasteJwtToken(success, failure)
for { for {
select { select {
case loginResponse := <-success: case loginResponse := <-success:
_ = closeListener(&listener) _ = closeListener(&listener)
_ = stdin.Close()
fmt.Println("Browser login successful") fmt.Println("Browser login successful")
return loginResponse, nil return loginResponse, nil
case err := <-failure: case err := <-failure:
serverErr := closeListener(&listener) serverErr := closeListener(&listener)
stdErr := stdin.Close() return models.UserCredentials{}, errors.Join(err, serverErr)
return models.UserCredentials{}, errors.Join(err, serverErr, stdErr)
case <-timeout: case <-timeout:
_ = closeListener(&listener) _ = closeListener(&listener)
_ = stdin.Close()
return models.UserCredentials{}, errors.New("server timeout") return models.UserCredentials{}, errors.New("server timeout")
} }
} }