sharing: further review
This commit is contained in:
@@ -328,7 +328,7 @@ class BaseSharing:
|
|||||||
if not self.sharing_collection_by_map:
|
if not self.sharing_collection_by_map:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("TRACE/sharing/map: not active")
|
logger.debug("TRACE/sharing/map: not active")
|
||||||
return [{}]
|
return []
|
||||||
|
|
||||||
# retrieve collections depending on filter
|
# retrieve collections depending on filter
|
||||||
shared_collection_list = self.database_list_sharing(
|
shared_collection_list = self.database_list_sharing(
|
||||||
@@ -356,7 +356,7 @@ class BaseSharing:
|
|||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("TRACE/sharing/token: not active")
|
logger.debug("TRACE/sharing/token: not active")
|
||||||
return None
|
pass
|
||||||
|
|
||||||
if self.sharing_collection_by_map:
|
if self.sharing_collection_by_map:
|
||||||
result = self.sharing_collection_by_map_resolver(path, user)
|
result = self.sharing_collection_by_map_resolver(path, user)
|
||||||
@@ -494,8 +494,12 @@ class BaseSharing:
|
|||||||
Status in JSON/TEXT (TEXT can be parsed by shell)
|
Status in JSON/TEXT (TEXT can be parsed by shell)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
# initial log prefix
|
||||||
|
api_info = "Sharing/API/POST"
|
||||||
|
|
||||||
if not self._enabled:
|
if not self._enabled:
|
||||||
# API is not enabled
|
# API is not enabled
|
||||||
|
logger.warning(api_info + ": API is not enabled")
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
|
|
||||||
if user == "":
|
if user == "":
|
||||||
@@ -504,6 +508,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
# supported API version check
|
# supported API version check
|
||||||
if not path.startswith("/.sharing/v1/"):
|
if not path.startswith("/.sharing/v1/"):
|
||||||
|
logger.warning(api_info + ": leading part of path not matching supported API version")
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
|
|
||||||
# split into ShareType and action
|
# split into ShareType and action
|
||||||
@@ -517,6 +522,9 @@ class BaseSharing:
|
|||||||
ShareType = match.group(1)
|
ShareType = match.group(1)
|
||||||
action = match.group(2)
|
action = match.group(2)
|
||||||
|
|
||||||
|
# append ShareType
|
||||||
|
api_info = api_info + "/" + ShareType
|
||||||
|
|
||||||
# check for valid ShareTypes
|
# check for valid ShareTypes
|
||||||
if ShareType:
|
if ShareType:
|
||||||
if ShareType not in SHARE_TYPES:
|
if ShareType not in SHARE_TYPES:
|
||||||
@@ -539,6 +547,9 @@ class BaseSharing:
|
|||||||
logger.debug("TRACE/sharing/API: action not whitelisted: %r", action)
|
logger.debug("TRACE/sharing/API: action not whitelisted: %r", action)
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
|
|
||||||
|
# append action
|
||||||
|
api_info = api_info + "/" + action
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("TRACE/sharing/API: called by authenticated user: %r", user)
|
logger.debug("TRACE/sharing/API: called by authenticated user: %r", user)
|
||||||
# read POST data
|
# read POST data
|
||||||
@@ -551,9 +562,6 @@ class BaseSharing:
|
|||||||
logger.debug("Client timed out", exc_info=True)
|
logger.debug("Client timed out", exc_info=True)
|
||||||
return httputils.REQUEST_TIMEOUT
|
return httputils.REQUEST_TIMEOUT
|
||||||
|
|
||||||
# initial log prefix
|
|
||||||
api_info = "Sharing/API/POST/" + ShareType + "/" + action
|
|
||||||
|
|
||||||
# parse body according to content-type
|
# parse body according to content-type
|
||||||
content_type = environ.get("CONTENT_TYPE", "")
|
content_type = environ.get("CONTENT_TYPE", "")
|
||||||
if 'application/json' in content_type:
|
if 'application/json' in content_type:
|
||||||
@@ -776,6 +784,7 @@ class BaseSharing:
|
|||||||
with self._storage.acquire_lock("r", user, path=PathMapped):
|
with self._storage.acquire_lock("r", user, path=PathMapped):
|
||||||
item = next(iter(self._storage.discover(PathMapped)), None)
|
item = next(iter(self._storage.discover(PathMapped)), None)
|
||||||
if not item:
|
if not item:
|
||||||
|
logger.warning(api_info + ": cannot find PathMapped=%r", PathMapped)
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
if not isinstance(item, storage.BaseCollection):
|
if not isinstance(item, storage.BaseCollection):
|
||||||
return httputils.METHOD_NOT_ALLOWED
|
return httputils.METHOD_NOT_ALLOWED
|
||||||
|
|||||||
Reference in New Issue
Block a user