mirror of
https://github.com/minio/minio.git
synced 2025-04-23 03:45:49 -04:00
notify/webhook: Handle webendpoints without port (#3568)
Fixes and issue initializing webhook notification ``` FATA[0000] Initializing object layer failed cause=Unable to initialize event \ notification. dial tcp: missing port in address requestb.in source=[server-main.go:448:serverMain()] ```
This commit is contained in:
parent
d6a327fbc5
commit
7b85756c64
@ -37,13 +37,13 @@ type httpConn struct {
|
|||||||
Endpoint string
|
Endpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup host address by dialing.
|
// Lookup endpoint address by successfully dialing.
|
||||||
func lookupHost(addr string) error {
|
func lookupEndpoint(u *url.URL) error {
|
||||||
dialer := &net.Dialer{
|
dialer := &net.Dialer{
|
||||||
Timeout: 300 * time.Millisecond,
|
Timeout: 300 * time.Millisecond,
|
||||||
KeepAlive: 300 * time.Millisecond,
|
KeepAlive: 300 * time.Millisecond,
|
||||||
}
|
}
|
||||||
nconn, err := dialer.Dial("tcp", addr)
|
nconn, err := dialer.Dial("tcp", canonicalAddr(u))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func newWebhookNotify(accountID string) (*logrus.Logger, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = lookupHost(u.Host); err != nil {
|
if err = lookupEndpoint(u); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
cmd/utils.go
18
cmd/utils.go
@ -102,6 +102,24 @@ func urlPath2BucketObjectName(u *url.URL) (bucketName, objectName string) {
|
|||||||
return bucketName, objectName
|
return bucketName, objectName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var portMap = map[string]string{
|
||||||
|
"http": "80",
|
||||||
|
"https": "443",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Given a string of the form "host", "host:port", or "[ipv6::address]:port",
|
||||||
|
// return true if the string includes a port.
|
||||||
|
func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
|
||||||
|
|
||||||
|
// canonicalAddr returns url.Host but always with a ":port" suffix
|
||||||
|
func canonicalAddr(u *url.URL) string {
|
||||||
|
addr := u.Host
|
||||||
|
if !hasPort(addr) {
|
||||||
|
return addr + ":" + portMap[u.Scheme]
|
||||||
|
}
|
||||||
|
return addr
|
||||||
|
}
|
||||||
|
|
||||||
// checkDuplicates - function to validate if there are duplicates in a slice of endPoints.
|
// checkDuplicates - function to validate if there are duplicates in a slice of endPoints.
|
||||||
func checkDuplicateEndpoints(endpoints []*url.URL) error {
|
func checkDuplicateEndpoints(endpoints []*url.URL) error {
|
||||||
var strs []string
|
var strs []string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user