...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package transport
16
17 import (
18 "context"
19 "fmt"
20 "strings"
21 "time"
22 )
23
24
25
26 func ValidateSecureEndpoints(tlsInfo TLSInfo, eps []string) ([]string, error) {
27 t, err := NewTransport(tlsInfo, 5*time.Second)
28 if err != nil {
29 return nil, err
30 }
31 defer t.CloseIdleConnections()
32
33 var errs []string
34 var endpoints []string
35 for _, ep := range eps {
36 if !strings.HasPrefix(ep, "https://") {
37 errs = append(errs, fmt.Sprintf("%q is insecure", ep))
38 continue
39 }
40 conn, cerr := t.DialContext(context.Background(), "tcp", ep[len("https://"):])
41 if cerr != nil {
42 errs = append(errs, fmt.Sprintf("%q failed to dial (%v)", ep, cerr))
43 continue
44 }
45 conn.Close()
46 endpoints = append(endpoints, ep)
47 }
48 if len(errs) != 0 {
49 err = fmt.Errorf("%s", strings.Join(errs, ","))
50 }
51 return endpoints, err
52 }
53
View as plain text