Skip to main content

Simple library to interact with Git Credentials

Project description

Simple small library to provide an interface around the git credential Git command. No dependencies but git must in the PATH.

Example

from git_credentials import GitCredentials, GitCredentialDescription, GitCredentialError, GitCredentialNotStoredError

def test_creds(user, pw):
    ...

def ask_for_creds():
    ...

cred = GitCredentials("/path/to/repo")

try:
    response = cred.fill(GitCredentialDescription(
        protocol="https",
        host="example.com",
        path="/"
    ))
    print(f"Request was successful. Host: {response.host}, User: {response.username}, Password: {response.password}")
    # Test the credentials
    if test_creds(response.username, response.password):
        # Tell Git the credentials are good.
        cred.approve(response)
    else:
        # Otherwise tell it to reject them.
        cred.reject(response)
except GitCredentialNotStoredError:
    print("Did not know the PW :(")
    # Ask user for PW. You can store it then (after testing it) using approve:
    (user, pw) = ask_for_creds()
    if test_creds(user, pw):
        # Tell Git the credentials are good.
        cred.approve(GitCredentialDescription(
            protocol="https",
            host="example.com",
            path="/",
            username=user,
            password=pw
        ))
except GitCredentialError:
    # Another misc. error. GitCredentialNotStoredError subclasses this.
    raise

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

git_credentials-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file git_credentials-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: git_credentials-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for git_credentials-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38440ad0e84f53e6b0eacc1c46e3ee84d5e6daff4353ffc8ee0c2e3e770f4891
MD5 b09bd20db63a94ddf1f0a7337651bd1e
BLAKE2b-256 13801c84474607459f314fe8f9390e6793f81b1cf7c78b6d9d2aa41befdb19b6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page