MCPcopy Create free account
hub / github.com/libgit2/pygit2 / get_credentials

Function get_credentials

pygit2/callbacks.py:675–729  ·  view source on GitHub ↗

Call fn and return the credentials object.

(fn, url, username, allowed)

Source from the content-addressed store, hash-verified

673
674
675def get_credentials(fn, url, username, allowed):
676 """Call fn and return the credentials object."""
677 url_str = maybe_string(url)
678 username_str = maybe_string(username)
679
680 creds = fn(url_str, username_str, allowed)
681
682 credential_type = getattr(creds, 'credential_type', None)
683 credential_tuple = getattr(creds, 'credential_tuple', None)
684 if not credential_type or not credential_tuple:
685 raise TypeError('credential does not implement interface')
686
687 cred_type = credential_type
688
689 if not (allowed & cred_type):
690 raise TypeError('invalid credential type')
691
692 ccred = ffi.new('git_credential **')
693 if cred_type == CredentialType.USERPASS_PLAINTEXT:
694 name, passwd = credential_tuple
695 err = C.git_credential_userpass_plaintext_new(
696 ccred, to_bytes(name), to_bytes(passwd)
697 )
698
699 elif cred_type == CredentialType.SSH_KEY:
700 name, pubkey, privkey, passphrase = credential_tuple
701 name = to_bytes(name)
702 if pubkey is None and privkey is None:
703 err = C.git_credential_ssh_key_from_agent(ccred, name)
704 else:
705 err = C.git_credential_ssh_key_new(
706 ccred, name, to_bytes(pubkey), to_bytes(privkey), to_bytes(passphrase)
707 )
708
709 elif cred_type == CredentialType.USERNAME:
710 (name,) = credential_tuple
711 err = C.git_credential_username_new(ccred, to_bytes(name))
712
713 elif cred_type == CredentialType.SSH_MEMORY:
714 name, pubkey, privkey, passphrase = credential_tuple
715 if pubkey is None and privkey is None:
716 raise TypeError('SSH keys from memory are empty')
717 err = C.git_credential_ssh_key_memory_new(
718 ccred,
719 to_bytes(name),
720 to_bytes(pubkey),
721 to_bytes(privkey),
722 to_bytes(passphrase),
723 )
724 else:
725 raise TypeError('unsupported credential type')
726
727 check_error(err)
728
729 return ccred
730
731
732#

Callers 1

_credentials_cbFunction · 0.85

Calls 3

maybe_stringFunction · 0.85
to_bytesFunction · 0.85
check_errorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…