-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
55 lines (44 loc) · 1.08 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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package gcpkms
import (
"strings"
"github.com/hashicorp/go-secure-stdlib/strutil"
"github.com/hashicorp/vault/sdk/framework"
)
const (
defaultScope = "https://www.googleapis.com/auth/cloudkms"
)
// Config is the stored configuration.
type Config struct {
Credentials string `json:"credentials"`
Scopes []string `json:"scopes"`
}
// DefaultConfig returns a config with the default values.
func DefaultConfig() *Config {
return &Config{
Scopes: []string{defaultScope},
}
}
// Update updates the configuration from the given field data.
func (c *Config) Update(d *framework.FieldData) (bool, error) {
if d == nil {
return false, nil
}
changed := false
if v, ok := d.GetOk("credentials"); ok {
nv := strings.TrimSpace(v.(string))
if nv != c.Credentials {
c.Credentials = nv
changed = true
}
}
if v, ok := d.GetOk("scopes"); ok {
nv := strutil.RemoveDuplicates(v.([]string), true)
if !strutil.EquivalentSlices(nv, c.Scopes) {
c.Scopes = nv
changed = true
}
}
return changed, nil
}