Skip to content

Commit

Permalink
Breaking: url_host now returns only hostname without port
Browse files Browse the repository at this point in the history
url_port is added to templates to compensate
  • Loading branch information
Eugene Dementyev committed Aug 3, 2021
1 parent 86b53ed commit a3b245d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ssm/transformations/template_funcs.go
Expand Up @@ -11,6 +11,7 @@ import (
var funcMap = template.FuncMap{
"env": GetEnv,
"url_host": URLHost,
"url_port": URLPort,
"url_password": URLPassword,
"url_path": URLPath,
"url_scheme": URLScheme,
Expand Down Expand Up @@ -59,13 +60,22 @@ func URLScheme(input string) (string, error) {
return u.Scheme, nil
}

// URLHost extracts host from the URL or returns "" if it's not set
// URLHost extracts host from the URL or returns "" if it's not set. It also strips any port if there is any
func URLHost(input string) (string, error) {
u, err := url.Parse(input)
if err != nil {
return "", err
}
return u.Host, nil
return u.Hostname(), nil
}

// URLHost extracts host from the URL or returns "" if it's not set
func URLPort(input string) (string, error) {
u, err := url.Parse(input)
if err != nil {
return "", err
}
return u.Port(), nil
}

// URLPath extracts path from the URL or returns "" if it's not set
Expand Down

0 comments on commit a3b245d

Please sign in to comment.