Add InsecureSkipVerify functionality.

This commit is contained in:
Kalle Carlbark 2019-09-11 09:38:29 +02:00
parent 79ae6869a7
commit 62df6ed37f
No known key found for this signature in database
GPG key ID: 3FC0C93C5A5A0670
2 changed files with 11 additions and 4 deletions

View file

@ -1,13 +1,15 @@
package nbclient package nbclient
type NetBox struct { type NetBox struct {
RootURL string RootURL string
Token string Token string
InsecureSkipVerify bool
} }
func (n *NetBox) New(root, token string) error { func (n *NetBox) New(root, token string, TlsSkipVerify bool) error {
n.RootURL = root n.RootURL = root
n.Token = token n.Token = token
n.InsecureSkipVerify = TlsSkipVerify
return nil return nil
} }

View file

@ -2,6 +2,7 @@ package nbclient
import ( import (
"bytes" "bytes"
"crypto/tls"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -85,9 +86,13 @@ func (i *Dcim_Interfaces_Create) CreateInterface(n *NetBox) error {
if err != nil { if err != nil {
return err return err
} }
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: n.InsecureSkipVerify},
}
timeout := time.Duration(60 * time.Second) timeout := time.Duration(60 * time.Second)
client := &http.Client{ client := &http.Client{
Timeout: timeout, Timeout: timeout,
Transport: transport,
} }
request, err := http.NewRequest("POST", n.RootURL+"/dcim/interfaces/", bytes.NewBuffer(interfaceData)) request, err := http.NewRequest("POST", n.RootURL+"/dcim/interfaces/", bytes.NewBuffer(interfaceData))
if err != nil { if err != nil {