1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00

Merge pull request #1298 from dmach/fix-interactive-config-setup

Fix interactive config setup
This commit is contained in:
Daniel Mach 2023-04-11 13:41:59 +02:00 committed by GitHub
commit 1a9d973bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 13 deletions

View File

@ -397,17 +397,33 @@ class OscMainCommand(MainCommand):
# let's leave setting the right value to conf.get_config()
pass
conf.get_config(
override_apiurl=args.apiurl,
override_conffile=args.conffile,
override_debug=args.debug,
override_http_debug=args.http_debug,
override_http_full_debug=args.http_full_debug,
override_no_keyring=args.no_keyring,
override_post_mortem=args.post_mortem,
override_traceback=args.traceback,
override_verbose=args.verbose,
)
try:
conf.get_config(
override_apiurl=args.apiurl,
override_conffile=args.conffile,
override_debug=args.debug,
override_http_debug=args.http_debug,
override_http_full_debug=args.http_full_debug,
override_no_keyring=args.no_keyring,
override_post_mortem=args.post_mortem,
override_traceback=args.traceback,
override_verbose=args.verbose,
)
except oscerr.NoConfigfile as e:
print(e.msg, file=sys.stderr)
print(f"Creating osc configuration file {e.file} ...", file=sys.stderr)
conf.interactive_config_setup(e.file, args.apiurl)
print("done", file=sys.stderr)
self.post_parse_args(args)
except oscerr.ConfigMissingApiurl as e:
print(e.msg, file=sys.stderr)
conf.interactive_config_setup(e.file, e.url, initial=False)
self.post_parse_args(args)
except oscerr.ConfigMissingCredentialsError as e:
print(e.msg, file=sys.stderr)
print("Please enter new credentials.", file=sys.stderr)
conf.interactive_config_setup(e.file, e.url, initial=False)
self.post_parse_args(args)
# write config values back to args
# this is crucial mainly for apiurl to resolve an alias to full url

View File

@ -972,6 +972,9 @@ def identify_conf():
def interactive_config_setup(conffile, apiurl, initial=True):
if not apiurl:
apiurl = DEFAULTS["apiurl"]
scheme = urlsplit(apiurl)[0]
http = scheme == "http"
if http:
@ -984,8 +987,11 @@ def interactive_config_setup(conffile, apiurl, initial=True):
raise oscerr.UserAbort()
print()
user = raw_input('Username: ')
passwd = getpass.getpass()
apiurl_no_scheme = urlsplit(apiurl)[1]
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)
creds_mgr_descr = select_credentials_manager_descr()
if initial:
config = {'user': user, 'pass': passwd}