provider.go golines -m 70
parent
7f2f09d9a5
commit
f16dee1cd5
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue