Skip to content

Commit

Permalink
fix: CLI login with custom auth URL (#6024)
Browse files Browse the repository at this point in the history
* fix: CLI login with custom auth URL
* fix: CLI login with custom agent URL
* fix: typo in README
  • Loading branch information
rangoo94 authored Nov 13, 2024
1 parent a2b13f3 commit 39fbcdc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/kubectl-testkube/commands/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ func GetClient(cmd *cobra.Command) (client.Client, string, error) {

if cfg.CloudContext.ApiKey != "" && cfg.CloudContext.RefreshToken != "" {
var refreshToken string
authURI := fmt.Sprintf("%s/idp", cfg.CloudContext.ApiUri)
authURI := cfg.CloudContext.AuthUri
if cfg.CloudContext.AuthUri == "" {
authURI = fmt.Sprintf("%s/idp", cfg.CloudContext.ApiUri)
}
token, refreshToken, err = cloudlogin.CheckAndRefreshToken(context.Background(), authURI, cfg.CloudContext.ApiKey, cfg.CloudContext.RefreshToken)
if err != nil {
// Error: failed refreshing, go thru login flow
Expand Down
14 changes: 12 additions & 2 deletions cmd/kubectl-testkube/commands/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,20 @@ func PopulateLoginDataToContext(orgID, envID, token, refreshToken, dockerContain
if options.Master.AgentToken != "" {
cfg.CloudContext.AgentKey = options.Master.AgentToken
}
if options.Master.URIs.Api != "" {
cfg.CloudContext.AgentUri = options.Master.URIs.Api
if options.Master.URIs.Agent != "" {
cfg.CloudContext.AgentUri = options.Master.URIs.Agent
}
if options.Master.URIs.Ui != "" {
cfg.CloudContext.UiUri = options.Master.URIs.Ui
}
if options.Master.URIs.Api != "" {
cfg.CloudContext.ApiUri = options.Master.URIs.Api
if options.Master.URIs.Agent == "" {
cfg.CloudContext.AgentUri = options.Master.URIs.Api
}
}
if options.Master.URIs.Auth != "" {
cfg.CloudContext.AuthUri = options.Master.URIs.Auth
}
cfg.ContextType = config.ContextTypeCloud
cfg.CloudContext.OrganizationId = orgID
Expand Down Expand Up @@ -349,6 +355,10 @@ func PopulateAgentDataToContext(options HelmOptions, cfg config.Data) error {
cfg.CloudContext.ApiUri = options.Master.URIs.Api
updated = true
}
if options.Master.URIs.Auth != "" {
cfg.CloudContext.AuthUri = options.Master.URIs.Auth
updated = true
}
if options.Master.IdToken != "" {
cfg.CloudContext.ApiKey = options.Master.IdToken
updated = true
Expand Down
1 change: 1 addition & 0 deletions cmd/kubectl-testkube/config/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type CloudContext struct {
AgentUri string `json:"agentUri,omitempty"`
RootDomain string `json:"rootDomain,omitempty"`
UiUri string `json:"uiUri,omitempty"`
AuthUri string `json:"authUri,omitempty"`
TokenType string `json:"tokenType,omitempty"`
DockerContainerName string `json:"dockerContainerName,omitempty"`
CustomAuth bool `json:"customConnector,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion cmd/tcl/kubectl-testkube/devbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This utility is used to help with development of the Agent features (like Test W
## Usage

* Login to Testkube CLI, like `testkube login`
* For local development Testkube Enterprise (Skaffold), consider `testkube login --api-uri-override=http://localhost:8099 --agent-uri-override=http://testkube-enterprise-api.tk-dev.svc.local:8089 --auth-uri-override=http://localhost:5556 --custom-auth`
* For local development Testkube Enterprise (Skaffold), consider `testkube login --api-uri-override=http://localhost:8099 --agent-uri-override=http://testkube-enterprise-api.tk-dev.svc.cluster.local:8089 --auth-uri-override=http://localhost:5556 --custom-auth`
* It's worth to create alias for that in own `.bashrc` or `.bash_profile`
* It's worth to pass a devbox name, like `-n dawid`, so it's not using random name
* For OSS version - run with `--oss` parameter
Expand Down

0 comments on commit 39fbcdc

Please sign in to comment.