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

Add equality operator to EnvironCredential #549

Merged
merged 4 commits into from Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,9 @@
v23.4.0
-------

* #549: EnvironCredential now allows for equality
comparison.

v23.3.0
-------

Expand Down
17 changes: 16 additions & 1 deletion keyring/credentials.py
Expand Up @@ -31,14 +31,29 @@ def password(self):


class EnvironCredential(Credential):
"""Source credentials from environment variables.
"""
Source credentials from environment variables.

Actual sourcing is deferred until requested.

Supports comparison by equality.

>>> e1 = EnvironCredential('a', 'b')
>>> e2 = EnvironCredential('a', 'b')
>>> e3 = EnvironCredential('a', 'c')
>>> e1 == e2
True
>>> e2 == e3
False
"""

def __init__(self, user_env_var, pwd_env_var):
self.user_env_var = user_env_var
self.pwd_env_var = pwd_env_var

def __eq__(self, other: object) -> bool:
return vars(self) == vars(other)

def _get_env(self, env_var):
"""Helper to read an environment variable"""
value = os.environ.get(env_var)
Expand Down