Skip to content

Commit

Permalink
Honor the PYTHON_KEYRING_BACKEND environment variable to allow an env…
Browse files Browse the repository at this point in the history
…ironment to select a particular keyring. Fixes #340.
  • Loading branch information
jaraco committed Sep 14, 2018
1 parent 9be4525 commit 5a887c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* #340: Add the Null keyring, disabled by default.
* #340: Added ``--disable`` option to command-line
interface.
* #340: Now honor a ``PYTHON_KEYRING_BACKEND``
environment variable to select a backend. Environments
may set to ``keyring.backends.null.Keyring`` to disable
keyring.

15.0.0
------
Expand Down
11 changes: 10 additions & 1 deletion keyring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def init_backend(limit=None):
keyrings = filter(limit, backend.get_all_keyring())

set_keyring(
load_config()
load_env()
or load_config()
or max(keyrings, default=fail.Keyring, key=by_priority)
)

Expand Down Expand Up @@ -128,6 +129,14 @@ def load_keyring(keyring_name):
return class_()


def load_env():
"""Load a keyring configured in the environment variable."""
try:
return load_keyring(os.environ['PYTHON_KEYRING_BACKEND'])
except KeyError:
pass


def load_config():
"""Load a keyring using the config file in the config root."""

Expand Down

0 comments on commit 5a887c1

Please sign in to comment.