insecure mode inventory backend

This commit is contained in:
Pavel Vorobyov
2019-11-18 16:09:02 +03:00
parent 4177ed91a1
commit 93e477ed62
2 changed files with 26 additions and 0 deletions

View File

@@ -1,6 +1,8 @@
package inventoree
import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
@@ -36,6 +38,18 @@ func New(cfg *config.XCConfig) (*Inventoree, error) {
return nil, fmt.Errorf("Inventoree backend URL is not configured")
}
// insecure configuration
insec, found := options["insecure"]
if !found {
insec = "false"
}
insecure := false
if insec == "true" || insec == "yes" || insec == "1" {
insecure = true
term.Warnf("WARNING: Inventory backend will be accessed in insecure mode\n")
}
// auth configuration
authToken, found := options["auth_token"]
if !found {
@@ -48,6 +62,7 @@ func New(cfg *config.XCConfig) (*Inventoree, error) {
cacheDir: cfg.CacheDir,
url: url,
authToken: authToken,
insecure: insecure,
}, nil
}
@@ -100,6 +115,16 @@ func (i *Inventoree) Load() error {
func (i *Inventoree) inventoreeGet(path string) ([]byte, error) {
client := &http.Client{}
if i.insecure {
rootCAs, _ := x509.SystemCertPool()
tlsconf := &tls.Config{
InsecureSkipVerify: true,
RootCAs: rootCAs,
}
transport := &http.Transport{TLSClientConfig: tlsconf}
client.Transport = transport
}
url := fmt.Sprintf("%s%s", i.url, path)
req, err := http.NewRequest("GET", url, nil)
if err != nil {

View File

@@ -13,6 +13,7 @@ type Inventoree struct {
cacheDir string
url string
authToken string
insecure bool
hosts []*store.Host
groups []*store.Group
workgroups []*store.WorkGroup