Skip to content

Commit

Permalink
feat(cli): correctly handle trailing slash in server url (#3586)
Browse files Browse the repository at this point in the history
  • Loading branch information
schoren committed Jan 31, 2024
1 parent 9f7f26f commit 69393fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
33 changes: 14 additions & 19 deletions cli/config/config.go
Expand Up @@ -22,15 +22,15 @@ var (
)

type Config struct {
Scheme string `yaml:"scheme"`
Endpoint string `yaml:"endpoint"`
ServerPath *string `yaml:"serverPath,omitempty"`
OrganizationID string `yaml:"organizationID,omitempty"`
EnvironmentID string `yaml:"environmentID,omitempty"`
Token string `yaml:"token,omitempty"`
Jwt string `yaml:"jwt,omitempty"`
AgentApiKey string `yaml:"-"`
EndpointOverriden bool `yaml:"-"`
Scheme string `yaml:"scheme"`
Endpoint string `yaml:"endpoint"`
ServerPath string `yaml:"serverPath,omitempty"`
OrganizationID string `yaml:"organizationID,omitempty"`
EnvironmentID string `yaml:"environmentID,omitempty"`
Token string `yaml:"token,omitempty"`
Jwt string `yaml:"jwt,omitempty"`
AgentApiKey string `yaml:"-"`
EndpointOverriden bool `yaml:"-"`

// cloud config
CloudAPIEndpoint string `yaml:"-"`
Expand Down Expand Up @@ -61,8 +61,8 @@ func (c Config) UI() string {

func (c Config) Path() string {
pathPrefix := "/api"
if c.ServerPath != nil {
pathPrefix = *c.ServerPath
if c.ServerPath != "" {
pathPrefix = c.ServerPath
}

if pathPrefix == "/" {
Expand Down Expand Up @@ -130,18 +130,13 @@ func ValidateServerURL(serverURL string) error {
return nil
}

func ParseServerURL(serverURL string) (scheme, endpoint string, serverPath *string, err error) {
func ParseServerURL(serverURL string) (scheme, endpoint, serverPath string, err error) {
url, err := urlx.Parse(serverURL)
if err != nil {
return "", "", nil, fmt.Errorf("could not parse server URL: %w", err)
return "", "", "", fmt.Errorf("could not parse server URL: %w", err)
}

var path *string
if url.Path != "" {
path = &url.Path
}

return url.Scheme, url.Host, path, nil
return url.Scheme, url.Host, url.Path, nil
}

func Save(config Config) error {
Expand Down
4 changes: 3 additions & 1 deletion cli/config/configurator.go
Expand Up @@ -101,7 +101,9 @@ func (c Configurator) createConfig(serverURL string) (Config, error) {
}

if strings.Contains(serverURL, DefaultCloudDomain) {
path = &DefaultCloudPath
path = DefaultCloudPath
} else if !strings.HasSuffix(path, "/api") {
path = strings.TrimSuffix(path, "/") + "/api"
}

return Config{
Expand Down

0 comments on commit 69393fc

Please sign in to comment.