log/sharing: replace legacy trace log
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
import base64
|
import base64
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import uuid
|
import uuid
|
||||||
@@ -362,8 +361,7 @@ class BaseSharing:
|
|||||||
sharing_collection_list = []
|
sharing_collection_list = []
|
||||||
|
|
||||||
if not self.sharing_collection_by_map:
|
if not self.sharing_collection_by_map:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map: not active")
|
||||||
logger.debug("TRACE/sharing/map: not active")
|
|
||||||
else:
|
else:
|
||||||
# retrieve collections depending on filter
|
# retrieve collections depending on filter
|
||||||
sharing_collection_list += self.database_list_sharing(
|
sharing_collection_list += self.database_list_sharing(
|
||||||
@@ -382,7 +380,7 @@ class BaseSharing:
|
|||||||
# resolves a path to a share
|
# resolves a path to a share
|
||||||
def sharing_collection_resolver(self, path: str, user: str) -> Union[dict, None]:
|
def sharing_collection_resolver(self, path: str, user: str) -> Union[dict, None]:
|
||||||
""" returning dict with PathMapped, Owner, Permissions or None if not found"""
|
""" returning dict with PathMapped, Owner, Permissions or None if not found"""
|
||||||
logger.debug("TRACE/sharing/resolver: lookup path=%r user=%r", path, user)
|
logger.trace("sharing/resolver: lookup path=%r user=%r", path, user)
|
||||||
share = None
|
share = None
|
||||||
|
|
||||||
if path == "/":
|
if path == "/":
|
||||||
@@ -395,8 +393,7 @@ class BaseSharing:
|
|||||||
if share is not None and 'error' in share:
|
if share is not None and 'error' in share:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token: not active")
|
||||||
logger.debug("TRACE/sharing/token: not active")
|
|
||||||
|
|
||||||
if self.sharing_collection_by_map:
|
if self.sharing_collection_by_map:
|
||||||
if share is None:
|
if share is None:
|
||||||
@@ -404,23 +401,21 @@ class BaseSharing:
|
|||||||
if share is not None and 'error' in share:
|
if share is not None and 'error' in share:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map: not active")
|
||||||
logger.debug("TRACE/sharing/map: not active")
|
|
||||||
|
|
||||||
return share
|
return share
|
||||||
|
|
||||||
# adjust a share
|
# adjust a share
|
||||||
def sharing_collection_update(self, ShareType: str, PathOrToken: str, OwnerOrUser: str, Properties: dict) -> None:
|
def sharing_collection_update(self, ShareType: str, PathOrToken: str, OwnerOrUser: str, Properties: dict) -> None:
|
||||||
""" returning dict with PathMapped, Owner, Permissions or None if not found"""
|
""" returning dict with PathMapped, Owner, Permissions or None if not found"""
|
||||||
logger.info("Sharing/collection/update: ShareType=%r PathOrToken=%r OwnerOrUser=%r", ShareType, PathOrToken, OwnerOrUser)
|
logger.info("sharing/collection/update: ShareType=%r PathOrToken=%r OwnerOrUser=%r", ShareType, PathOrToken, OwnerOrUser)
|
||||||
# Filter properies for permitted ones
|
# Filter properies for permitted ones
|
||||||
properties_filtered: dict = {}
|
properties_filtered: dict = {}
|
||||||
for prop in Properties:
|
for prop in Properties:
|
||||||
if prop in OVERLAY_PROPERTIES_WHITELIST:
|
if prop in OVERLAY_PROPERTIES_WHITELIST:
|
||||||
properties_filtered[prop] = Properties[prop]
|
properties_filtered[prop] = Properties[prop]
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/collection_update: silent discard unsupported property: %r", prop)
|
||||||
logger.debug("TRACE/sharing/collection_update: silent discard unsupported property: %r", prop)
|
|
||||||
|
|
||||||
self.database_update_sharing(ShareType=ShareType,
|
self.database_update_sharing(ShareType=ShareType,
|
||||||
PathOrToken=PathOrToken,
|
PathOrToken=PathOrToken,
|
||||||
@@ -435,51 +430,43 @@ class BaseSharing:
|
|||||||
def sharing_collection_by_token_resolver(self, path) -> Union[dict, None]:
|
def sharing_collection_by_token_resolver(self, path) -> Union[dict, None]:
|
||||||
""" returning dict with PathMapped, Owner, Permissions or None if invalid"""
|
""" returning dict with PathMapped, Owner, Permissions or None if invalid"""
|
||||||
if self.sharing_collection_by_token:
|
if self.sharing_collection_by_token:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token/resolver: check path: %r", path)
|
||||||
logger.debug("TRACE/sharing/token/resolver: check path: %r", path)
|
|
||||||
if path.startswith("/.token/"):
|
if path.startswith("/.token/"):
|
||||||
pattern = re.compile('^(/\\.token/' + TOKEN_PATTERN_V1 + '/)$')
|
pattern = re.compile('^(/\\.token/' + TOKEN_PATTERN_V1 + '/)$')
|
||||||
match = pattern.match(path)
|
match = pattern.match(path)
|
||||||
if not match:
|
if not match:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token/resolver: unsupported token: %r", path)
|
||||||
logger.debug("TRACE/sharing/token/resolver: unsupported token: %r", path)
|
|
||||||
return {'error': 'token-not-supported'}
|
return {'error': 'token-not-supported'}
|
||||||
else:
|
else:
|
||||||
# TODO add token validity checks
|
# TODO add token validity checks
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token/resolver: supported token: %r", path)
|
||||||
logger.debug("TRACE/sharing/token/resolver: supported token: %r", path)
|
|
||||||
result = self.database_get_sharing(
|
result = self.database_get_sharing(
|
||||||
ShareType="token",
|
ShareType="token",
|
||||||
OnlyEnabled=False,
|
OnlyEnabled=False,
|
||||||
PathOrToken=match[1])
|
PathOrToken=match[1])
|
||||||
|
|
||||||
if result is None:
|
if result is None:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token/resolver: supported token not found: %r", path)
|
||||||
logger.debug("TRACE/sharing/token/resolver: supported token not found: %r", path)
|
|
||||||
return {'error': 'token-not-found'}
|
return {'error': 'token-not-found'}
|
||||||
|
|
||||||
if result['EnabledByOwner'] is not True:
|
if result['EnabledByOwner'] is not True:
|
||||||
logger.info("Sharing/%s: resolved path %r->%r, User=%r not enabled by owner", "token", path, result['PathMapped'], result['Owner'])
|
logger.info("sharing/%s: resolved path %r->%r, User=%r not enabled by owner", "token", path, result['PathMapped'], result['Owner'])
|
||||||
return {'error': 'token-not-enabled'}
|
return {'error': 'token-not-enabled'}
|
||||||
|
|
||||||
logger.info("Sharing/%s: resolved %r->%r, User=%r, Permissions=%r Conversion=%r", "token", path, result['PathMapped'], result['Owner'], result['Permissions'], result['Conversion'])
|
logger.info("sharing/%s: resolved %r->%r, User=%r, Permissions=%r Conversion=%r", "token", path, result['PathMapped'], result['Owner'], result['Permissions'], result['Conversion'])
|
||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token/resolver: no supported prefix found in path: %r", path)
|
||||||
logger.debug("TRACE/sharing/token/resolver: no supported prefix found in path: %r", path)
|
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token: not active")
|
||||||
logger.debug("TRACE/sharing/token: not active")
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# resolves a map "path" to a share
|
# resolves a map "path" to a share
|
||||||
def sharing_collection_by_map_resolver(self, path: str, user: str) -> Union[dict, None]:
|
def sharing_collection_by_map_resolver(self, path: str, user: str) -> Union[dict, None]:
|
||||||
""" returning dict with PathMapped, Owner, Permissions or None if invalid"""
|
""" returning dict with PathMapped, Owner, Permissions or None if invalid"""
|
||||||
if self.sharing_collection_by_map:
|
if self.sharing_collection_by_map:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map/resolver: check path: %r", path)
|
||||||
logger.debug("TRACE/sharing/map/resolver: check path: %r", path)
|
|
||||||
|
|
||||||
result = self.database_get_sharing(
|
result = self.database_get_sharing(
|
||||||
ShareType="map",
|
ShareType="map",
|
||||||
PathOrToken=path,
|
PathOrToken=path,
|
||||||
@@ -489,8 +476,7 @@ class BaseSharing:
|
|||||||
if not result:
|
if not result:
|
||||||
# fallback to parent path
|
# fallback to parent path
|
||||||
parent_path = pathutils.parent_path(path)
|
parent_path = pathutils.parent_path(path)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map/resolver: check parent path: %r", parent_path)
|
||||||
logger.debug("TRACE/sharing/map/resolver: check parent path: %r", parent_path)
|
|
||||||
result = self.database_get_sharing(
|
result = self.database_get_sharing(
|
||||||
ShareType="map",
|
ShareType="map",
|
||||||
PathOrToken=parent_path,
|
PathOrToken=parent_path,
|
||||||
@@ -498,28 +484,25 @@ class BaseSharing:
|
|||||||
User=user)
|
User=user)
|
||||||
if result:
|
if result:
|
||||||
result['PathMapped'] = path.replace(parent_path, result['PathMapped'])
|
result['PathMapped'] = path.replace(parent_path, result['PathMapped'])
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map/resolver: PathMapped=%r Permissions=%r by parent_path=%r", result['PathMapped'], result['Permissions'], parent_path)
|
||||||
logger.debug("TRACE/sharing/map/resolver: PathMapped=%r Permissions=%r by parent_path=%r", result['PathMapped'], result['Permissions'], parent_path)
|
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map/resolver: not found")
|
||||||
logger.debug("TRACE/sharing/map/resolver: not found")
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
if result['EnabledByOwner'] is not True:
|
if result['EnabledByOwner'] is not True:
|
||||||
logger.info("Sharing/%s: resolved path %r->%r, user %r->%r not enabled by owner", "map", path, result['PathMapped'], user, result['Owner'])
|
logger.info("sharing/%s: resolved path %r->%r, user %r->%r not enabled by owner", "map", path, result['PathMapped'], user, result['Owner'])
|
||||||
return {'error': 'map-not-enabled'}
|
return {'error': 'map-not-enabled'}
|
||||||
if result['EnabledByUser'] is not True:
|
if result['EnabledByUser'] is not True:
|
||||||
logger.info("Sharing/%s: resolved path %r->%r, user %r->%r not enabled by user", "map", path, result['PathMapped'], user, result['Owner'])
|
logger.info("sharing/%s: resolved path %r->%r, user %r->%r not enabled by user", "map", path, result['PathMapped'], user, result['Owner'])
|
||||||
return {'error': 'map-not-enabled'}
|
return {'error': 'map-not-enabled'}
|
||||||
|
|
||||||
logger.info("Sharing/%s: resolved path %r->%r, user %r->%r, Permissions=%r Conversion=%r", "map", path, result['PathMapped'], user, result['Owner'], result['Permissions'], result['Conversion'])
|
logger.info("sharing/%s: resolved path %r->%r, user %r->%r, Permissions=%r Conversion=%r", "map", path, result['PathMapped'], user, result['Owner'], result['Permissions'], result['Conversion'])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map: not active")
|
||||||
logger.debug("TRACE/sharing/map: not active")
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# *** POST API ***
|
# *** POST API ***
|
||||||
@@ -570,7 +553,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
# initial log prefix
|
# initial log prefix
|
||||||
api_info = "Sharing/API/POST"
|
api_info = "sharing/API/POST"
|
||||||
|
|
||||||
if not self._enabled:
|
if not self._enabled:
|
||||||
# API is not enabled
|
# API is not enabled
|
||||||
@@ -590,8 +573,7 @@ class BaseSharing:
|
|||||||
ShareType_action = path.removeprefix("/.sharing/v1/")
|
ShareType_action = path.removeprefix("/.sharing/v1/")
|
||||||
match = re.search('([a-z]+)/([a-z]+)$', ShareType_action)
|
match = re.search('([a-z]+)/([a-z]+)$', ShareType_action)
|
||||||
if not match:
|
if not match:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API: ShareType/action not extractable: %r", ShareType_action)
|
||||||
logger.debug("TRACE/sharing/API: ShareType/action not extractable: %r", ShareType_action)
|
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
else:
|
else:
|
||||||
ShareType = match.group(1)
|
ShareType = match.group(1)
|
||||||
@@ -603,8 +585,7 @@ class BaseSharing:
|
|||||||
# check for valid ShareTypes
|
# check for valid ShareTypes
|
||||||
if ShareType:
|
if ShareType:
|
||||||
if ShareType not in SHARE_TYPES:
|
if ShareType not in SHARE_TYPES:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API: ShareType not whitelisted: %r", ShareType)
|
||||||
logger.debug("TRACE/sharing/API: ShareType not whitelisted: %r", ShareType)
|
|
||||||
return httputils.NOT_FOUND
|
return httputils.NOT_FOUND
|
||||||
|
|
||||||
# check for enabled ShareTypes
|
# check for enabled ShareTypes
|
||||||
@@ -620,15 +601,13 @@ class BaseSharing:
|
|||||||
|
|
||||||
# check for valid API hooks
|
# check for valid API hooks
|
||||||
if action not in API_HOOKS_V1:
|
if action not in API_HOOKS_V1:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.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
|
# append action
|
||||||
api_info = api_info + "/" + action
|
api_info = api_info + "/" + action
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.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
|
||||||
try:
|
try:
|
||||||
request_body = httputils.read_request_body(self.configuration, environ)
|
request_body = httputils.read_request_body(self.configuration, environ)
|
||||||
@@ -654,8 +633,7 @@ class BaseSharing:
|
|||||||
if type(request_data[key]) is not bool:
|
if type(request_data[key]) is not bool:
|
||||||
logger.warning(api_info + ": unsupported (non-boolean) " + key + ": " + request_data[key])
|
logger.warning(api_info + ": unsupported (non-boolean) " + key + ": " + request_data[key])
|
||||||
return httputils.bad_request("Invalid non-boolean value for " + key + ": " + request_data[key])
|
return httputils.bad_request("Invalid non-boolean value for " + key + ": " + request_data[key])
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace(api_info + " (json): %r", f"{request_data}")
|
||||||
logger.debug("TRACE/" + api_info + " (json): %r", f"{request_data}")
|
|
||||||
elif 'application/x-www-form-urlencoded' in content_type:
|
elif 'application/x-www-form-urlencoded' in content_type:
|
||||||
input_format = "form"
|
input_format = "form"
|
||||||
output_format = "plain" # default
|
output_format = "plain" # default
|
||||||
@@ -667,8 +645,7 @@ class BaseSharing:
|
|||||||
# Properties key value parser
|
# Properties key value parser
|
||||||
properties_dict: dict = {}
|
properties_dict: dict = {}
|
||||||
for entry in request_parsed[key]:
|
for entry in request_parsed[key]:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API: parse property %r", entry)
|
||||||
logger.debug("TRACE/sharing/API: parse property %r", entry)
|
|
||||||
if entry == "":
|
if entry == "":
|
||||||
continue
|
continue
|
||||||
m = re.search('^([^=]+)=([^=]+)$', entry)
|
m = re.search('^([^=]+)=([^=]+)$', entry)
|
||||||
@@ -677,8 +654,7 @@ class BaseSharing:
|
|||||||
token = m.group(1).lstrip('"\'').rstrip('"\'')
|
token = m.group(1).lstrip('"\'').rstrip('"\'')
|
||||||
value = m.group(2).lstrip('"\'').rstrip('"\'')
|
value = m.group(2).lstrip('"\'').rstrip('"\'')
|
||||||
properties_dict[token] = value
|
properties_dict[token] = value
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API: converted Properties from form into dict: %r", properties_dict)
|
||||||
logger.debug("TRACE/sharing/API: converted Properties from form into dict: %r", properties_dict)
|
|
||||||
request_data[key] = properties_dict
|
request_data[key] = properties_dict
|
||||||
if len(request_data[key]) == 0:
|
if len(request_data[key]) == 0:
|
||||||
# empty
|
# empty
|
||||||
@@ -691,11 +667,9 @@ class BaseSharing:
|
|||||||
return httputils.bad_request("Invalid non-boolean value for " + key + ": " + request_parsed[key][0])
|
return httputils.bad_request("Invalid non-boolean value for " + key + ": " + request_parsed[key][0])
|
||||||
else:
|
else:
|
||||||
request_data[key] = request_parsed[key][0]
|
request_data[key] = request_parsed[key][0]
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + " (form): %r", f"{request_data}")
|
||||||
logger.debug("TRACE/" + api_info + " (form): %r", f"{request_data}")
|
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": no supported content data")
|
||||||
logger.debug("TRACE/" + api_info + ": no supported content data")
|
|
||||||
return httputils.bad_request("Content-type not supported")
|
return httputils.bad_request("Content-type not supported")
|
||||||
|
|
||||||
# check for requested output type
|
# check for requested output type
|
||||||
@@ -840,12 +814,10 @@ class BaseSharing:
|
|||||||
|
|
||||||
# action: list
|
# action: list
|
||||||
if action == "list":
|
if action == "list":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": start")
|
||||||
logger.debug("TRACE/" + api_info + ": start")
|
|
||||||
|
|
||||||
if PathOrToken is not None:
|
if PathOrToken is not None:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": filter: %r", PathOrToken)
|
||||||
logger.debug("TRACE/" + api_info + ": filter: %r", PathOrToken)
|
|
||||||
|
|
||||||
if ShareType != "all":
|
if ShareType != "all":
|
||||||
result_array = self.database_list_sharing(
|
result_array = self.database_list_sharing(
|
||||||
@@ -874,8 +846,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
# action: create
|
# action: create
|
||||||
elif action == "create":
|
elif action == "create":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": start")
|
||||||
logger.debug("TRACE/" + api_info + ": start")
|
|
||||||
|
|
||||||
if PathMapped is None:
|
if PathMapped is None:
|
||||||
logger.warning(api_info + ": missing PathMapped")
|
logger.warning(api_info + ": missing PathMapped")
|
||||||
@@ -955,8 +926,7 @@ class BaseSharing:
|
|||||||
# v1: create uuid token with 2x 16 bytes + separator = 264 bit with base64 encoding resulting in 56 chars without '=' padding
|
# v1: create uuid token with 2x 16 bytes + separator = 264 bit with base64 encoding resulting in 56 chars without '=' padding
|
||||||
token = "/.token/v1/" + str(base64.urlsafe_b64encode(uuid.uuid4().bytes + b"\0" + uuid.uuid4().bytes), 'utf-8') + "/"
|
token = "/.token/v1/" + str(base64.urlsafe_b64encode(uuid.uuid4().bytes + b"\0" + uuid.uuid4().bytes), 'utf-8') + "/"
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": %r (Permissions=%r token=%r)", PathMapped, Permissions, token)
|
||||||
logger.debug("TRACE/" + api_info + ": %r (Permissions=%r token=%r)", PathMapped, Permissions, token)
|
|
||||||
|
|
||||||
result = self.database_create_sharing(
|
result = self.database_create_sharing(
|
||||||
ShareType=ShareType,
|
ShareType=ShareType,
|
||||||
@@ -975,8 +945,7 @@ class BaseSharing:
|
|||||||
Actions=Actions,
|
Actions=Actions,
|
||||||
)
|
)
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": result=%r", result)
|
||||||
logger.debug("TRACE/" + api_info + ": result=%r", result)
|
|
||||||
|
|
||||||
elif ShareType == "map":
|
elif ShareType == "map":
|
||||||
# check preconditions
|
# check preconditions
|
||||||
@@ -1031,8 +1000,7 @@ class BaseSharing:
|
|||||||
logger.warning(api_info + ": PathOrToken=%r already exists as real collection for User=%r", PathOrToken, User)
|
logger.warning(api_info + ": PathOrToken=%r already exists as real collection for User=%r", PathOrToken, User)
|
||||||
return httputils.CONFLICT
|
return httputils.CONFLICT
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": %r (Permissions=%r PathOrToken=%r Owner=%r User=%r)", PathMapped, Permissions, PathOrToken, user, User)
|
||||||
logger.debug("TRACE/" + api_info + ": %r (Permissions=%r PathOrToken=%r Owner=%r User=%r)", PathMapped, Permissions, PathOrToken, user, User)
|
|
||||||
|
|
||||||
result = self.database_create_sharing(
|
result = self.database_create_sharing(
|
||||||
ShareType=ShareType,
|
ShareType=ShareType,
|
||||||
@@ -1054,8 +1022,7 @@ class BaseSharing:
|
|||||||
else:
|
else:
|
||||||
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
||||||
return httputils.bad_request("Invalid share type")
|
return httputils.bad_request("Invalid share type")
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": result=%r", result)
|
||||||
logger.debug("TRACE/" + api_info + ": result=%r", result)
|
|
||||||
# result handling
|
# result handling
|
||||||
if result['status'] == "conflict":
|
if result['status'] == "conflict":
|
||||||
return httputils.CONFLICT
|
return httputils.CONFLICT
|
||||||
@@ -1078,8 +1045,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
# action: update
|
# action: update
|
||||||
elif action == "update":
|
elif action == "update":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": start")
|
||||||
logger.debug("TRACE/" + api_info + ": start")
|
|
||||||
|
|
||||||
if ShareType not in SHARE_TYPES_V1:
|
if ShareType not in SHARE_TYPES_V1:
|
||||||
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
||||||
@@ -1105,17 +1071,14 @@ class BaseSharing:
|
|||||||
elif share['Properties'] is not None:
|
elif share['Properties'] is not None:
|
||||||
# replace properties
|
# replace properties
|
||||||
for prop in share['Properties']:
|
for prop in share['Properties']:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": check for existing property %r", prop)
|
||||||
logger.debug("TRACE/" + api_info + ": check for existing property %r", prop)
|
|
||||||
if prop not in Properties:
|
if prop not in Properties:
|
||||||
# overtake
|
# overtake
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": overtake property %r", prop)
|
||||||
logger.debug("TRACE/" + api_info + ": overtake property %r", prop)
|
|
||||||
Properties[prop] = share['Properties'][prop]
|
Properties[prop] = share['Properties'][prop]
|
||||||
elif Properties[prop] == '':
|
elif Properties[prop] == '':
|
||||||
# unset, do nothing
|
# unset, do nothing
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": clear property %r", prop)
|
||||||
logger.debug("TRACE/" + api_info + ": clear property %r", prop)
|
|
||||||
del Properties[prop]
|
del Properties[prop]
|
||||||
|
|
||||||
if user == share['Owner']:
|
if user == share['Owner']:
|
||||||
@@ -1160,8 +1123,7 @@ class BaseSharing:
|
|||||||
logger.warning(api_info + ": access to %r not allowed for user %r to adjust anything beside: %s", PathOrToken, user, " ".join(DB_FIELDS_V1_USER_PERMITTED))
|
logger.warning(api_info + ": access to %r not allowed for user %r to adjust anything beside: %s", PathOrToken, user, " ".join(DB_FIELDS_V1_USER_PERMITTED))
|
||||||
return httputils.NOT_ALLOWED
|
return httputils.NOT_ALLOWED
|
||||||
if 'Properties' in request_data:
|
if 'Properties' in request_data:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API/update: permit_properties_overlay=%s Permissions=%r", self.permit_properties_overlay, share['Permissions'])
|
||||||
logger.debug("TRACE/sharing/API/update: permit_properties_overlay=%s Permissions=%r", self.permit_properties_overlay, share['Permissions'])
|
|
||||||
if self.permit_properties_overlay:
|
if self.permit_properties_overlay:
|
||||||
if share['Permissions'] is not None and "p" in str(share['Permissions']):
|
if share['Permissions'] is not None and "p" in str(share['Permissions']):
|
||||||
logger.warning(api_info + ": %r properties overlay permitted by option, but denied by permission 'p'", PathOrToken)
|
logger.warning(api_info + ": %r properties overlay permitted by option, but denied by permission 'p'", PathOrToken)
|
||||||
@@ -1204,8 +1166,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
# action: delete
|
# action: delete
|
||||||
elif action == "delete":
|
elif action == "delete":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("" + api_info + ": start")
|
||||||
logger.debug("TRACE/" + api_info + ": start")
|
|
||||||
|
|
||||||
if ShareType not in SHARE_TYPES_V1:
|
if ShareType not in SHARE_TYPES_V1:
|
||||||
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
||||||
@@ -1260,8 +1221,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
# action: TOGGLE
|
# action: TOGGLE
|
||||||
elif action in API_SHARE_TOGGLES_V1:
|
elif action in API_SHARE_TOGGLES_V1:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API/POST/" + action)
|
||||||
logger.debug("TRACE/sharing/API/POST/" + action)
|
|
||||||
|
|
||||||
if ShareType not in SHARE_TYPES_V1:
|
if ShareType not in SHARE_TYPES_V1:
|
||||||
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
logger.warning(api_info + ": unsupported for ShareType=%r", ShareType)
|
||||||
@@ -1338,9 +1298,8 @@ class BaseSharing:
|
|||||||
return httputils.bad_request("Invalid action")
|
return httputils.bad_request("Invalid action")
|
||||||
|
|
||||||
# output handler
|
# output handler
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/API/POST output format: %r", output_format)
|
||||||
logger.debug("TRACE/sharing/API/POST output format: %r", output_format)
|
logger.trace("sharing/API/POST answer: %r", answer)
|
||||||
logger.debug("TRACE/sharing/API/POST answer: %r", answer)
|
|
||||||
if output_format == "csv" or output_format == "plain":
|
if output_format == "csv" or output_format == "plain":
|
||||||
answer_array = []
|
answer_array = []
|
||||||
if output_format == "plain":
|
if output_format == "plain":
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
@@ -97,8 +96,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
User: Union[str, None] = None) -> Union[dict, None]:
|
User: Union[str, None] = None) -> Union[dict, None]:
|
||||||
""" retrieve sharing target and attributes by map """
|
""" retrieve sharing target and attributes by map """
|
||||||
# Lookup
|
# Lookup
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing: lookup ShareType=%r PathOrToken=%r User=%r OnlyEnabled=%s)", ShareType, PathOrToken, User, OnlyEnabled)
|
||||||
logger.debug("TRACE/sharing: lookup ShareType=%r PathOrToken=%r User=%r OnlyEnabled=%s)", ShareType, PathOrToken, User, OnlyEnabled)
|
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
found = False
|
found = False
|
||||||
@@ -107,8 +105,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
# skip fieldnames
|
# skip fieldnames
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing: check row: %r", row)
|
||||||
logger.debug("TRACE/sharing: check row: %r", row)
|
|
||||||
if row['ShareType'] != ShareType:
|
if row['ShareType'] != ShareType:
|
||||||
pass
|
pass
|
||||||
elif row['PathOrToken'] != PathOrToken:
|
elif row['PathOrToken'] != PathOrToken:
|
||||||
@@ -174,33 +171,27 @@ class Sharing(sharing.BaseSharing):
|
|||||||
result = []
|
result = []
|
||||||
|
|
||||||
with self._storage.acquire_lock("r", path=self._sharing_db_file):
|
with self._storage.acquire_lock("r", path=self._sharing_db_file):
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s Conversion=%r", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser, Conversion)
|
||||||
logger.debug("TRACE/sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s Conversion=%r", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser, Conversion)
|
|
||||||
|
|
||||||
for row in self._sharing_cache:
|
for row in self._sharing_cache:
|
||||||
if index == 0:
|
if index == 0:
|
||||||
# skip fieldnames
|
# skip fieldnames
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: test: %r", row)
|
||||||
logger.debug("TRACE/sharing/list/row: test: %r", row)
|
|
||||||
if ShareType is not None and row['ShareType'] != ShareType:
|
if ShareType is not None and row['ShareType'] != ShareType:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by ShareType")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by ShareType")
|
|
||||||
pass
|
pass
|
||||||
elif OwnerOrUser is not None and (row['Owner'] != OwnerOrUser and row['User'] != OwnerOrUser):
|
elif OwnerOrUser is not None and (row['Owner'] != OwnerOrUser and row['User'] != OwnerOrUser):
|
||||||
pass
|
pass
|
||||||
elif User is not None and row['User'] != User:
|
elif User is not None and row['User'] != User:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by User")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by User")
|
|
||||||
pass
|
pass
|
||||||
elif PathOrToken is not None and row['PathOrToken'] != PathOrToken:
|
elif PathOrToken is not None and row['PathOrToken'] != PathOrToken:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by PathOrToken")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by PathOrToken")
|
|
||||||
pass
|
pass
|
||||||
elif PathMapped is not None and row['PathMapped'] != PathMapped:
|
elif PathMapped is not None and row['PathMapped'] != PathMapped:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by PathMapped")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by PathMapped")
|
|
||||||
pass
|
pass
|
||||||
elif EnabledByOwner is not None and row['EnabledByOwner'] != EnabledByOwner:
|
elif EnabledByOwner is not None and row['EnabledByOwner'] != EnabledByOwner:
|
||||||
pass
|
pass
|
||||||
@@ -213,8 +204,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
elif Conversion is not None and row['Conversion'] != Conversion:
|
elif Conversion is not None and row['Conversion'] != Conversion:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: add : %r", row)
|
||||||
logger.debug("TRACE/sharing/list/row: add : %r", row)
|
|
||||||
result.append(row)
|
result.append(row)
|
||||||
index += 1
|
index += 1
|
||||||
return result
|
return result
|
||||||
@@ -235,11 +225,9 @@ class Sharing(sharing.BaseSharing):
|
|||||||
row: dict
|
row: dict
|
||||||
|
|
||||||
with self._storage.acquire_lock("w", path=self._sharing_db_file):
|
with self._storage.acquire_lock("w", path=self._sharing_db_file):
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing: ShareType=%r", ShareType)
|
||||||
logger.debug("TRACE/sharing: ShareType=%r", ShareType)
|
|
||||||
if ShareType == "token":
|
if ShareType == "token":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/token/create: PathOrToken=%r Owner=%r PathMapped=%r User=%r Permissions=%r", PathOrToken, Owner, PathMapped, User, Permissions)
|
||||||
logger.debug("TRACE/sharing/token/create: PathOrToken=%r Owner=%r PathMapped=%r User=%r Permissions=%r", PathOrToken, Owner, PathMapped, User, Permissions)
|
|
||||||
# check for duplicate token entry
|
# check for duplicate token entry
|
||||||
for row in self._sharing_cache:
|
for row in self._sharing_cache:
|
||||||
if row['ShareType'] != "token":
|
if row['ShareType'] != "token":
|
||||||
@@ -249,8 +237,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
logger.error("sharing/token/create: PathOrToken already exists: PathOrToken=%r", PathOrToken)
|
logger.error("sharing/token/create: PathOrToken already exists: PathOrToken=%r", PathOrToken)
|
||||||
return {"status": "conflict"}
|
return {"status": "conflict"}
|
||||||
elif ShareType == "map":
|
elif ShareType == "map":
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/map/create: PathOrToken=%r Owner=%r PathMapped=%r User=%r Permissions=%r", PathOrToken, Owner, PathMapped, User, Permissions)
|
||||||
logger.debug("TRACE/sharing/map/create: PathOrToken=%r Owner=%r PathMapped=%r User=%r Permissions=%r", PathOrToken, Owner, PathMapped, User, Permissions)
|
|
||||||
# check for duplicate map entry
|
# check for duplicate map entry
|
||||||
for row in self._sharing_cache:
|
for row in self._sharing_cache:
|
||||||
if row['ShareType'] != "map":
|
if row['ShareType'] != "map":
|
||||||
@@ -279,13 +266,11 @@ class Sharing(sharing.BaseSharing):
|
|||||||
"Actions": Actions,
|
"Actions": Actions,
|
||||||
}
|
}
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/*/create: add row: %r", row)
|
||||||
logger.debug("TRACE/sharing/*/create: add row: %r", row)
|
|
||||||
self._sharing_cache.append(row)
|
self._sharing_cache.append(row)
|
||||||
|
|
||||||
if self._write_csv(self._sharing_db_file):
|
if self._write_csv(self._sharing_db_file):
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/create: write CSV done", ShareType)
|
||||||
logger.debug("TRACE/sharing/%s/create: write CSV done", ShareType)
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
|
|
||||||
logger.error("sharing/%s/create: cannot update CSV database", ShareType)
|
logger.error("sharing/%s/create: cannot update CSV database", ShareType)
|
||||||
@@ -308,8 +293,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
Actions: Union[dict, None] = None,
|
Actions: Union[dict, None] = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
""" update sharing """
|
""" update sharing """
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/update: PathOrToken=%r OwnerOrUser=%r PathMapped=%r Properties=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s", ShareType, PathOrToken, OwnerOrUser, PathMapped, Properties, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser)
|
||||||
logger.debug("TRACE/sharing/%s/update: PathOrToken=%r OwnerOrUser=%r PathMapped=%r Properties=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s", ShareType, PathOrToken, OwnerOrUser, PathMapped, Properties, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser)
|
|
||||||
|
|
||||||
with self._storage.acquire_lock("w", path=self._sharing_db_file):
|
with self._storage.acquire_lock("w", path=self._sharing_db_file):
|
||||||
# lookup token
|
# lookup token
|
||||||
@@ -329,8 +313,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/update: orig row[%d]=%r", ShareType, index, row)
|
||||||
logger.debug("TRACE/sharing/%s/update: orig row[%d]=%r", ShareType, index, row)
|
|
||||||
|
|
||||||
# CSV: remove+adjust+readd
|
# CSV: remove+adjust+readd
|
||||||
if PathMapped is not None:
|
if PathMapped is not None:
|
||||||
@@ -356,12 +339,10 @@ class Sharing(sharing.BaseSharing):
|
|||||||
# update timestamp
|
# update timestamp
|
||||||
self._sharing_cache[index]["TimestampUpdated"] = Timestamp
|
self._sharing_cache[index]["TimestampUpdated"] = Timestamp
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/update: adj row[%d]=%r", ShareType, index, self._sharing_cache[index])
|
||||||
logger.debug("TRACE/sharing/%s/update: adj row[%d]=%r", ShareType, index, self._sharing_cache[index])
|
|
||||||
|
|
||||||
if self._write_csv(self._sharing_db_file):
|
if self._write_csv(self._sharing_db_file):
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/update: write CSV done", ShareType)
|
||||||
logger.debug("TRACE/sharing/%s/update: write CSV done", ShareType)
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
|
|
||||||
logger.error("sharing/%s/update: cannot update CSV database", ShareType)
|
logger.error("sharing/%s/update: cannot update CSV database", ShareType)
|
||||||
@@ -374,16 +355,14 @@ class Sharing(sharing.BaseSharing):
|
|||||||
PathOrToken: str,
|
PathOrToken: str,
|
||||||
User: str) -> dict:
|
User: str) -> dict:
|
||||||
""" delete sharing """
|
""" delete sharing """
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/delete: PathOrToken=%r", ShareType, PathOrToken)
|
||||||
logger.debug("TRACE/sharing/%s/delete: PathOrToken=%r", ShareType, PathOrToken)
|
|
||||||
|
|
||||||
with self._storage.acquire_lock("w", User, path=self._sharing_db_file):
|
with self._storage.acquire_lock("w", User, path=self._sharing_db_file):
|
||||||
# lookup token
|
# lookup token
|
||||||
found = False
|
found = False
|
||||||
index = 0
|
index = 0
|
||||||
for row in self._sharing_cache:
|
for row in self._sharing_cache:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/delete: check: %r", ShareType, row)
|
||||||
logger.debug("TRACE/sharing/%s/delete: check: %r", ShareType, row)
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
# skip fieldnames
|
# skip fieldnames
|
||||||
pass
|
pass
|
||||||
@@ -397,15 +376,11 @@ class Sharing(sharing.BaseSharing):
|
|||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
if found:
|
if found:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/delete: PathOrToken=%r Owner=%r index=%d", ShareType, PathOrToken, row['Owner'], index)
|
||||||
logger.debug("TRACE/sharing/%s/delete: found index=%d", ShareType, index)
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
|
||||||
logger.debug("TRACE/sharing/%s/delete: PathOrToken=%r Owner=%r index=%d", ShareType, PathOrToken, row['Owner'], index)
|
|
||||||
self._sharing_cache.pop(index)
|
self._sharing_cache.pop(index)
|
||||||
|
|
||||||
if self._write_csv(self._sharing_db_file):
|
if self._write_csv(self._sharing_db_file):
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/delete: write CSV done", ShareType)
|
||||||
logger.debug("TRACE/sharing_by_token: write CSV done")
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
|
|
||||||
logger.error("sharing/%s/delete: cannot update CSV database", ShareType)
|
logger.error("sharing/%s/delete: cannot update CSV database", ShareType)
|
||||||
@@ -440,8 +415,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
# convert txt to bool or int
|
# convert txt to bool or int
|
||||||
if self._lines > 0:
|
if self._lines > 0:
|
||||||
for fieldname in row:
|
for fieldname in row:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/_load_csv: test fieldname=%r", fieldname)
|
||||||
logger.debug("TRACE/sharing/_load: test fieldname=%r", fieldname)
|
|
||||||
if fieldname not in sharing.DB_TYPES_V1:
|
if fieldname not in sharing.DB_TYPES_V1:
|
||||||
logger.error("sharing database row error, unsupported fieldname found: %r", fieldname)
|
logger.error("sharing database row error, unsupported fieldname found: %r", fieldname)
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
import urllib
|
import urllib
|
||||||
@@ -93,8 +92,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
User: Union[str, None] = None) -> Union[dict, None]:
|
User: Union[str, None] = None) -> Union[dict, None]:
|
||||||
""" retrieve sharing target and attributes by map """
|
""" retrieve sharing target and attributes by map """
|
||||||
# Lookup
|
# Lookup
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/get: PathOrToken=%r User=%r)", ShareType, PathOrToken, User)
|
||||||
logger.debug("TRACE/sharing/%s/get: PathOrToken=%r User=%r)", ShareType, PathOrToken, User)
|
|
||||||
|
|
||||||
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
||||||
|
|
||||||
@@ -132,8 +130,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
Conversion = row['Conversion']
|
Conversion = row['Conversion']
|
||||||
if 'Actions' in row:
|
if 'Actions' in row:
|
||||||
Actions = row['Actions']
|
Actions = row['Actions']
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing: map %r to %r (Owner=%r User=%r Permissions=%r Hidden=%s Properties=%r)", PathOrToken, PathMapped, Owner, UserShare, Permissions, Hidden, Properties)
|
||||||
logger.debug("TRACE/sharing: map %r to %r (Owner=%r User=%r Permissions=%r Hidden=%s Properties=%r)", PathOrToken, PathMapped, Owner, UserShare, Permissions, Hidden, Properties)
|
|
||||||
return {
|
return {
|
||||||
"mapped": True,
|
"mapped": True,
|
||||||
"ShareType": ShareType,
|
"ShareType": ShareType,
|
||||||
@@ -167,8 +164,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
""" retrieve sharing """
|
""" retrieve sharing """
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s Conversion=%r", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser, Conversion)
|
||||||
logger.debug("TRACE/sharing/list/called: ShareType=%r OwnerOrUser=%r User=%r PathOrToken=%r PathMapped=%r EnabledByOwner=%s EnabledByUser=%s HiddenByOwner=%s HiddenByUser=%s Conversion=%r", ShareType, OwnerOrUser, User, PathOrToken, PathMapped, EnabledByOwner, EnabledByUser, HiddenByOwner, HiddenByUser, Conversion)
|
|
||||||
|
|
||||||
for _ShareType in sharing.SHARE_TYPES_V1:
|
for _ShareType in sharing.SHARE_TYPES_V1:
|
||||||
if ShareType is not None and _ShareType != ShareType:
|
if ShareType is not None and _ShareType != ShareType:
|
||||||
@@ -181,8 +177,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
if not entry.is_file():
|
if not entry.is_file():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list: check file: %r", entry.name)
|
||||||
logger.debug("TRACE/sharing/list: check file: %r", entry.name)
|
|
||||||
# read file
|
# read file
|
||||||
with open(entry, "rb") as fb:
|
with open(entry, "rb") as fb:
|
||||||
(version, row) = pickle.load(fb)
|
(version, row) = pickle.load(fb)
|
||||||
@@ -191,25 +186,20 @@ class Sharing(sharing.BaseSharing):
|
|||||||
# skip
|
# skip
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: test: %r", row)
|
||||||
logger.debug("TRACE/sharing/list/row: test: %r", row)
|
|
||||||
if ShareType is not None and row['ShareType'] != ShareType:
|
if ShareType is not None and row['ShareType'] != ShareType:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by ShareType")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by ShareType")
|
|
||||||
pass
|
pass
|
||||||
elif OwnerOrUser is not None and (row['Owner'] != OwnerOrUser and row['User'] != OwnerOrUser):
|
elif OwnerOrUser is not None and (row['Owner'] != OwnerOrUser and row['User'] != OwnerOrUser):
|
||||||
pass
|
pass
|
||||||
elif User is not None and row['User'] != User:
|
elif User is not None and row['User'] != User:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by User")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by User")
|
|
||||||
pass
|
pass
|
||||||
elif PathOrToken is not None and row['PathOrToken'] != PathOrToken:
|
elif PathOrToken is not None and row['PathOrToken'] != PathOrToken:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by PathOrToken")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by PathOrToken")
|
|
||||||
pass
|
pass
|
||||||
elif PathMapped is not None and row['PathMapped'] != PathMapped:
|
elif PathMapped is not None and row['PathMapped'] != PathMapped:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: skip by PathMapped")
|
||||||
logger.debug("TRACE/sharing/list/row: skip by PathMapped")
|
|
||||||
pass
|
pass
|
||||||
elif EnabledByOwner is not None and row['EnabledByOwner'] != EnabledByOwner:
|
elif EnabledByOwner is not None and row['EnabledByOwner'] != EnabledByOwner:
|
||||||
pass
|
pass
|
||||||
@@ -222,8 +212,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
elif Conversion is not None and row['Conversion'] != Conversion:
|
elif Conversion is not None and row['Conversion'] != Conversion:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/list/row: add: %r", row)
|
||||||
logger.debug("TRACE/sharing/list/row: add: %r", row)
|
|
||||||
result.append(row)
|
result.append(row)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@@ -245,9 +234,8 @@ class Sharing(sharing.BaseSharing):
|
|||||||
|
|
||||||
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/create: sharing_config_file=%r", ShareType, sharing_config_file)
|
||||||
logger.debug("TRACE/sharing/%s/create: sharing_config_file=%r", ShareType, sharing_config_file)
|
logger.trace("sharing/%s/create: PathOrToken=%r Owner=%r PathMapped=%r User=%r Permissions=%r", ShareType, PathOrToken, Owner, PathMapped, User, Permissions)
|
||||||
logger.debug("TRACE/sharing/%s/create: PathOrToken=%r Owner=%r PathMapped=%r User=%r Permissions=%r", ShareType, PathOrToken, Owner, PathMapped, User, Permissions)
|
|
||||||
if os.path.isfile(sharing_config_file):
|
if os.path.isfile(sharing_config_file):
|
||||||
return {"status": "conflict"}
|
return {"status": "conflict"}
|
||||||
|
|
||||||
@@ -272,13 +260,11 @@ class Sharing(sharing.BaseSharing):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
with self._storage.acquire_lock("w", Owner, path=sharing_config_file):
|
with self._storage.acquire_lock("w", Owner, path=sharing_config_file):
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/create: store share-config: %r into file %r", ShareType, row, sharing_config_file)
|
||||||
logger.debug("TRACE/sharing/%s/create: store share-config: %r into file %r", ShareType, row, sharing_config_file)
|
|
||||||
# write file
|
# write file
|
||||||
with open(sharing_config_file, "wb") as fb:
|
with open(sharing_config_file, "wb") as fb:
|
||||||
pickle.dump((version, row), fb)
|
pickle.dump((version, row), fb)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/*/create: share-config file stored: %r", sharing_config_file)
|
||||||
logger.debug("TRACE/sharing/*/create: share-config file stored: %r", sharing_config_file)
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("sharing/%s/create: cannot store share-config: %r (%r)", ShareType, sharing_config_file, e)
|
logger.error("sharing/%s/create: cannot store share-config: %r (%r)", ShareType, sharing_config_file, e)
|
||||||
@@ -301,8 +287,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
Actions: Union[dict, None] = None,
|
Actions: Union[dict, None] = None,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
""" update sharing """
|
""" update sharing """
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/update: PathOrToken=%r OwnerOrUser=%r User=%r Properties=%r", ShareType, PathOrToken, OwnerOrUser, User, Properties)
|
||||||
logger.debug("TRACE/sharing/%s/update: PathOrToken=%r OwnerOrUser=%r User=%r Properties=%r", ShareType, PathOrToken, OwnerOrUser, User, Properties)
|
|
||||||
|
|
||||||
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
||||||
|
|
||||||
@@ -318,11 +303,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
if version != DB_VERSION:
|
if version != DB_VERSION:
|
||||||
return {"status": "error"}
|
return {"status": "error"}
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/update: orig row=%r", ShareType, row)
|
||||||
logger.debug("TRACE/sharing/%s/update: check: %r", ShareType, row)
|
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
|
||||||
logger.debug("TRACE/sharing/%s/update: orig row=%r", ShareType, row)
|
|
||||||
|
|
||||||
if PathMapped is not None:
|
if PathMapped is not None:
|
||||||
row["PathMapped"] = PathMapped
|
row["PathMapped"] = PathMapped
|
||||||
@@ -347,14 +328,13 @@ class Sharing(sharing.BaseSharing):
|
|||||||
# update timestamp
|
# update timestamp
|
||||||
row["TimestampUpdated"] = Timestamp
|
row["TimestampUpdated"] = Timestamp
|
||||||
|
|
||||||
logger.debug("TRACE/sharing/%s/update: adj row=%r", ShareType, row)
|
logger.trace("sharing/%s/update: adj row=%r", ShareType, row)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# write file
|
# write file
|
||||||
with open(sharing_config_file, "wb") as fb:
|
with open(sharing_config_file, "wb") as fb:
|
||||||
pickle.dump((version, row), fb)
|
pickle.dump((version, row), fb)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/create: share-config file stored: %r", ShareType, sharing_config_file)
|
||||||
logger.debug("TRACE/sharing/%s/create: share-config file stored: %r", ShareType, sharing_config_file)
|
|
||||||
return {"status": "success"}
|
return {"status": "success"}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("sharing/%s/create: cannot store share-config: %r (%r)", ShareType, sharing_config_file, e)
|
logger.error("sharing/%s/create: cannot store share-config: %r (%r)", ShareType, sharing_config_file, e)
|
||||||
@@ -365,8 +345,7 @@ class Sharing(sharing.BaseSharing):
|
|||||||
PathOrToken: str,
|
PathOrToken: str,
|
||||||
User: str) -> dict:
|
User: str) -> dict:
|
||||||
""" delete sharing """
|
""" delete sharing """
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
logger.trace("sharing/%s/delete: PathOrToken=%r", ShareType, PathOrToken)
|
||||||
logger.debug("TRACE/sharing/%s/delete: PathOrToken=%r", ShareType, PathOrToken)
|
|
||||||
|
|
||||||
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
sharing_config_file = os.path.join(self._sharing_database_path_ShareType[ShareType], self._encode_path(PathOrToken))
|
||||||
|
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ class Sharing(sharing.BaseSharing):
|
|||||||
def get_sharing_collection_by_token(self, token: str) -> Union[dict, None]:
|
def get_sharing_collection_by_token(self, token: str) -> Union[dict, None]:
|
||||||
""" retrieve target and attributs by token """
|
""" retrieve target and attributs by token """
|
||||||
# default
|
# default
|
||||||
logger.debug("TRACE/sharing_by_token: 'none' cannot provide any map for token: %r", token)
|
logger.trace("sharing/collection_by_token: 'none' cannot provide any map for token: %r", token)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_sharing_collection_by_map(self, path) -> Union[dict, None]:
|
def get_sharing_collection_by_map(self, path) -> Union[dict, None]:
|
||||||
""" retrieve target and attributs by map """
|
""" retrieve target and attributs by map """
|
||||||
logger.debug("TRACE/sharing_by_map: 'none' cannot provide any map for path: %r", path)
|
logger.trace("sharing/collection_by_map: 'none' cannot provide any map for path: %r", path)
|
||||||
return {"mapped": False}
|
return {"mapped": False}
|
||||||
|
|||||||
Reference in New Issue
Block a user