Skip to content

Commit 9bcd300

Browse files
committed
Changed Vault secret engine types to constants
1 parent 52be46e commit 9bcd300

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

collector/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ func (c ConnectConfig) GetQueryTimeout() int {
161161
}
162162

163163
func (h HashiCorpVault) GetUsernameAttr() string {
164-
if h.UsernameAttr == "" || h.MountType == "database" {
164+
if h.UsernameAttr == "" || h.MountType == hashivault.MountTypeDatabase {
165165
return "username"
166166
}
167167
return h.UsernameAttr
168168
}
169169

170170
func (h HashiCorpVault) GetPasswordAttr() string {
171-
if h.PasswordAttr == "" || h.MountType == "database" {
171+
if h.PasswordAttr == "" || h.MountType == hashivault.MountTypeDatabase {
172172
return "password"
173173
}
174174
return h.PasswordAttr

hashivault/hashivault.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import (
1717
vault "github.com/hashicorp/vault/api"
1818
)
1919

20+
const (
21+
MountTypeKVv1 = "kvv1"
22+
MountTypeKVv2 = "kvv2"
23+
MountTypeDatabase = "database"
24+
MountTypeLogical = "logical"
25+
)
26+
2027
var UnsupportedMountType = errors.New("Unsupported HashiCorp Vault mount type")
2128
var RequiredKeyMissing = errors.New("Required key missing from HashiCorp Vault secret")
2229

@@ -77,11 +84,11 @@ func (c HashicorpVaultClient) getVaultSecret(mountType string, mount string, pat
7784
result := map[string]string{}
7885
var err error
7986
var secretData map[string]interface{}
80-
if mountType == "kvv2" || mountType == "kvv1" {
87+
if mountType == MountTypeKVv1 || mountType == MountTypeKVv2 {
8188
// Handle simple key-value secrets
8289
var secret *vault.KVSecret
8390
c.logger.Info("Making call to HashiCorp Vault", "mountType", mountType, "mountName", mount, "secretPath", path, "expectedKeys", requiredKeys)
84-
if mountType == "kvv2" {
91+
if mountType == MountTypeKVv2 {
8592
secret, err = c.client.KVv2(mount).Get(context.TODO(), path)
8693
} else {
8794
secret, err = c.client.KVv1(mount).Get(context.TODO(), path)
@@ -91,11 +98,11 @@ func (c HashicorpVaultClient) getVaultSecret(mountType string, mount string, pat
9198
return result, err
9299
}
93100
secretData = secret.Data
94-
} else if mountType == "database" || mountType == "logical" {
101+
} else if mountType == MountTypeDatabase || mountType == MountTypeLogical {
95102
// Handle other types of secrets, for example database roles, just using the Logical() backend
96103
var secret *vault.Secret
97104
var secretPath string
98-
if mountType == "database" {
105+
if mountType == MountTypeDatabase {
99106
secretPath = fmt.Sprintf("%s/creds/%s", mount, path)
100107
} else {
101108
secretPath = fmt.Sprintf("%s/%s", mount, path)

0 commit comments

Comments
 (0)