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 env var as credential input in cli #1456

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ which is easier if you develop on osc.
When you use osc for the first time, it will ask you for your username and
password, and store it in `~/.config/osc/oscrc`.

Alternatively, you can set the environment variable to bypass the interactive input
session with the OSC_USERNAME as the username, OSC_PASSWORD as the password and
OSC_CREDENTIALMGR as ['Kernel keyring', 'Secret Service', 'Transient', 'Obfuscated',
'Config'] the credentials configuration like the following:

OSC_USERNAME='username'
OSC_PASSWORD='password'
OSC_CREDENTIALMGR='Kernel keyring'


## Keyrings

Expand Down
21 changes: 16 additions & 5 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,10 +1999,14 @@
print()

apiurl_no_scheme = urlsplit(apiurl)[1] or apiurl
user_prompt = f"Username [{apiurl_no_scheme}]: "
user = raw_input(user_prompt)
pass_prompt = f"Password [{user}@{apiurl_no_scheme}]: "
passwd = getpass.getpass(pass_prompt)
user = os.environ.get("OSC_USERNAME", None)
if not user:
user_prompt = f"Username [{apiurl_no_scheme}]: "
user = raw_input(user_prompt)
passwd = os.environ.get("OSC_PASSWORD", None)
if not passwd:
pass_prompt = f"Password [{user}@{apiurl_no_scheme}]: "
passwd = getpass.getpass(pass_prompt)

Check warning on line 2009 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L2002-L2009

Added lines #L2002 - L2009 were not covered by tests
creds_mgr_descr = select_credentials_manager_descr()
if initial:
config = {'user': user, 'pass': passwd}
Expand All @@ -2020,9 +2024,13 @@
print('To use keyrings please install python%d-keyring.' % sys.version_info.major)
creds_mgr_descriptors = credentials.get_credentials_manager_descriptors()

cred = os.environ.get("OSC_CREDENTIALMGR", None)
cred_pick = None

Check warning on line 2028 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L2027-L2028

Added lines #L2027 - L2028 were not covered by tests
rows = []
for i, creds_mgr_descr in enumerate(creds_mgr_descriptors, 1):
rows += [str(i), creds_mgr_descr.name(), creds_mgr_descr.description()]
if creds_mgr_descr.name() == cred:
cred_pick = str(i)

Check warning on line 2033 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L2032-L2033

Added lines #L2032 - L2033 were not covered by tests

from .core import build_table
headline = ('NUM', 'NAME', 'DESCRIPTION')
Expand All @@ -2031,7 +2039,10 @@
for row in table:
print(row)

i = raw_input('Select credentials manager [default=1]: ')
if cred_pick:
i = cred_pick

Check warning on line 2043 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L2042-L2043

Added lines #L2042 - L2043 were not covered by tests
else:
i = raw_input('Select credentials manager [default=1]: ')

Check warning on line 2045 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L2045

Added line #L2045 was not covered by tests
if not i:
i = "1"
if not i.isdigit():
Expand Down
Loading