@@ -7,8 +7,12 @@ Licensed under the MIT License.
7
7
package helpers
8
8
9
9
import (
10
+ "crypto/tls"
11
+ "net"
12
+ "net/http"
10
13
"os"
11
14
"strings"
15
+ "time"
12
16
13
17
"github.com/elastic/go-elasticsearch/v7"
14
18
"github.com/elastic/go-elasticsearch/v7/estransport"
@@ -17,13 +21,30 @@ import (
17
21
)
18
22
19
23
// NewElasticSearchClient create elasticsearch.Client
20
- func NewElasticSearchClient (host string ) (* elasticsearch.Client , error ) {
24
+ func NewElasticSearchClient (host string , insecureSkipVerify bool ) (* elasticsearch.Client , error ) {
21
25
conf := elasticsearch.Config {
22
26
Addresses : []string {host },
23
27
EnableMetrics : true ,
24
28
EnableDebugLogger : bool (klog .V (4 )),
25
29
Logger : nil ,
26
30
}
31
+ if insecureSkipVerify {
32
+ conf .Transport = & http.Transport {
33
+ Proxy : http .ProxyFromEnvironment ,
34
+ DialContext : (& net.Dialer {
35
+ Timeout : 30 * time .Second ,
36
+ KeepAlive : 30 * time .Second ,
37
+ }).DialContext ,
38
+ ForceAttemptHTTP2 : true ,
39
+ MaxIdleConns : 100 ,
40
+ IdleConnTimeout : 90 * time .Second ,
41
+ TLSHandshakeTimeout : 10 * time .Second ,
42
+ ExpectContinueTimeout : 1 * time .Second ,
43
+ TLSClientConfig : & tls.Config {
44
+ InsecureSkipVerify : true ,
45
+ },
46
+ }
47
+ }
27
48
if klog .V (4 ) {
28
49
conf .Logger = & estransport.TextLogger {
29
50
Output : os .Stdout ,
0 commit comments