Commit d0ca16b3 by Kálmán Viktor

dashboard: add timeout for certain store function

parent b66c1174
...@@ -17,7 +17,7 @@ def get_host(): ...@@ -17,7 +17,7 @@ def get_host():
return settings['store_url'] return settings['store_url']
def post_request(url, payload): def post_request(url, payload, timeout=None):
try: try:
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
if settings['ssl_auth'] == 'True' and settings['basic_auth'] == 'True': if settings['ssl_auth'] == 'True' and settings['basic_auth'] == 'True':
...@@ -26,24 +26,27 @@ def post_request(url, payload): ...@@ -26,24 +26,27 @@ def post_request(url, payload):
cert=(settings['store_client_cert'], cert=(settings['store_client_cert'],
settings['store_client_key']), settings['store_client_key']),
auth=(settings['store_client_user'], auth=(settings['store_client_user'],
settings['store_client_pass']) settings['store_client_pass']),
timeout=timeout,
) )
elif settings['ssl_auth'] == 'True': elif settings['ssl_auth'] == 'True':
r = requests.post(url, data=payload, headers=headers, r = requests.post(url, data=payload, headers=headers,
verify=settings['verify_ssl'] == 'True', verify=settings['verify_ssl'] == 'True',
cert=(settings['store_client_cert'], cert=(settings['store_client_cert'],
settings['store_client_key']) settings['store_client_key']),
timeout=timeout,
) )
elif settings['basic_auth'] == 'True': elif settings['basic_auth'] == 'True':
r = requests.post(url, data=payload, headers=headers, r = requests.post(url, data=payload, headers=headers,
verify=settings['verify_ssl'] == 'True', verify=settings['verify_ssl'] == 'True',
auth=(settings['store_client_user'], auth=(settings['store_client_user'],
settings['store_client_pass']) settings['store_client_pass']),
timeout=timeout,
) )
else: else:
r = requests.post(url, data=payload, headers=headers, r = requests.post(url, data=payload, headers=headers,
verify=settings['verify_ssl'] == 'True' verify=settings['verify_ssl'] == 'True',
) timeout=timeout)
return r return r
except: except:
dummy = Mock() dummy = Mock()
...@@ -52,7 +55,7 @@ def post_request(url, payload): ...@@ -52,7 +55,7 @@ def post_request(url, payload):
return dummy return dummy
def get_request(url): def get_request(url, timeout=None):
try: try:
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
if settings['ssl_auth'] == 'True' and settings['basic_auth'] == 'True': if settings['ssl_auth'] == 'True' and settings['basic_auth'] == 'True':
...@@ -65,7 +68,9 @@ def get_request(url): ...@@ -65,7 +68,9 @@ def get_request(url):
settings['store_client_key']), settings['store_client_key']),
auth=( auth=(
settings['store_client_user'], settings['store_client_user'],
settings['store_client_pass'])) settings['store_client_pass']),
timeout=timeout,
)
elif settings['ssl_auth'] == 'True': elif settings['ssl_auth'] == 'True':
r = requests.get( r = requests.get(
url, url,
...@@ -73,7 +78,9 @@ def get_request(url): ...@@ -73,7 +78,9 @@ def get_request(url):
verify=settings['verify_ssl'] == 'True', verify=settings['verify_ssl'] == 'True',
cert=( cert=(
settings['store_client_cert'], settings['store_client_cert'],
settings['store_client_key'])) settings['store_client_key']),
timeout=timeout,
)
elif settings['basic_auth'] == 'True': elif settings['basic_auth'] == 'True':
r = requests.get( r = requests.get(
url, url,
...@@ -81,10 +88,13 @@ def get_request(url): ...@@ -81,10 +88,13 @@ def get_request(url):
verify=settings['verify_ssl'] == 'True', verify=settings['verify_ssl'] == 'True',
auth=( auth=(
settings['store_client_user'], settings['store_client_user'],
settings['store_client_pass'])) settings['store_client_pass']),
timeout=timeout,
)
else: else:
r = requests.get(url, headers=headers, r = requests.get(url, headers=headers,
verify=settings['verify_ssl'] == 'True' verify=settings['verify_ssl'] == 'True',
timeout=timeout,
) )
return r return r
except: except:
...@@ -97,7 +107,7 @@ def get_request(url): ...@@ -97,7 +107,7 @@ def get_request(url):
def listfolder(neptun, path): def listfolder(neptun, path):
url = settings['store_url']+'/'+neptun url = settings['store_url']+'/'+neptun
payload = json.dumps({'CMD': 'LIST', 'PATH': path}) payload = json.dumps({'CMD': 'LIST', 'PATH': path})
r = post_request(url, payload) r = post_request(url, payload, timeout=5)
if r.status_code == requests.codes.ok: if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content) tupplelist = json.loads(r.content)
return tupplelist return tupplelist
...@@ -108,7 +118,7 @@ def listfolder(neptun, path): ...@@ -108,7 +118,7 @@ def listfolder(neptun, path):
def toplist(neptun): def toplist(neptun):
url = settings['store_url']+'/'+neptun url = settings['store_url']+'/'+neptun
payload = json.dumps({'CMD': 'TOPLIST'}) payload = json.dumps({'CMD': 'TOPLIST'})
r = post_request(url, payload) r = post_request(url, payload, timeout=2)
if r.status_code == requests.codes.ok: if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content) tupplelist = json.loads(r.content)
return tupplelist return tupplelist
...@@ -187,7 +197,7 @@ def set_quota(neptun, quota): ...@@ -187,7 +197,7 @@ def set_quota(neptun, quota):
def userexist(neptun): def userexist(neptun):
url = settings['store_url']+'/'+neptun url = settings['store_url']+'/'+neptun
r = get_request(url) r = get_request(url, timeout=5)
if r.status_code == requests.codes.ok: if r.status_code == requests.codes.ok:
return True return True
else: else:
...@@ -198,7 +208,7 @@ def createuser(neptun, password, key_list, quota): ...@@ -198,7 +208,7 @@ def createuser(neptun, password, key_list, quota):
url = settings['store_url']+'/new/'+neptun url = settings['store_url']+'/new/'+neptun
payload = json.dumps( payload = json.dumps(
{'SMBPASSWD': password, 'KEYS': key_list, 'QUOTA': quota}) {'SMBPASSWD': password, 'KEYS': key_list, 'QUOTA': quota})
r = post_request(url, payload) r = post_request(url, payload, timeout=5)
if r.status_code == requests.codes.ok: if r.status_code == requests.codes.ok:
return True return True
else: else:
......
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