mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-03 18:16:17 +01:00
Pass apiurl to all auth handlers
Fixes TransientCredentialsManager check when working with multiple apiurls
This commit is contained in:
parent
157d4b79f8
commit
7de13ea597
@ -260,9 +260,9 @@ def http_request(method, url, headers=None, data=None, file=None):
|
|||||||
CONNECTION_POOLS[apiurl] = pool
|
CONNECTION_POOLS[apiurl] = pool
|
||||||
|
|
||||||
auth_handlers = [
|
auth_handlers = [
|
||||||
CookieJarAuthHandler(os.path.expanduser(conf.config["cookiejar"])),
|
CookieJarAuthHandler(apiurl, os.path.expanduser(conf.config["cookiejar"])),
|
||||||
SignatureAuthHandler(options["user"], options["sshkey"], options["pass"]),
|
SignatureAuthHandler(apiurl, options["user"], options["sshkey"], options["pass"]),
|
||||||
BasicAuthHandler(options["user"], options["pass"]),
|
BasicAuthHandler(apiurl, options["user"], options["pass"]),
|
||||||
]
|
]
|
||||||
|
|
||||||
for handler in auth_handlers:
|
for handler in auth_handlers:
|
||||||
@ -371,6 +371,9 @@ def http_DELETE(*args, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
class AuthHandlerBase:
|
class AuthHandlerBase:
|
||||||
|
def __init__(self, apiurl):
|
||||||
|
self.apiurl = apiurl
|
||||||
|
|
||||||
def _get_auth_schemes(self, response):
|
def _get_auth_schemes(self, response):
|
||||||
"""
|
"""
|
||||||
Extract all `www-authenticate` headers from `response` and return them
|
Extract all `www-authenticate` headers from `response` and return them
|
||||||
@ -426,7 +429,8 @@ class CookieJarAuthHandler(AuthHandlerBase):
|
|||||||
# Shared among instances, instantiate on first use, key equals to cookiejar path.
|
# Shared among instances, instantiate on first use, key equals to cookiejar path.
|
||||||
COOKIEJARS = {}
|
COOKIEJARS = {}
|
||||||
|
|
||||||
def __init__(self, cookiejar_path):
|
def __init__(self, apiurl, cookiejar_path):
|
||||||
|
super().__init__(apiurl)
|
||||||
self.cookiejar_path = cookiejar_path
|
self.cookiejar_path = cookiejar_path
|
||||||
if self.cookiejar_path in self.COOKIEJARS:
|
if self.cookiejar_path in self.COOKIEJARS:
|
||||||
self.cookiejar_lock_path = None
|
self.cookiejar_lock_path = None
|
||||||
@ -487,7 +491,8 @@ class CookieJarAuthHandler(AuthHandlerBase):
|
|||||||
|
|
||||||
|
|
||||||
class BasicAuthHandler(AuthHandlerBase):
|
class BasicAuthHandler(AuthHandlerBase):
|
||||||
def __init__(self, user, password):
|
def __init__(self, apiurl, user, password):
|
||||||
|
super().__init__(apiurl)
|
||||||
self.user = user
|
self.user = user
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
@ -508,15 +513,16 @@ class BasicAuthHandler(AuthHandlerBase):
|
|||||||
|
|
||||||
|
|
||||||
class SignatureAuthHandler(AuthHandlerBase):
|
class SignatureAuthHandler(AuthHandlerBase):
|
||||||
def __init__(self, user, sshkey, basic_auth_password=None):
|
def __init__(self, apiurl, user, sshkey, basic_auth_password=None):
|
||||||
|
super().__init__(apiurl)
|
||||||
self.user = user
|
self.user = user
|
||||||
self.sshkey = sshkey
|
self.sshkey = sshkey
|
||||||
|
|
||||||
self.ssh_keygen_path = shutil.which("ssh-keygen")
|
self.ssh_keygen_path = shutil.which("ssh-keygen")
|
||||||
self.ssh_add_path = shutil.which("ssh-add")
|
self.ssh_add_path = shutil.which("ssh-add")
|
||||||
|
|
||||||
apiurl = conf.config["apiurl"]
|
creds_mgr = conf.config["api_host_options"][self.apiurl].get("credentials_mgr_class", None)
|
||||||
if conf.config["api_host_options"][apiurl].get("credentials_mgr_class", None) == "osc.credentials.TransientCredentialsManager":
|
if creds_mgr == "osc.credentials.TransientCredentialsManager":
|
||||||
self.basic_auth_password = False
|
self.basic_auth_password = False
|
||||||
else:
|
else:
|
||||||
# value of `basic_auth_password` is only used as a hint if we should skip signature auth
|
# value of `basic_auth_password` is only used as a hint if we should skip signature auth
|
||||||
|
Loading…
Reference in New Issue
Block a user