Skip to content

Commit

Permalink
feat: Allow a configurable basepath
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobstr committed Mar 11, 2021
1 parent e38cc5e commit 7392901
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ provider netbox {
# Environment variable NETBOX_URL
url = "127.0.0.1:8000"
# Environment variable NETBOX_BASEPATH
basepath = "/api"
# Environment variable NETBOX_TOKEN
token = "c07a2db4adb8b1e7f75e7c4369964e92f7680512"
Expand All @@ -25,5 +28,6 @@ provider netbox {
## Argument Reference

* `url` or `NETBOX_URL` environment variable to define the URL and the port (127.0.0.1:8000 by default)
* `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)
9 changes: 8 additions & 1 deletion netbox/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func Provider() *schema.Provider {
DefaultFunc: schema.EnvDefaultFunc("NETBOX_URL", "127.0.0.1:8000"),
Description: "URL to reach netbox application.",
},
"basepath": {
Type: schema.TypeString,
Required: false,
DefaultFunc: schema.EnvDefaultFunc("NETBOX_BASEPATH", client.DefaultBasePath),
Description: "URL path to the netbox API.",
},
"token": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -133,12 +139,13 @@ func Provider() *schema.Provider {

func configureProvider(d *schema.ResourceData) (interface{}, error) {
url := d.Get("url").(string)
basepath := d.Get("basepath").(string)
token := d.Get("token").(string)
scheme := d.Get("scheme").(string)

defaultScheme := []string{scheme}

t := runtimeclient.New(url, client.DefaultBasePath, defaultScheme)
t := runtimeclient.New(url, basepath, defaultScheme)
t.DefaultAuthentication = runtimeclient.APIKeyAuth(authHeaderName, "header",
fmt.Sprintf(authHeaderFormat, token))
return client.New(t, strfmt.Default), nil
Expand Down

0 comments on commit 7392901

Please sign in to comment.