Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
soledad
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
leap
soledad
Commits
6f823928
Commit
6f823928
authored
7 years ago
by
drebs
Browse files
Options
Downloads
Patches
Plain Diff
[refactor] make blobs backend delete_blob() agnostic of twisted.web requests
parent
a78ed867
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/leap/soledad/server/_blobs.py
+8
-5
8 additions, 5 deletions
src/leap/soledad/server/_blobs.py
src/leap/soledad/server/interfaces.py
+0
-5
0 additions, 5 deletions
src/leap/soledad/server/interfaces.py
tests/blobs/test_fs_backend.py
+2
-4
2 additions, 4 deletions
tests/blobs/test_fs_backend.py
with
10 additions
and
14 deletions
src/leap/soledad/server/_blobs.py
+
8
−
5
View file @
6f823928
...
...
@@ -137,11 +137,10 @@ class FilesystemBlobsBackend(object):
yield
fbp
.
startProducing
(
blobfile
)
yield
self
.
semaphore
.
release
()
def
delete_blob
(
self
,
user
,
blob_id
,
request
,
namespace
=
''
):
def
delete_blob
(
self
,
user
,
blob_id
,
namespace
=
''
):
blob_path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
if
not
os
.
path
.
isfile
(
blob_path
):
request
.
setResponseCode
(
404
)
return
"
Blob doesn
'
t exists: %s
"
%
blob_id
raise
BlobNotFound
self
.
__touch
(
blob_path
+
'
.deleted
'
)
os
.
unlink
(
blob_path
)
try
:
...
...
@@ -304,8 +303,12 @@ class BlobsResource(resource.Resource):
def
render_DELETE
(
self
,
request
):
logger
.
info
(
"
http put: %s
"
%
request
.
path
)
user
,
blob_id
,
namespace
=
self
.
_validate
(
request
)
self
.
_handler
.
delete_blob
(
user
,
blob_id
,
request
,
namespace
=
namespace
)
return
''
try
:
self
.
_handler
.
delete_blob
(
user
,
blob_id
,
namespace
=
namespace
)
return
''
except
BlobNotFound
:
request
.
setResponseCode
(
404
)
return
"
Blob doesn
'
t exists: %s
"
%
blob_id
def
render_PUT
(
self
,
request
):
logger
.
info
(
"
http put: %s
"
%
request
.
path
)
...
...
This diff is collapsed.
Click to expand it.
src/leap/soledad/server/interfaces.py
+
0
−
5
View file @
6f823928
...
...
@@ -23,11 +23,6 @@ class IBlobsBackend(Interface):
"""
An interface for a backend that can store blobs.
Classes that implement this interface are supposed to be used by
``BlobsResource``, which is a ``twisted.web.resource.Resource`` that serves
the Blobs API. Because of that, their methods receive instances of
``twisted.web.server.Request`` and should use them to serve the Blobs API.
"""
def
read_blob
(
user
,
blob_id
,
namespace
=
''
):
...
...
This diff is collapsed.
Click to expand it.
tests/blobs/test_fs_backend.py
+
2
−
4
View file @
6f823928
...
...
@@ -172,14 +172,13 @@ class FilesystemBackendTestCase(unittest.TestCase):
@mock.patch
(
'
leap.soledad.server._blobs.os.unlink
'
)
def
test_delete_blob
(
self
,
unlink_mock
):
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
self
.
tempdir
)
request
=
DummyRequest
([
''
])
# write a blob...
path
=
backend
.
_get_path
(
'
user
'
,
'
blob_id
'
,
''
)
mkdir_p
(
os
.
path
.
split
(
path
)[
0
])
with
open
(
path
,
"
w
"
)
as
f
:
f
.
write
(
"
bl0b
"
)
# ...and delete it
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
,
request
)
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
)
unlink_mock
.
assert_any_call
(
backend
.
_get_path
(
'
user
'
,
'
blob_id
'
))
unlink_mock
.
assert_any_call
(
backend
.
_get_path
(
'
user
'
,
...
...
@@ -189,14 +188,13 @@ class FilesystemBackendTestCase(unittest.TestCase):
@mock.patch
(
'
leap.soledad.server._blobs.os.unlink
'
)
def
test_delete_blob_custom_namespace
(
self
,
unlink_mock
):
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
self
.
tempdir
)
request
=
DummyRequest
([
''
])
# write a blob...
path
=
backend
.
_get_path
(
'
user
'
,
'
blob_id
'
,
'
trash
'
)
mkdir_p
(
os
.
path
.
split
(
path
)[
0
])
with
open
(
path
,
"
w
"
)
as
f
:
f
.
write
(
"
bl0b
"
)
# ...and delete it
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
,
request
,
namespace
=
'
trash
'
)
backend
.
delete_blob
(
'
user
'
,
'
blob_id
'
,
namespace
=
'
trash
'
)
unlink_mock
.
assert_any_call
(
backend
.
_get_path
(
'
user
'
,
'
blob_id
'
,
'
trash
'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment