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
9f07826c
Verified
Commit
9f07826c
authored
7 years ago
by
drebs
Browse files
Options
Downloads
Patches
Plain Diff
[refactor] make blobs backend get_flags() agnostic of twisted.web requests
parent
6f29df7d
No related branches found
No related tags found
1 merge request
!169
#9007 - improve and document IBlobsBackend
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/leap/soledad/server/_blobs.py
+10
-10
10 additions, 10 deletions
src/leap/soledad/server/_blobs.py
src/leap/soledad/server/interfaces.py
+3
-6
3 additions, 6 deletions
src/leap/soledad/server/interfaces.py
tests/server/test_incoming_server.py
+1
-3
1 addition, 3 deletions
tests/server/test_incoming_server.py
with
14 additions
and
19 deletions
src/leap/soledad/server/_blobs.py
+
10
−
10
View file @
9f07826c
...
...
@@ -85,16 +85,14 @@ class FilesystemBlobsBackend(object):
_file
=
static
.
File
(
path
,
defaultType
=
'
application/octet-stream
'
)
return
_file
.
render_GET
(
request
)
def
get_flags
(
self
,
user
,
blob_id
,
request
,
namespace
=
''
):
def
get_flags
(
self
,
user
,
blob_id
,
namespace
=
''
):
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
if
not
os
.
path
.
isfile
(
path
):
# 404 - Not Found
request
.
setResponseCode
(
404
)
return
"
Blob doesn
'
t exists: %s
"
%
blob_id
raise
BlobNotFound
if
not
os
.
path
.
isfile
(
path
+
'
.flags
'
):
return
'
[]
'
return
[]
with
open
(
path
+
'
.flags
'
,
'
r
'
)
as
flags_file
:
return
flags_file
.
read
()
return
json
.
loads
(
flags_file
.
read
()
)
def
set_flags
(
self
,
user
,
blob_id
,
request
,
namespace
=
''
):
path
=
self
.
_get_path
(
user
,
blob_id
,
namespace
)
...
...
@@ -286,16 +284,18 @@ class BlobsResource(resource.Resource):
order_by
=
order
,
deleted
=
deleted
,
filter_flag
=
filter_flag
)
only_flags
=
request
.
args
.
get
(
'
only_flags
'
,
[
False
])[
0
]
if
only_flags
:
return
self
.
_handler
.
get_flags
(
user
,
blob_id
,
request
,
namespace
)
try
:
if
only_flags
:
flags
=
self
.
_handler
.
get_flags
(
user
,
blob_id
,
namespace
)
return
json
.
dumps
(
flags
)
tag
=
self
.
_handler
.
get_tag
(
user
,
blob_id
,
namespace
)
request
.
responseHeaders
.
setRawHeaders
(
'
Tag
'
,
[
tag
])
except
BlobNotFound
:
# 404 - Not Found
request
.
setResponseCode
(
404
)
return
"
Blob doesn
'
t exists: %s
"
%
blob_id
re
quest
.
responseHeaders
.
setRawHeaders
(
'
Tag
'
,
[
tag
])
return
self
.
_handler
.
read_blob
(
user
,
blob_id
,
request
,
namespace
)
re
turn
self
.
_handler
.
read_blob
(
user
,
blob_id
,
request
,
namespace
=
namespace
)
def
render_DELETE
(
self
,
request
):
logger
.
info
(
"
http put: %s
"
%
request
.
path
)
...
...
This diff is collapsed.
Click to expand it.
src/leap/soledad/server/interfaces.py
+
3
−
6
View file @
9f07826c
...
...
@@ -167,7 +167,7 @@ class IBlobsBackend(Interface):
:rtype: str
"""
def
get_flags
(
user
,
blob_id
,
request
,
namespace
=
''
):
def
get_flags
(
user
,
blob_id
,
namespace
=
''
):
"""
Get the flags for a blob.
...
...
@@ -175,14 +175,11 @@ class IBlobsBackend(Interface):
:type user: str
:param blob_id: The id of the blob.
:type blob_id: str
:param request: A representation of all of the information about the
request that is being made.
:type request: twisted.web.server.Request
:param namespace: An optional namespace for the blob.
:type namespace: str
:return: a
JSON encoded string with a
list of flags.
:rtype: str
:return: a list of flags.
:rtype:
list of
str
"""
def
set_flags
(
user
,
blob_id
,
request
,
namespace
=
''
):
...
...
This diff is collapsed.
Click to expand it.
tests/server/test_incoming_server.py
+
1
−
3
View file @
9f07826c
...
...
@@ -18,7 +18,6 @@
Integration tests for incoming API
"""
import
pytest
import
json
from
io
import
BytesIO
from
uuid
import
uuid4
from
twisted.web.test.test_web
import
DummyRequest
...
...
@@ -86,8 +85,7 @@ class IncomingOnCouchServerTestCase(CouchDBTestCase):
db
=
self
.
state
.
open_database
(
user_id
)
request
=
DummyRequest
([
user_id
,
doc_id
])
yield
db
.
read_blob
(
user_id
,
doc_id
,
request
,
'
MX
'
)
flags
=
db
.
get_flags
(
user_id
,
doc_id
,
request
,
'
MX
'
)
flags
=
json
.
loads
(
flags
)
flags
=
db
.
get_flags
(
user_id
,
doc_id
,
'
MX
'
)
expected_preamble
=
formatter
.
preamble
(
content
,
doc_id
)
expected_preamble
=
decode_preamble
(
expected_preamble
,
True
)
written_preamble
,
written_content
=
request
.
written
[
0
].
split
()
...
...
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