Skip to content

Commit

Permalink
fix: cloud context callback port
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Nov 18, 2024
1 parent f9ce626 commit d563588
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/kubectl-testkube/commands/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"github.com/kubeshop/testkube/pkg/cloudlogin"
)

const UserAgentCLI = "Testkube-CLI"
const (
UserAgentCLI = "Testkube-CLI"
callbackPort = 38090
)

// GetClient returns api client
func GetClient(cmd *cobra.Command) (client.Client, string, error) {
Expand Down Expand Up @@ -76,7 +79,12 @@ func GetClient(cmd *cobra.Command) (client.Client, string, error) {
token, refreshToken, err = cloudlogin.CheckAndRefreshToken(context.Background(), authURI, cfg.CloudContext.ApiKey, cfg.CloudContext.RefreshToken)
if err != nil {
// Error: failed refreshing, go thru login flow
token, refreshToken, err = LoginUser(authURI, cfg.CloudContext.CustomAuth, cfg.CloudContext.CallbackPort)
port := callbackPort
if cfg.CloudContext.CallbackPort != 0 {
port = cfg.CloudContext.CallbackPort
}

token, refreshToken, err = LoginUser(authURI, cfg.CloudContext.CustomAuth, port)
if err != nil {
return nil, "", fmt.Errorf("error logging in: %w", err)
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/kubectl-testkube/commands/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ func PopulateLoginDataToContext(orgID, envID, token, refreshToken, dockerContain
cfg.CloudContext.RefreshToken = refreshToken
}
cfg.CloudContext.DockerContainerName = dockerContainerName
if options.Master.CallbackPort != 0 {
cfg.CloudContext.CallbackPort = options.Master.CallbackPort
}

cfg, err := PopulateOrgAndEnvNames(cfg, orgID, envID, options.Master.URIs.Api)
if err != nil {
Expand Down Expand Up @@ -407,6 +410,10 @@ func PopulateAgentDataToContext(options HelmOptions, cfg config.Data) error {
cfg.CloudContext.OrganizationId = options.Master.OrgId
updated = true
}
if options.Master.CallbackPort != 0 {
cfg.CloudContext.CallbackPort = options.Master.CallbackPort
updated = true
}

if updated {
return config.Save(cfg)
Expand Down Expand Up @@ -488,6 +495,7 @@ func PopulateCloudConfig(cfg config.Data, apiKey string, dockerContainerName *st
if dockerContainerName != nil {
cfg.CloudContext.DockerContainerName = *dockerContainerName
}
cfg.CloudContext.CallbackPort = opts.Master.CallbackPort

return cfg
}
Expand Down

0 comments on commit d563588

Please sign in to comment.