1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-14 11:57:59 +00:00

add coonection Close, add default port on Network Validate

This commit is contained in:
Pedro Carmezim 2022-04-07 16:05:21 +01:00
parent 33d794e3b2
commit 1f07096404
2 changed files with 9 additions and 5 deletions

View file

@ -140,19 +140,23 @@ func ValidateServiceAccountSelector(store esv1beta1.GenericStore, ref esmeta.Ser
func NetworkValidate(endpoint string, timeout time.Duration) error {
hostname, err := url.Parse(endpoint)
if err != nil {
return fmt.Errorf("could not parse url: %w", err)
}
host, port, err := net.SplitHostPort(hostname.Host)
if err != nil {
return fmt.Errorf("could not find host and port from url: %w", err)
host := hostname.Hostname()
port := hostname.Port()
if port == "" {
port = "443"
}
url := fmt.Sprintf("%v:%v", host, port)
_, err = net.DialTimeout("tcp", url, timeout)
conn, err := net.DialTimeout("tcp", url, timeout)
if err != nil {
return fmt.Errorf("error accessing external store: %w", err)
}
defer conn.Close()
return nil
}

View file

@ -227,7 +227,7 @@ func TestConvertKeys(t *testing.T) {
}
func TestValidate(t *testing.T) {
err := NetworkValidate("https://google.com", 10*time.Second)
err := NetworkValidate("http://google.com", 10*time.Second)
if err != nil {
t.Errorf("Connection problem: %v", err)
}