diff options
| author | lhchavez <[email protected]> | 2021-09-05 16:39:07 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-05 16:39:07 -0700 |
| commit | b983e1daebf528443e2a3954cd595fa3664ec93f (patch) | |
| tree | 51ed7f7c359c9548dad7afa1a445749380d59f66 /credentials.go | |
| parent | f1fa96c7b7f548389c7560d3a1a0bce83be56c9f (diff) | |
Add support for managed HTTP/S transports (#810)
This change uses the newly-exposed Transport interface to use Go's
implementation of http.Client instead of httpclient via libgit2.
Diffstat (limited to 'credentials.go')
| -rw-r--r-- | credentials.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/credentials.go b/credentials.go index 843c6b2..273de2f 100644 --- a/credentials.go +++ b/credentials.go @@ -11,6 +11,7 @@ void _go_git_populate_credential_ssh_custom(git_credential_ssh_custom *cred); import "C" import ( "crypto/rand" + "errors" "fmt" "runtime" "strings" @@ -106,6 +107,19 @@ func (o *Credential) Free() { o.ptr = nil } +// GetUserpassPlaintext returns the plaintext username/password combination stored in the Cred. +func (o *Credential) GetUserpassPlaintext() (username, password string, err error) { + if o.Type() != CredentialTypeUserpassPlaintext { + err = errors.New("credential is not userpass plaintext") + return + } + + plaintextCredPtr := (*C.git_cred_userpass_plaintext)(unsafe.Pointer(o.ptr)) + username = C.GoString(plaintextCredPtr.username) + password = C.GoString(plaintextCredPtr.password) + return +} + func NewCredentialUsername(username string) (*Credential, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() |
