Skip to content

Commit

Permalink
Merge pull request #549 from wwuck/feature/eq
Browse files Browse the repository at this point in the history
Add equality operator to EnvironCredential
  • Loading branch information
jaraco committed Nov 28, 2021
2 parents c63ab7d + b3f9f2c commit 0f0faf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit 0f0faf1

Please sign in to comment.