sharing/token/resolver: add delay in case token was not found
This commit is contained in:
@@ -19,8 +19,10 @@ import base64
|
|||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from csv import DictWriter
|
from csv import DictWriter
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -138,6 +140,7 @@ class BaseSharing:
|
|||||||
|
|
||||||
_storage: storage.BaseStorage
|
_storage: storage.BaseStorage
|
||||||
_rights: rights.BaseRights
|
_rights: rights.BaseRights
|
||||||
|
_auth_delay: float
|
||||||
_enabled: bool = False
|
_enabled: bool = False
|
||||||
default_permissions_create_token: str
|
default_permissions_create_token: str
|
||||||
default_permissions_create_map: str
|
default_permissions_create_map: str
|
||||||
@@ -154,6 +157,7 @@ class BaseSharing:
|
|||||||
self.configuration = configuration
|
self.configuration = configuration
|
||||||
self._rights = rights.load(configuration)
|
self._rights = rights.load(configuration)
|
||||||
self._storage = storage.load(configuration)
|
self._storage = storage.load(configuration)
|
||||||
|
self._auth_delay = configuration.get("auth", "delay")
|
||||||
# Sharing
|
# Sharing
|
||||||
self.sharing_collection_by_map = configuration.get("sharing", "collection_by_map")
|
self.sharing_collection_by_map = configuration.get("sharing", "collection_by_map")
|
||||||
self.sharing_collection_by_token = configuration.get("sharing", "collection_by_token")
|
self.sharing_collection_by_token = configuration.get("sharing", "collection_by_token")
|
||||||
@@ -388,6 +392,10 @@ class BaseSharing:
|
|||||||
if share is None:
|
if share is None:
|
||||||
share = self.sharing_collection_by_token_resolver(path)
|
share = self.sharing_collection_by_token_resolver(path)
|
||||||
if share is not None and 'error' in share:
|
if share is not None and 'error' in share:
|
||||||
|
if self._auth_delay > 0:
|
||||||
|
random_delay = self._auth_delay * (1 + random.random())
|
||||||
|
logger.debug("Failed shared-by-token resolver, sleeping random: %.3f sec", random_delay)
|
||||||
|
time.sleep(random_delay)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
|
|||||||
Reference in New Issue
Block a user