diff --git a/.changeset/pre.json b/.changeset/pre.json index bfa3dc3e..d1488516 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -1,5 +1,5 @@ { - "mode": "pre", + "mode": "exit", "tag": "dev", "initialVersions": { "fingerprint-pro-server-api-python-sdk": "7.1.0" diff --git a/.changeset/rude-kids-rhyme.md b/.changeset/rude-kids-rhyme.md new file mode 100644 index 00000000..1c797ae3 --- /dev/null +++ b/.changeset/rude-kids-rhyme.md @@ -0,0 +1,6 @@ +--- +"fingerprint-pro-server-api-python-sdk": major +--- + +Rename `Webhook` class to `WebhookValidation`. +Right now, `Webhook` class points to the actual data model. diff --git a/README.md b/README.md index 82a42109..62c5b575 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ This SDK provides utility method for verifying the HMAC signature of the incomin ```python import os from flask import Flask, request, jsonify -from fingerprint_pro_server_api_sdk import Webhook +from fingerprint_pro_server_api_sdk import WebhookValidation app = Flask(__name__) @@ -229,7 +229,7 @@ def webhook_handler(): data = request.get_data() # Validate the webhook signature - is_valid = Webhook.is_valid_webhook_signature(header, data, secret) + is_valid = WebhookValidation.is_valid_webhook_signature(header, data, secret) if not is_valid: return jsonify({"message": "Webhook signature is invalid."}), 403 diff --git a/fingerprint_pro_server_api_sdk/__init__.py b/fingerprint_pro_server_api_sdk/__init__.py index e9291bbc..2be993c8 100644 --- a/fingerprint_pro_server_api_sdk/__init__.py +++ b/fingerprint_pro_server_api_sdk/__init__.py @@ -124,6 +124,6 @@ from fingerprint_pro_server_api_sdk.models.webhook_velocity import WebhookVelocity from fingerprint_pro_server_api_sdk.models.webhook_virtual_machine import WebhookVirtualMachine # import custom methods into sdk package -from fingerprint_pro_server_api_sdk.webhook import Webhook +from fingerprint_pro_server_api_sdk.webhook_validation import WebhookValidation from fingerprint_pro_server_api_sdk.sealed import ApiClientDeserializer, DecryptionAlgorithm, DecryptionKey, \ UnsealError, UnsealAggregateError, unseal_event_response diff --git a/fingerprint_pro_server_api_sdk/webhook.py b/fingerprint_pro_server_api_sdk/webhook_validation.py similarity index 88% rename from fingerprint_pro_server_api_sdk/webhook.py rename to fingerprint_pro_server_api_sdk/webhook_validation.py index 3ee43b09..cf684f09 100644 --- a/fingerprint_pro_server_api_sdk/webhook.py +++ b/fingerprint_pro_server_api_sdk/webhook_validation.py @@ -2,7 +2,7 @@ import hashlib -class Webhook: +class WebhookValidation: """Manages work with webhooks.""" @staticmethod def is_valid_hmac_signature(signature: str, data: bytes, secret: str) -> bool: @@ -23,7 +23,7 @@ def is_valid_webhook_signature(header: str, data: bytes, secret: str) -> bool: parts = signature.split('=') if len(parts) == 2: version, hash_value = parts - if version == "v1" and Webhook.is_valid_hmac_signature(hash_value, data, secret): + if version == "v1" and WebhookValidation.is_valid_hmac_signature(hash_value, data, secret): return True return False diff --git a/template/README.mustache b/template/README.mustache index a8edc9b7..983010ff 100644 --- a/template/README.mustache +++ b/template/README.mustache @@ -214,7 +214,7 @@ This SDK provides utility method for verifying the HMAC signature of the incomin ```python import os from flask import Flask, request, jsonify -from fingerprint_pro_server_api_sdk import Webhook +from fingerprint_pro_server_api_sdk import WebhookValidation app = Flask(__name__) @@ -235,7 +235,7 @@ def webhook_handler(): data = request.get_data() # Validate the webhook signature - is_valid = Webhook.is_valid_webhook_signature(header, data, secret) + is_valid = WebhookValidation.is_valid_webhook_signature(header, data, secret) if not is_valid: return jsonify({"message": "Webhook signature is invalid."}), 403 diff --git a/template/__init__package.mustache b/template/__init__package.mustache index 58f8e5ed..4c318079 100644 --- a/template/__init__package.mustache +++ b/template/__init__package.mustache @@ -16,6 +16,6 @@ from {{packageName}}.base_model import BaseModel {{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}} {{/model}}{{/models}} # import custom methods into sdk package -from {{packageName}}.webhook import Webhook +from {{packageName}}.webhook_validation import WebhookValidation from {{packageName}}.sealed import ApiClientDeserializer, DecryptionAlgorithm, DecryptionKey, \ UnsealError, UnsealAggregateError, unseal_event_response diff --git a/test/test_webhook_validation.py b/test/test_webhook_validation.py index 90f7f696..6cfea69d 100644 --- a/test/test_webhook_validation.py +++ b/test/test_webhook_validation.py @@ -1,6 +1,6 @@ import unittest -from fingerprint_pro_server_api_sdk import Webhook +from fingerprint_pro_server_api_sdk import WebhookValidation class TestWebhookValidation(unittest.TestCase): @@ -10,31 +10,31 @@ class TestWebhookValidation(unittest.TestCase): data = b"data" def test_valid_header(self): - result = Webhook.is_valid_webhook_signature(self.valid_header, self.data, self.secret) + result = WebhookValidation.is_valid_webhook_signature(self.valid_header, self.data, self.secret) self.assertTrue(result) def test_invalid_header(self): - result = Webhook.is_valid_webhook_signature("v2=invalid", self.data, self.secret) + result = WebhookValidation.is_valid_webhook_signature("v2=invalid", self.data, self.secret) self.assertFalse(result) def test_header_without_version(self): - result = Webhook.is_valid_webhook_signature("invalid", self.data, self.secret) + result = WebhookValidation.is_valid_webhook_signature("invalid", self.data, self.secret) self.assertFalse(result) def test_header_with_unsupported_version(self): - result = Webhook.is_valid_webhook_signature(self.valid_header_v2, self.data, self.secret) + result = WebhookValidation.is_valid_webhook_signature(self.valid_header_v2, self.data, self.secret) self.assertFalse(result) def test_empty_header(self): - result = Webhook.is_valid_webhook_signature("", self.data, self.secret) + result = WebhookValidation.is_valid_webhook_signature("", self.data, self.secret) self.assertFalse(result) def test_empty_secret(self): - result = Webhook.is_valid_webhook_signature("invalid", self.data, "") + result = WebhookValidation.is_valid_webhook_signature("invalid", self.data, "") self.assertFalse(result) def test_empty_data(self): - result = Webhook.is_valid_webhook_signature(self.valid_header, b"", self.secret) + result = WebhookValidation.is_valid_webhook_signature(self.valid_header, b"", self.secret) self.assertFalse(result) diff --git a/webhook_signature_example.py b/webhook_signature_example.py index fadf8099..c069c174 100644 --- a/webhook_signature_example.py +++ b/webhook_signature_example.py @@ -1,9 +1,9 @@ -from fingerprint_pro_server_api_sdk import Webhook +from fingerprint_pro_server_api_sdk import WebhookValidation header = "v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db" secret = "secret" data = b"data" -is_valid = Webhook.is_valid_webhook_signature(header, data, secret) +is_valid = WebhookValidation.is_valid_webhook_signature(header, data, secret) print("Webhook signature is correct!" if is_valid else "Webhook signature is incorrect!")