From a3b245d63310c390ce7515c8bdbf3d49567d0976 Mon Sep 17 00:00:00 2001 From: Eugene Dementyev Date: Tue, 3 Aug 2021 14:54:25 +1200 Subject: [PATCH] Breaking: url_host now returns only hostname without port url_port is added to templates to compensate --- ssm/transformations/template_funcs.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ssm/transformations/template_funcs.go b/ssm/transformations/template_funcs.go index 8abab5c..5fdffef 100644 --- a/ssm/transformations/template_funcs.go +++ b/ssm/transformations/template_funcs.go @@ -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, @@ -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