Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: add support for get_credential #26

Open
AlexanderLanin opened this issue Feb 10, 2023 · 1 comment
Open

Request: add support for get_credential #26

AlexanderLanin opened this issue Feb 10, 2023 · 1 comment

Comments

@AlexanderLanin
Copy link

AlexanderLanin commented Feb 10, 2023

I'm attempting to store a username and a password for a specific service. As far as I can understand the get_credential function is currently not supported.

Here is my workaround, but I'd like to get rid of it ... ;-)

def _active_backend_name(user_readable=True):
    return f"{keyring.get_keyring().__module__}.{type(keyring.get_keyring()).__name__}"

def _get_credential(service: str):
    if _active_backend_name() == "keyrings.cryptfile.cryptfile.CryptFileKeyring":
        username = keyring.get_password(service, "USERNAME")
        if username:
            password = keyring.get_password(service, username)
            return SimpleCredential(username, password)
        else:
            return None
    else:
        return keyring.get_credential(service, None)


def _keyring_set(service: str, cred: SimpleCredential):
    if _active_backend_name() == "keyrings.cryptfile.cryptfile.CryptFileKeyring":
        keyring.set_password(service, "USERNAME", cred.username)
    keyring.set_password(service, cred.username, cred.password)
@frispete
Copy link
Owner

Hi Alexander,

in general, I'm in for such a change, but I don't have the time to prepare that at the moment.

Would you be so kind to prepare a PR, that implements something like this, while taking the existing class hierarchy and conformance to the predominant code style into account?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants