You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/api/internal/edge/url.go

33 lines
680 B

package edge
import (
"net"
"net/url"
"github.com/pkg/errors"
)
// ParseHostForEdge returns the hostname of the given URL, will fail if host is localhost
func ParseHostForEdge(portainerURL string) (string, error) {
parsedURL, err := url.Parse(portainerURL)
if err != nil {
return "", errors.Wrap(err, "Unable to parse Portainer URL")
}
portainerHost, _, err := net.SplitHostPort(parsedURL.Host)
if err != nil {
portainerHost = parsedURL.Host
}
if portainerHost == "" {
return "", errors.New("hostname cannot be empty")
}
if portainerHost == "localhost" {
return "", errors.New("cannot use localhost as environment URL")
}
return portainerHost, nil
}