daemon/logger/gelf: remove uses of pkg/urlutil.IsTransportURL()

pkg/urlutil (despite its poorly chosen name) is not really intended as a generic
utility to handle URLs, and should only be used by the builder to handle (remote)
build contexts.

This patch:

- removes a redundant use of urlutil.IsTransportURL(); code further below already
  checked if the given scheme (protocol) was supported.
- renames some variables that collided with imported packages.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-04-09 15:03:04 +02:00
parent c6872980bb
commit 2e831c76c2
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 8 additions and 14 deletions

View File

@ -14,7 +14,6 @@ import (
"github.com/Graylog2/go-gelf/gelf"
"github.com/docker/docker/daemon/logger"
"github.com/docker/docker/daemon/logger/loggerutils"
"github.com/docker/docker/pkg/urlutil"
"github.com/sirupsen/logrus"
)
@ -251,23 +250,18 @@ func parseAddress(address string) (*url.URL, error) {
if address == "" {
return nil, fmt.Errorf("gelf-address is a required parameter")
}
if !urlutil.IsTransportURL(address) {
return nil, fmt.Errorf("gelf-address should be in form proto://address, got %v", address)
}
url, err := url.Parse(address)
addr, err := url.Parse(address)
if err != nil {
return nil, err
}
// we support only udp
if url.Scheme != "udp" && url.Scheme != "tcp" {
if addr.Scheme != "udp" && addr.Scheme != "tcp" {
return nil, fmt.Errorf("gelf: endpoint needs to be TCP or UDP")
}
// get host and port
if _, _, err = net.SplitHostPort(url.Host); err != nil {
if _, _, err = net.SplitHostPort(addr.Host); err != nil {
return nil, fmt.Errorf("gelf: please provide gelf-address as proto://host:port")
}
return url, nil
return addr, nil
}

View File

@ -223,12 +223,12 @@ func TestNewTCP(t *testing.T) {
ContainerID: "12345678901234567890",
}
logger, err := New(info)
gelfLogger, err := New(info)
if err != nil {
t.Fatal(err)
}
err = logger.Close()
err = gelfLogger.Close()
if err != nil {
t.Fatal(err)
}
@ -250,12 +250,12 @@ func TestNewUDP(t *testing.T) {
ContainerID: "12345678901234567890",
}
logger, err := New(info)
gelfLogger, err := New(info)
if err != nil {
t.Fatal(err)
}
err = logger.Close()
err = gelfLogger.Close()
if err != nil {
t.Fatal(err)
}