Merge pull request #4 from networkop/main

provider.go golines -m 70
main
Nicolas Leiva 2022-05-05 04:33:16 -04:00 committed by GitHub
commit 3cda167c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 11 deletions

View File

@ -33,16 +33,22 @@ func New(version string) func() *schema.Provider {
"url": { "url": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
DefaultFunc: schema.EnvDefaultFunc("NAUTOBOT_URL", nil), DefaultFunc: schema.EnvDefaultFunc(
"NAUTOBOT_URL",
nil,
),
ValidateFunc: validation.IsURLWithHTTPorHTTPS, ValidateFunc: validation.IsURLWithHTTPorHTTPS,
Description: "URL for the Nautobot API platform. It should be of the form https:///server.example.org/api/.", Description: "Nautobot API URL",
}, },
"token": { "token": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
Sensitive: true, Sensitive: true,
DefaultFunc: schema.EnvDefaultFunc("NAUTOBOT_TOKEN", nil), DefaultFunc: schema.EnvDefaultFunc(
Description: "Customer/user-specific authorization API token for Nautobot.", "NAUTOBOT_TOKEN",
nil,
),
Description: "Admin API token",
}, },
}, },
DataSourcesMap: map[string]*schema.Resource{ DataSourcesMap: map[string]*schema.Resource{
@ -67,7 +73,10 @@ type apiClient struct {
Server string Server string
} }
func configure(version string, p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { func configure(
version string,
p *schema.Provider,
) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) { return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
serverURL := d.Get("url").(string) serverURL := d.Get("url").(string)
_, hasToken := d.GetOk("token") _, hasToken := d.GetOk("token")
@ -80,7 +89,9 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema
return &apiClient{Server: serverURL}, diags return &apiClient{Server: serverURL}, diags
} }
token, _ := NewSecurityProviderNautobotToken(d.Get("token").(string)) token, _ := NewSecurityProviderNautobotToken(
d.Get("token").(string),
)
c, err := nb.NewClientWithResponses( c, err := nb.NewClientWithResponses(
serverURL, serverURL,