Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cmd/command/cd/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cd
import (
"fmt"
"os"
"strings"

"github.com/urfave/cli"
"helm.sh/helm/v3/pkg/action"
Expand Down Expand Up @@ -188,11 +189,13 @@ func confirmCluster(url, token string) (bool, string, error) {
func (p *Plural) HandleCdLogin(c *cli.Context) (err error) {
prior := console.ReadConfig()
if prior.Url != "" {
if common.Affirm(
fmt.Sprintf("You've already configured your console at %s, continue using those credentials?", prior.Url),
"PLURAL_CD_USE_EXISTING_CREDENTIALS",
) {
return
if !strings.EqualFold(common.GetHostnameFromURL(prior.Url), common.GetHostnameFromURL(consoleURL)) {
if common.Affirm(
fmt.Sprintf("You've already configured your console at %s, continue using those credentials?", prior.Url),
"PLURAL_CD_USE_EXISTING_CREDENTIALS",
) {
return
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/command/up/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/AlecAivazis/survey/v2"
"github.com/pluralsh/plural-cli/pkg/api"
"github.com/pluralsh/plural-cli/pkg/console"
"github.com/samber/lo"
"github.com/urfave/cli"

Expand Down Expand Up @@ -165,6 +166,7 @@ func (p *Plural) handleUp(c *cli.Context) error {
}

func (p *Plural) choseCluster() (name, url string, err error) {
prior := console.ReadConfig()
instances, err := p.GetConsoleInstances()
if err != nil {
return
Expand All @@ -174,6 +176,11 @@ func (p *Plural) choseCluster() (name, url string, err error) {
clusterMap := map[string]string{}

for _, cluster := range instances {
if prior.Url != "" && strings.EqualFold(common.GetHostnameFromURL(prior.Url), common.GetHostnameFromURL(cluster.URL)) {
name = cluster.Name
url = cluster.URL
return
}
clusterNames = append(clusterNames, cluster.Name)
clusterMap[cluster.Name] = cluster.URL
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -192,3 +193,17 @@ func GetIdAndName(input string) (id, name *string) {
}
return
}

func GetHostnameFromURL(u string) string {
parsed, err := url.Parse(u)
if err != nil {
return ""
}
if parsed.Scheme == "" && parsed.Host == "" {
if parsed, err = url.Parse("//" + u); err != nil {
return ""
}
}
hostname := parsed.Hostname()
return hostname
}
Loading