-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
59 lines (45 loc) · 1.46 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package provider
import (
"fmt"
"time"
"github.com/hashicorp/go-hclog"
cloud "github.com/hashicorp/hcp-sdk-go/clients/cloud-shared/v1/models"
sdk "github.com/hashicorp/hcp-sdk-go/config"
"github.com/hashicorp/hcp-scada-provider/internal/resource"
)
// Config is used to parameterize a provider
type Config struct {
// Service is the name to identify the client.
Service string
// Resource contains information about the Resource the provider will
// register as.
Resource cloud.HashicorpCloudLocationLink
// HCPConfig is the HCP specific configuration, it provides information
// necessary to talk to HCP APIs.
HCPConfig sdk.HCPConfig
// Logger is the Logger to use for logs.
Logger hclog.Logger
// TestBackoff is used to force the provider to retry more aggressively.
TestBackoff time.Duration
}
func (c *Config) Validate() error {
if c == nil {
return fmt.Errorf("failed to initialize SCADA provider: missing config")
}
if c.Service == "" {
return fmt.Errorf("failed to initialize SCADA provider: missing Service")
}
err := resource.Validate(c.Resource)
if err != nil {
return fmt.Errorf("failed to initialize SCADA provider: %w", err)
}
if c.HCPConfig == nil {
return fmt.Errorf("failed to initialize SCADA provider: HCPConfig must be provided")
}
if c.Logger == nil {
return fmt.Errorf("failed to initialize SCADA provider: Logger must be provided")
}
return nil
}