mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00

In PR-2894[1] we isolated botdetection from the limiter, this PR isolates the botdetection from the SearXNG core code. This PR also fixes the issue [2] that the ``server.public_instance`` option needs to activate the limiter. - [1] https://github.com/searxng/searxng/pull/2894 - [2] https://github.com/searxng/searxng/issues/2975 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
23 lines
654 B
Python
23 lines
654 B
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
# lint: pylint
|
|
"""A collection of convenient functions and redis/lua scripts.
|
|
"""
|
|
|
|
import hmac
|
|
|
|
from searx import get_setting
|
|
|
|
|
|
def secret_hash(name: str):
|
|
"""Creates a hash of the ``name``.
|
|
|
|
Combines argument ``name`` with the ``secret_key`` from :ref:`settings
|
|
server`. This function can be used to get a more anonymized name of a Redis
|
|
KEY.
|
|
|
|
:param name: the name to create a secret hash for
|
|
:type name: str
|
|
"""
|
|
m = hmac.new(bytes(name, encoding='utf-8'), digestmod='sha256')
|
|
m.update(bytes(get_setting('server.secret_key'), encoding='utf-8'))
|
|
return m.hexdigest()
|