| |
@@ -31,7 +31,7 @@
|
| |
from textwrap import wrap
|
| |
|
| |
# extra python modules
|
| |
- from bodhi.client.bindings import BodhiClient
|
| |
+ from bodhi.client.bindings import BodhiClient, BodhiClientException
|
| |
import dnf
|
| |
# Used to catch fedora.client.AuthError and fedora.client.ServerError
|
| |
# exceptions
|
| |
@@ -476,13 +476,26 @@
|
| |
fas_username = os.environ["LOGNAME"]
|
| |
self.options.fas_username = fas_username
|
| |
|
| |
- # note that the retry logic in the bodhi client is currently not
|
| |
- # functional
|
| |
- # https://github.com/fedora-infra/python-fedora/issues/144
|
| |
- bc = BodhiClient(username=self.options.fas_username,
|
| |
+ csrf = None
|
| |
+ tried = 0
|
| |
+ while not csrf and tried <= self.options.retries:
|
| |
+ bc = BodhiClient(username=self.options.fas_username,
|
| |
useragent="Fedora Easy Karma/GIT",
|
| |
retries=self.options.retries)
|
| |
+ try:
|
| |
+ csrf = bc.csrf()
|
| |
+ except fedora.client.AuthError as e:
|
| |
+ self.warning("Authentication error for user: %s" % self.options.fas_username)
|
| |
+ tried = tried + 1
|
| |
+ self.options.fas_username = self.input("Username: ", default=self.options.fas_username)
|
| |
+ continue
|
| |
+
|
| |
+ if not csrf:
|
| |
+ self.warning("Too many authentication attempts, exiting!")
|
| |
+ sys.exit(1)
|
| |
+
|
| |
self.bc = bc
|
| |
+
|
| |
# Bodhi is too slow for our queries, therefore wait longer
|
| |
bc.timeout = 300
|
| |
pkghelper = PkgHelper()
|
| |
@@ -656,7 +669,7 @@
|
| |
default=self.options.default_comment)
|
| |
if comment or not self.options.skip_empty_comment:
|
| |
result = self.send_comment(bc, update, comment,
|
| |
- karma)
|
| |
+ karma)
|
| |
if not result[0]:
|
| |
self.warning("Comment not submitted: %s" %
|
| |
result[1])
|
| |
@@ -784,11 +797,16 @@
|
| |
bc.retries = orig_retries
|
| |
return (True, res)
|
| |
except fedora.client.AuthError as e:
|
| |
- self.warning("Authentication error")
|
| |
- bc.password = getpass.getpass('FAS password for %s: ' %
|
| |
- self.options.fas_username)
|
| |
+ return (False, 'Authentication error')
|
| |
except fedora.client.ServerError as e:
|
| |
self.warning("Server error: %s" % str(e))
|
| |
+ except BodhiClientException as e:
|
| |
+ self.warning("Bodhi Client error: %s" % str(e))
|
| |
+ if "csrf" in str(e).lower():
|
| |
+ self.warning("Possible CSRF token mismatch, trying to obtain a new one...")
|
| |
+ bc._session.cookies.clear()
|
| |
+ bc.csrf_token = None
|
| |
+ bc.csrf()
|
| |
|
| |
bc.retries = orig_retries
|
| |
return (False, 'too many errors')
|
| |
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1818453
Move authentication test to an earlier point and won't proceed to fetch updates from bodhi without working credentials.