feat(credential): Add specific credential types (#1525)

This adds interfaces for the following credential types:
- Username and password
- Username and private key
- Certificate and private key

It also adds the following types for redacting secret data:
- Password
- PrivateKey
This commit is contained in:
Michael Gaffney authored and GitHub committed 2021-09-14 14:11:42 -04:00
1 parent 2afac7348a
commit e9d3cebd45
3 files changed
+199

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
package credential
import "encoding/json"
const (
redactedPassword = "[REDACTED: password]"
redactedPrivateKey = "[REDACTED: private key]"
)
// String returns a string with the password redacted.
func (s Password) String() string {
return redactedPassword
}
// GoString returns a string with the password redacted.
func (s Password) GoString() string {
return redactedPassword
}
// MarshalJSON returns a JSON-encoded string with the password redacted.
func (s Password) MarshalJSON() ([]byte, error) {
return json.Marshal(redactedPassword)
}
// String returns a string with the private key redacted.
func (s PrivateKey) String() string {
return redactedPrivateKey
}
// GoString returns a string with the private key redacted.
func (s PrivateKey) GoString() string {
return redactedPrivateKey
}
// MarshalJSON returns a JSON-encoded byte slice with the private key
// redacted.
func (s PrivateKey) MarshalJSON() ([]byte, error) {
return json.Marshal([]byte(redactedPrivateKey))
}