/
credentials_secret.go
40 lines (35 loc) · 1.05 KB
/
credentials_secret.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
package credentials
import (
"fmt"
)
// SecretTextCredentials represents credentials composed of a single string value
type SecretTextCredentials struct {
Base `mapstructure:",squash"`
Secret string
}
// NewSecretText instantiates a SecretTextCredentials struct
func NewSecretText() *SecretTextCredentials {
cred := &SecretTextCredentials{}
cred.CredType = "Secret text"
return cred
}
// ToString prints out the content of a SecretTextCredentials struct.
// If showSensitive is true, the secret text will be shown
func (cred *SecretTextCredentials) ToString(showSensitive bool) string {
secretText := "********"
if showSensitive {
secretText = cred.Secret
}
if secretText == "" {
secretText = "<empty>"
}
return fmt.Sprintf("%s - %s", cred.BaseToString(), secretText)
}
// Validate verifies that the credentials is valid.
// A SecretTextCredentials is always considered valid, as empty values are accepted.
func (cred *SecretTextCredentials) Validate() error {
if cred.Secret == "" && cred.Value != "" {
cred.Secret = cred.Value
}
return nil
}