Skip to content

Commit

Permalink
feat: Add options to skip TLS validation
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Barcelona <fede_rico_94@hotmail.com>
  • Loading branch information
tembleking committed May 11, 2020
1 parent 7832e1b commit 23b1e07
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
11 changes: 9 additions & 2 deletions sysdig/monitor/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package monitor

import (
"crypto/tls"
"io"
"net/http"
)
Expand All @@ -12,11 +13,17 @@ type SysdigMonitorClient interface {
GetAlertById(int) (Alert, error)
}

func NewSysdigMonitorClient(apiToken string, url string) SysdigMonitorClient {
func NewSysdigMonitorClient(apiToken string, url string, insecure bool) SysdigMonitorClient {
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
},
}

return &sysdigMonitorClient{
SysdigMonitorAPIToken: apiToken,
URL: url,
httpClient: http.DefaultClient,
httpClient: httpClient,
}
}

Expand Down
10 changes: 10 additions & 0 deletions sysdig/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func Provider() terraform.ResourceProvider {
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_SECURE_URL", "https://secure.sysdig.com"),
},
"sysdig_secure_insecure_tls": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_SECURE_INSECURE_TLS", false),
},
"sysdig_monitor_api_token": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -30,6 +35,11 @@ func Provider() terraform.ResourceProvider {
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_MONITOR_URL", "https://app.sysdigcloud.com"),
},
"sysdig_monitor_insecure_tls": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("SYSDIG_MONITOR_INSECURE_TLS", false),
},
},
ResourcesMap: map[string]*schema.Resource{
"sysdig_user": resourceSysdigUser(),
Expand Down
11 changes: 9 additions & 2 deletions sysdig/secure/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package secure

import (
"crypto/tls"
"io"
"log"
"net/http"
Expand Down Expand Up @@ -45,11 +46,17 @@ type SysdigSecureClient interface {
UpdateMacro(Macro) (Macro, error)
}

func NewSysdigSecureClient(sysdigSecureAPIToken string, url string) SysdigSecureClient {
func NewSysdigSecureClient(sysdigSecureAPIToken string, url string, insecure bool) SysdigSecureClient {
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecure},
},
}

return &sysdigSecureClient{
SysdigSecureAPIToken: sysdigSecureAPIToken,
URL: url,
httpClient: http.DefaultClient,
httpClient: httpClient,
}
}

Expand Down
2 changes: 2 additions & 0 deletions sysdig/sysdig_clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (c *sysdigClients) sysdigMonitorClient() (m monitor.SysdigMonitorClient, er
c.monitorClient = monitor.NewSysdigMonitorClient(
monitorAPIToken,
c.d.Get("sysdig_monitor_url").(string),
c.d.Get("sysdig_monitor_insecure_tls").(bool),
)
})

Expand All @@ -49,6 +50,7 @@ func (c *sysdigClients) sysdigSecureClient() (s secure.SysdigSecureClient, err e
c.secureClient = secure.NewSysdigSecureClient(
secureAPIToken,
c.d.Get("sysdig_secure_url").(string),
c.d.Get("sysdig_secure_insecure_tls").(bool),
)
})

Expand Down

0 comments on commit 23b1e07

Please sign in to comment.