mirror of
https://github.com/minio/minio.git
synced 2025-11-10 14:09:48 -05:00
committed by
Nitish Tiwari
parent
4b858b562a
commit
998f01fadc
@@ -80,15 +80,15 @@ const (
|
||||
|
||||
// PostgreSQLArgs - PostgreSQL target arguments.
|
||||
type PostgreSQLArgs struct {
|
||||
Enable bool `json:"enable"`
|
||||
Format string `json:"format"`
|
||||
ConnectionString string `json:"connectionString"`
|
||||
Table string `json:"table"`
|
||||
Host xnet.URL `json:"host"` // default: localhost
|
||||
Port string `json:"port"` // default: 5432
|
||||
User string `json:"user"` // default: user running minio
|
||||
Password string `json:"password"` // default: no password
|
||||
Database string `json:"database"` // default: same as user
|
||||
Enable bool `json:"enable"`
|
||||
Format string `json:"format"`
|
||||
ConnectionString string `json:"connectionString"`
|
||||
Table string `json:"table"`
|
||||
Host xnet.Host `json:"host"` // default: localhost
|
||||
Port string `json:"port"` // default: 5432
|
||||
User string `json:"user"` // default: user running minio
|
||||
Password string `json:"password"` // default: no password
|
||||
Database string `json:"database"` // default: same as user
|
||||
}
|
||||
|
||||
// Validate PostgreSQLArgs fields
|
||||
|
||||
@@ -118,7 +118,6 @@ func ParseHost(s string) (*Host, error) {
|
||||
if !strings.Contains(err.Error(), "missing port in address") {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
host = s
|
||||
portStr = ""
|
||||
} else {
|
||||
@@ -129,11 +128,23 @@ func ParseHost(s string) (*Host, error) {
|
||||
isPortSet = true
|
||||
}
|
||||
|
||||
if i := strings.Index(host, "%"); i > -1 {
|
||||
host = host[:i]
|
||||
if host != "" {
|
||||
host, err = trimIPv6(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if !isValidHost(host) {
|
||||
// IPv6 requires a link-local address on every network interface.
|
||||
// `%interface` should be preserved.
|
||||
trimmedHost := host
|
||||
|
||||
if i := strings.LastIndex(trimmedHost, "%"); i > -1 {
|
||||
// `%interface` can be skipped for validity check though.
|
||||
trimmedHost = trimmedHost[:i]
|
||||
}
|
||||
|
||||
if !isValidHost(trimmedHost) {
|
||||
return nil, errors.New("invalid hostname")
|
||||
}
|
||||
|
||||
@@ -143,3 +154,15 @@ func ParseHost(s string) (*Host, error) {
|
||||
IsPortSet: isPortSet,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// IPv6 can be embedded with square brackets.
|
||||
func trimIPv6(host string) (string, error) {
|
||||
// `missing ']' in host` error is already handled in `SplitHostPort`
|
||||
if host[len(host)-1] == ']' {
|
||||
if host[0] != '[' {
|
||||
return "", errors.New("missing '[' in host")
|
||||
}
|
||||
return host[1:][:len(host)-2], nil
|
||||
}
|
||||
return host, nil
|
||||
}
|
||||
|
||||
@@ -138,6 +138,13 @@ func TestHostUnmarshalJSON(t *testing.T) {
|
||||
{[]byte(`"play-minio-io"`), &Host{"play-minio-io", 0, false}, false},
|
||||
{[]byte(`"play--min.io"`), &Host{"play--min.io", 0, false}, false},
|
||||
{[]byte(`":9000"`), nil, true},
|
||||
{[]byte(`"[fe80::8097:76eb:b397:e067%wlp2s0]"`), &Host{"fe80::8097:76eb:b397:e067%wlp2s0", 0, false}, false},
|
||||
{[]byte(`"[fe80::8097:76eb:b397:e067]:9000"`), &Host{"fe80::8097:76eb:b397:e067", 9000, true}, false},
|
||||
{[]byte(`"fe80::8097:76eb:b397:e067%wlp2s0"`), nil, true},
|
||||
{[]byte(`"fe80::8097:76eb:b397:e067%wlp2s0]"`), nil, true},
|
||||
{[]byte(`"[fe80::8097:76eb:b397:e067%wlp2s0"`), nil, true},
|
||||
{[]byte(`"[[fe80::8097:76eb:b397:e067%wlp2s0]]"`), nil, true},
|
||||
{[]byte(`"[[fe80::8097:76eb:b397:e067%wlp2s0"`), nil, true},
|
||||
{[]byte(`"play:"`), nil, true},
|
||||
{[]byte(`"play::"`), nil, true},
|
||||
{[]byte(`"play:90000"`), nil, true},
|
||||
@@ -207,3 +214,31 @@ func TestParseHost(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrimIPv6(t *testing.T) {
|
||||
testCases := []struct {
|
||||
IP string
|
||||
expectedIP string
|
||||
expectErr bool
|
||||
}{
|
||||
{"[fe80::8097:76eb:b397:e067%wlp2s0]", "fe80::8097:76eb:b397:e067%wlp2s0", false},
|
||||
{"fe80::8097:76eb:b397:e067%wlp2s0]", "fe80::8097:76eb:b397:e067%wlp2s0", true},
|
||||
{"[fe80::8097:76eb:b397:e067%wlp2s0]]", "fe80::8097:76eb:b397:e067%wlp2s0]", false},
|
||||
{"[[fe80::8097:76eb:b397:e067%wlp2s0]]", "[fe80::8097:76eb:b397:e067%wlp2s0]", false},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
ip, err := trimIPv6(testCase.IP)
|
||||
expectErr := (err != nil)
|
||||
|
||||
if expectErr != testCase.expectErr {
|
||||
t.Fatalf("test %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr)
|
||||
}
|
||||
|
||||
if !testCase.expectErr {
|
||||
if ip != testCase.expectedIP {
|
||||
t.Fatalf("test %v: IP: expected: %#v, got: %#v", i+1, testCase.expectedIP, ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user