Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.libnetworkcache
Commits
2375ce5c
Commit
2375ce5c
authored
Sep 01, 2017
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
download: verify checksum of downloaded data
parent
735103da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
1 deletion
+22
-1
slapos/libnetworkcache.py
slapos/libnetworkcache.py
+22
-1
No files found.
slapos/libnetworkcache.py
View file @
2375ce5c
...
...
@@ -76,6 +76,27 @@ except NameError:
def
strify
(
input
):
return
input
class
CheckResponse
(
object
):
def
__init__
(
self
,
response
,
sha512sum
):
self
.
_response
=
response
self
.
_expected
=
sha512sum
self
.
_sha512sum
=
hashlib
.
sha512
()
def
__getattr__
(
self
,
attr
):
if
attr
.
startswith
(
'_'
)
or
'read'
in
attr
:
return
object
.
__getattribute__
(
self
,
attr
)
return
getattr
(
self
.
_response
,
attr
)
def
read
(
self
,
amt
=
None
):
r
=
self
.
_response
.
read
(
amt
)
if
r
:
self
.
_sha512sum
.
update
(
r
)
elif
amt
!=
0
and
self
.
_expected
!=
self
.
_sha512sum
.
hexdigest
():
raise
NetworkcacheException
(
'Failed to upload data to SHACACHE Server: invalid checksum.'
)
return
r
class
NetworkcacheClient
(
object
):
'''
NetworkcacheClient is a wrapper for httplib.
...
...
@@ -288,7 +309,7 @@ class NetworkcacheClient(object):
''' Download the file.
It uses http GET request method.
'''
return
self
.
_request
(
'cache'
,
sha512sum
)
return
CheckResponse
(
self
.
_request
(
'cache'
,
sha512sum
)
,
sha512sum
)
def
select
(
self
,
key
,
wanted_metadata_dict
=
{},
required_key_list
=
frozenset
()):
'''Return an iterator over shadir entries that match given criteria
...
...
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