@@ -6,15 +6,15 @@ package kibana
66
77import (
88 "bytes"
9+ "crypto/tls"
910 "io"
1011 "net/http"
1112 "net/url"
1213 "os"
1314
14- "github.com/elastic/elastic-package/internal/install"
15-
1615 "github.com/pkg/errors"
1716
17+ "github.com/elastic/elastic-package/internal/install"
1818 "github.com/elastic/elastic-package/internal/logger"
1919 "github.com/elastic/elastic-package/internal/stack"
2020)
@@ -24,10 +24,15 @@ type Client struct {
2424 host string
2525 username string
2626 password string
27+
28+ tlSkipVerify bool
2729}
2830
31+ // ClientOption is functional option modifying Kibana client.
32+ type ClientOption func (* Client )
33+
2934// NewClient creates a new instance of the client.
30- func NewClient () (* Client , error ) {
35+ func NewClient (opts ... ClientOption ) (* Client , error ) {
3136 host := os .Getenv (stack .KibanaHostEnv )
3237 if host == "" {
3338 return nil , stack .UndefinedEnvError (stack .KibanaHostEnv )
@@ -36,11 +41,23 @@ func NewClient() (*Client, error) {
3641 username := os .Getenv (stack .ElasticsearchUsernameEnv )
3742 password := os .Getenv (stack .ElasticsearchPasswordEnv )
3843
39- return & Client {
44+ c := & Client {
4045 host : host ,
4146 username : username ,
4247 password : password ,
43- }, nil
48+ }
49+
50+ for _ , opt := range opts {
51+ opt (c )
52+ }
53+ return c , nil
54+ }
55+
56+ // TLSSkipVerify option disables TLS verification.
57+ func TLSSkipVerify () ClientOption {
58+ return func (c * Client ) {
59+ c .tlSkipVerify = true
60+ }
4461}
4562
4663func (c * Client ) get (resourcePath string ) (int , []byte , error ) {
@@ -85,6 +102,12 @@ func (c *Client) sendRequest(method, resourcePath string, body []byte) (int, []b
85102 req .Header .Add ("kbn-xsrf" , install .DefaultStackVersion )
86103
87104 client := http.Client {}
105+ if c .tlSkipVerify {
106+ client .Transport = & http.Transport {
107+ TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
108+ }
109+ }
110+
88111 resp , err := client .Do (req )
89112 if err != nil {
90113 return 0 , nil , errors .Wrap (err , "could not send request to Kibana API" )
0 commit comments