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 hashes)

Uploaded Python 3

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