Skip to content

Commit

Permalink
feat: Add TLS insecure option
Browse files Browse the repository at this point in the history
  • Loading branch information
smutel committed Apr 8, 2021
1 parent 77d74b5 commit 827cdeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 15 additions & 2 deletions netbox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}

0 comments on commit 827cdeb

Please sign in to comment.