From 827cdeb4e91901ee4a02ab3feb3260b6ba49e08b Mon Sep 17 00:00:00 2001 From: smutel Date: Wed, 10 Mar 2021 20:30:08 +0100 Subject: [PATCH] feat: Add TLS insecure option --- docs/index.md | 1 + netbox/provider.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index ddf462723..354e77e52 100644 --- a/docs/index.md +++ b/docs/index.md @@ -31,3 +31,4 @@ provider netbox { * `basepath` or `NETBOX_BASEPATH` environment variable to define the base path (/api) * `token` or `NETBOX_TOKEN` environment variable to define the TOKEN to access the application (empty by default) * `scheme` or `NETBOX_SCHEME` environment variable to define the SCHEME of the URL (https by default) +* `insecure` or `NETBOX_INSECURE` environment variable to skip or not the TLS certificat validation (false by default) diff --git a/netbox/provider.go b/netbox/provider.go index ae8d01604..97c809fba 100644 --- a/netbox/provider.go +++ b/netbox/provider.go @@ -38,7 +38,13 @@ func Provider() *schema.Provider { Type: schema.TypeString, Optional: true, DefaultFunc: schema.EnvDefaultFunc("NETBOX_SCHEME", "https"), - Description: "Sheme used to reach netbox application.", + Description: "Scheme used to reach netbox application.", + }, + "insecure": { + Type: schema.TypeBool, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("NETBOX_INSECURE", false), + Description: "Skip TLS certificate validation.", }, }, DataSourcesMap: map[string]*schema.Resource{ @@ -142,11 +148,18 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) { basepath := d.Get("basepath").(string) token := d.Get("token").(string) scheme := d.Get("scheme").(string) + insecure := d.Get("insecure").(bool) defaultScheme := []string{scheme} - t := runtimeclient.New(url, basepath, defaultScheme) + var options runtimeclient.TLSClientOptions + options.InsecureSkipVerify = insecure + + clientWithTLSOptions, _ := runtimeclient.TLSClient(options) + + t := runtimeclient.NewWithClient(url, basepath, defaultScheme, clientWithTLSOptions) t.DefaultAuthentication = runtimeclient.APIKeyAuth(authHeaderName, "header", fmt.Sprintf(authHeaderFormat, token)) + return client.New(t, strfmt.Default), nil }