From 93e477ed620f32d79daf155e696dc9f306cf1ddc Mon Sep 17 00:00:00 2001
From: Pavel Vorobyov
Date: Mon, 18 Nov 2019 16:09:02 +0300
Subject: [PATCH] insecure mode inventory backend
---
backend/inventoree/inventoree.go | 25 +++++++++++++++++++++++++
backend/inventoree/types.go | 1 +
2 files changed, 26 insertions(+)
diff --git a/backend/inventoree/inventoree.go b/backend/inventoree/inventoree.go
index b2a8a0b..1d3c98e 100644
--- a/backend/inventoree/inventoree.go
+++ b/backend/inventoree/inventoree.go
@@ -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 {
diff --git a/backend/inventoree/types.go b/backend/inventoree/types.go
index 4d47030..d00a267 100644
--- a/backend/inventoree/types.go
+++ b/backend/inventoree/types.go
@@ -13,6 +13,7 @@ type Inventoree struct {
cacheDir string
url string
authToken string
+ insecure bool
hosts []*store.Host
groups []*store.Group
workgroups []*store.WorkGroup