Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7af38cf1
authored
Jun 30, 2014
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added cloudstore
parent
8caddf33
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
201 additions
and
0 deletions
+201
-0
circle/cloudstore/store_api.py
+201
-0
No files found.
circle/cloudstore/store_api.py
0 → 100644
View file @
7af38cf1
from
django.http
import
Http404
import
json
import
requests
import
time
import
django.conf
settings
=
django
.
conf
.
settings
.
STORE_SETTINGS
def
get_host
():
return
settings
[
'store_url'
]
def
post_request
(
url
,
payload
):
headers
=
{
'content-type'
:
'application/json'
}
if
settings
[
'ssl_auth'
]
==
'True'
and
settings
[
'basic_auth'
]
==
'True'
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
,
cert
=
(
settings
[
'store_client_cert'
],
settings
[
'store_client_key'
]),
auth
=
(
settings
[
'store_client_user'
],
settings
[
'store_client_pass'
])
)
elif
settings
[
'ssl_auth'
]
==
'True'
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
,
cert
=
(
settings
[
'store_client_cert'
],
settings
[
'store_client_key'
])
)
elif
settings
[
'basic_auth'
]
==
'True'
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
,
auth
=
(
settings
[
'store_client_user'
],
settings
[
'store_client_pass'
])
)
else
:
r
=
requests
.
post
(
url
,
data
=
payload
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
)
return
r
def
get_request
(
url
):
headers
=
{
'content-type'
:
'application/json'
}
if
settings
[
'ssl_auth'
]
==
'True'
and
settings
[
'basic_auth'
]
==
'True'
:
r
=
requests
.
get
(
url
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
,
cert
=
(
settings
[
'store_client_cert'
],
settings
[
'store_client_key'
]),
auth
=
(
settings
[
'store_client_user'
],
settings
[
'store_client_pass'
]))
elif
settings
[
'ssl_auth'
]
==
'True'
:
r
=
requests
.
get
(
url
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
,
cert
=
(
settings
[
'store_client_cert'
],
settings
[
'store_client_key'
]))
elif
settings
[
'basic_auth'
]
==
'True'
:
r
=
requests
.
get
(
url
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
,
auth
=
(
settings
[
'store_client_user'
],
settings
[
'store_client_pass'
]))
else
:
r
=
requests
.
get
(
url
,
headers
=
headers
,
verify
=
settings
[
'verify_ssl'
]
==
'True'
)
return
r
def
listfolder
(
neptun
,
path
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'LIST'
,
'PATH'
:
path
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
tupplelist
=
json
.
loads
(
r
.
content
)
for
item
in
tupplelist
:
item
[
'MTIME'
]
=
time
.
ctime
(
item
[
'MTIME'
])
return
tupplelist
else
:
raise
Http404
def
toplist
(
neptun
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'TOPLIST'
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
tupplelist
=
json
.
loads
(
r
.
content
)
for
item
in
tupplelist
:
item
[
'MTIME'
]
=
time
.
ctime
(
item
[
'MTIME'
])
return
tupplelist
else
:
raise
Http404
def
requestdownload
(
neptun
,
path
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'DOWNLOAD'
,
'PATH'
:
path
})
r
=
post_request
(
url
,
payload
)
response
=
json
.
loads
(
r
.
content
)
return
response
[
'LINK'
]
def
requestupload
(
neptun
,
path
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'UPLOAD'
,
'PATH'
:
path
})
r
=
post_request
(
url
,
payload
)
response
=
json
.
loads
(
r
.
content
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
response
[
'LINK'
]
else
:
raise
Http404
def
requestremove
(
neptun
,
path
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'REMOVE'
,
'PATH'
:
path
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
def
requestnewfolder
(
neptun
,
path
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
({
'CMD'
:
'NEW_FOLDER'
,
'PATH'
:
path
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
def
requestrename
(
neptun
,
old_path
,
new_name
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
payload
=
json
.
dumps
(
{
'CMD'
:
'RENAME'
,
'NEW_NAME'
:
new_name
,
'PATH'
:
old_path
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
def
requestquota
(
neptun
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
r
=
get_request
(
url
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
json
.
loads
(
r
.
content
)
else
:
return
False
def
set_quota
(
neptun
,
quota
):
url
=
settings
[
'store_url'
]
+
'/quota/'
+
neptun
payload
=
json
.
dumps
({
'QUOTA'
:
quota
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
def
userexist
(
neptun
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
r
=
get_request
(
url
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
def
createuser
(
neptun
,
password
,
key_list
,
quota
):
url
=
settings
[
'store_url'
]
+
'/new/'
+
neptun
payload
=
json
.
dumps
(
{
'SMBPASSWD'
:
password
,
'KEYS'
:
key_list
,
'QUOTA'
:
quota
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
def
updateauthorizationinfo
(
neptun
,
password
,
key_list
):
url
=
settings
[
'store_url'
]
+
'/set/'
+
neptun
payload
=
json
.
dumps
({
'SMBPASSWD'
:
password
,
'KEYS'
:
key_list
})
r
=
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
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