Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d0ca16b3
authored
Jul 10, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add timeout for certain store function
parent
b66c1174
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
15 deletions
+25
-15
circle/dashboard/store_api.py
+25
-15
No files found.
circle/dashboard/store_api.py
View file @
d0ca16b3
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment