Honour --force-auth for anonymous commands
Fixes: https://pagure.io/koji/issue/2657
This commit is contained in:
parent
1269317618
commit
5d86608931
7 changed files with 30 additions and 16 deletions
|
|
@ -1793,6 +1793,7 @@ def handle_prune_signed_copies(goptions, session, args):
|
|||
cutoff_ts = time.time() - options.days * 24 * 3600
|
||||
if options.debug:
|
||||
print("Cutoff date: %s" % time.asctime(time.localtime(cutoff_ts)))
|
||||
activate_session(session, goptions)
|
||||
if not options.build:
|
||||
if options.verbose:
|
||||
print("Getting builds...")
|
||||
|
|
@ -2145,11 +2146,12 @@ def handle_add_volume(goptions, session, args):
|
|||
print("Added volume %(name)s with id %(id)i" % volinfo)
|
||||
|
||||
|
||||
def handle_list_volumes(options, session, args):
|
||||
def anon_handle_list_volumes(options, session, args):
|
||||
"[info] List storage volumes"
|
||||
usage = _("usage: %prog list-volumes")
|
||||
parser = OptionParser(usage=get_usage_str(usage))
|
||||
(options, args) = parser.parse_args(args)
|
||||
ensure_connection(session, options)
|
||||
for volinfo in session.listVolumes():
|
||||
print(volinfo['name'])
|
||||
|
||||
|
|
@ -7265,6 +7267,7 @@ def anon_handle_download_logs(options, session, args):
|
|||
for child_task in child_tasks:
|
||||
save_logs(child_task['id'], match, task_log_dir, recurse)
|
||||
|
||||
ensure_connection(session, options)
|
||||
for arg in args:
|
||||
if suboptions.nvr:
|
||||
suboptions.recurse = True
|
||||
|
|
@ -7413,6 +7416,7 @@ def anon_handle_wait_repo(options, session, args):
|
|||
|
||||
tag = args[0]
|
||||
|
||||
ensure_connection(session, options)
|
||||
if suboptions.target:
|
||||
target_info = session.getBuildTarget(tag)
|
||||
if not target_info:
|
||||
|
|
@ -7707,6 +7711,7 @@ def anon_handle_search(options, session, args):
|
|||
matchType = 'regexp'
|
||||
elif options.exact:
|
||||
matchType = 'exact'
|
||||
ensure_connection(session, options)
|
||||
data = session.search(pattern, type, matchType)
|
||||
for row in data:
|
||||
print(row['name'])
|
||||
|
|
|
|||
|
|
@ -136,6 +136,10 @@ def get_usage_str(usage):
|
|||
|
||||
|
||||
def ensure_connection(session, options=None):
|
||||
if options and options.force_auth:
|
||||
# in such case we should act as a real activate_session
|
||||
activate_session(session, options)
|
||||
return
|
||||
try:
|
||||
ret = session.getAPIVersion()
|
||||
except requests.exceptions.ConnectionError as ex:
|
||||
|
|
@ -751,6 +755,8 @@ def activate_session(session, options):
|
|||
warn(_("Could not connect to Kerberos authentication service: %s") % e.args[1])
|
||||
if not noauth and not session.logged_in:
|
||||
error(_("Unable to log in, no authentication methods available"))
|
||||
# don't add "options" to ensure_connection it would create loop in case of --force-auth
|
||||
# when it calls activate_session
|
||||
ensure_connection(session)
|
||||
if getattr(options, 'debug', None):
|
||||
print("successfully connected to hub")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue