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