Commit e98b628f by Őry Máté

store: refactor get_request_arguments

parent 7f451e3e
...@@ -19,22 +19,14 @@ def get_host(): ...@@ -19,22 +19,14 @@ def get_host():
return settings.STORE_URL return settings.STORE_URL
def get_request_arguments(ssl_auth, basic_auth): def get_request_arguments():
args = { args = {'verify': settings.STORE_VERIFY_SSL}
'verify': settings.STORE_VERIFY_SSL,
'cert': (settings.STORE_CLIENT_CERT, settings.STORE_CLIENT_KEY), if settings.STORE_SSL_AUTH:
'auth': (settings.STORE_CLIENT_USER, settings.STORE_CLIENT_PASSWORD), args['cert'] = (settings.STORE_CLIENT_CERT, settings.STORE_CLIENT_KEY)
} if settings.STORE_BASIC_AUTH:
if ssl_auth and basic_auth: args['auth'] = (settings.STORE_CLIENT_USER,
pass settings.STORE_CLIENT_PASSWORD)
elif ssl_auth:
del args['auth']
elif basic_auth:
del args['cert']
else:
del args['cert']
del args['auth']
return args return args
...@@ -42,8 +34,7 @@ def post_request(url, payload, timeout=None): ...@@ -42,8 +34,7 @@ def post_request(url, payload, timeout=None):
try: try:
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
r = requests.post(url, data=payload, headers=headers, timeout=timeout, r = requests.post(url, data=payload, headers=headers, timeout=timeout,
**get_request_arguments(settings.STORE_SSL_AUTH, **get_request_arguments())
settings.STORE_BASIC_AUTH))
return r return r
except Exception as e: except Exception as e:
logger.error("Error in store POST: %s" % e) logger.error("Error in store POST: %s" % e)
...@@ -57,8 +48,7 @@ def get_request(url, timeout=None): ...@@ -57,8 +48,7 @@ def get_request(url, timeout=None):
try: try:
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
r = requests.get(url, headers=headers, timeout=timeout, r = requests.get(url, headers=headers, timeout=timeout,
**get_request_arguments(settings.STORE_SSL_AUTH, **get_request_arguments())
settings.STORE_BASIC_AUTH))
return r return r
except Exception as e: except Exception as e:
logger.error("Error in store GET: %s" % e) logger.error("Error in store GET: %s" % e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment