mirror of
https://github.com/remnawave/python-sdk.git
synced 2026-08-04 14:37:36 +00:00
feat: Update version to 1.0.7 in pyproject.toml; add WebhookUtility for webhook validation
This commit is contained in:
parent
167eca47de
commit
15ae9e6a20
4 changed files with 37 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "remnawave-api"
|
||||
version = "1.0.6"
|
||||
version = "1.0.7"
|
||||
description = "A Python SDK for interacting with the Remnawave API."
|
||||
authors = [
|
||||
{name = "Artem",email = "sm1ky@forestsnet.com"}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ from remnawave_api.controllers import (
|
|||
UsersController,
|
||||
UsersStatsController,
|
||||
XrayConfigController,
|
||||
WebhookUtility,
|
||||
# WebhookUtility is not a controller, but it's included in the controllers module for convenience
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from .users import UsersController
|
|||
from .users_bulk_actions import UsersBulkActionsController
|
||||
from .users_stats import UsersStatsController
|
||||
from .xray_config import XrayConfigController
|
||||
from .webhooks import WebhookUtility
|
||||
|
||||
__all__ = [
|
||||
"APITokensManagementController",
|
||||
|
|
@ -34,4 +35,5 @@ __all__ = [
|
|||
"UsersBulkActionsController",
|
||||
"UsersStatsController",
|
||||
"XrayConfigController",
|
||||
"WebhookUtility"
|
||||
]
|
||||
|
|
|
|||
32
remnawave_api/controllers/webhooks.py
Normal file
32
remnawave_api/controllers/webhooks.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import hmac
|
||||
import hashlib
|
||||
import json
|
||||
from typing import Union
|
||||
|
||||
class WebhookUtility:
|
||||
@staticmethod
|
||||
def validate_webhook(
|
||||
body: Union[str, dict],
|
||||
signature: str,
|
||||
webhook_secret: str
|
||||
) -> bool:
|
||||
"""
|
||||
Validates the webhook's authenticity using HMAC SHA-256.
|
||||
|
||||
:param body: The webhook request body (either a JSON string or a parsed dictionary).
|
||||
:param signature: The signature received from the server.
|
||||
:param webhook_secret: The secret key used to compute the HMAC.
|
||||
:return: True if the signature matches, otherwise False.
|
||||
"""
|
||||
if isinstance(body, str):
|
||||
original_body = body
|
||||
else:
|
||||
original_body = json.dumps(body, separators=(',', ':'))
|
||||
|
||||
computed_signature = hmac.new(
|
||||
webhook_secret.encode('utf-8'),
|
||||
original_body.encode('utf-8'),
|
||||
hashlib.sha256
|
||||
).hexdigest()
|
||||
|
||||
return hmac.compare_digest(computed_signature, signature)
|
||||
Loading…
Add table
Add a link
Reference in a new issue