Python SDK for Report Service.
Project description
Exnodes Report Service SDK
Version: 0.1.0
Khởi tạo client - install SDK
from exn_salon_report_sdk import ReportClient, ReportSDKException
api_key = "your_api_key"
secret_key = "your_secret_key"
client = ReportClient(api_key, secret_key)
# Gọi API để lấy báo cáo
try:
report_id = "12345"
report = client.get_report(report_id)
print("Report:", report)
# Tạo mới một báo cáo
new_report_data = {
"name": "Sales Report",
"filters": {"date_range": "2025-01-01 to 2025-01-20"},
}
new_report = client.create_report(new_report_data)
print("New Report Created:", new_report)
except ReportSDKException as e:
print("SDK Error:", str(e))
Xử lý phía Service Report
1. Lấy API key từ header.
api_key = request.headers.get("API-Key")
if not api_key:
return {"error": "API key is required"}, 401
secret_key = get_secret_key_from_db(api_key)
if not secret_key:
return {"error": "Invalid API key"}, 401
2. Xác minh chữ ký
import hmac
import hashlib
import base64
def verify_signature(secret_key, signature_payload, signature):
expected_signature = hmac.new(
secret_key.encode(),
signature_payload.encode(),
hashlib.sha256
).digest()
expected_signature = base64.b64encode(expected_signature).decode()
return hmac.compare_digest(expected_signature, signature)
# Xử lý chữ ký
signature_payload = f"{api_key}{timestamp}{request_payload}"
if not verify_signature(secret_key, signature_payload, received_signature):
return {"error": "Invalid signature"}, 401
3. Kiểm tra timestamp (chống replay attack):
from datetime import datetime, timedelta
def is_timestamp_valid(request_timestamp, max_skew_minutes=5):
try:
timestamp = datetime.fromisoformat(request_timestamp)
now = datetime.utcnow()
return abs((now - timestamp).total_seconds()) <= max_skew_minutes * 60
except ValueError:
return False
if not is_timestamp_valid(timestamp):
return {"error": "Invalid or expired timestamp"}, 401
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
exn_report_sdk-0.1.15.tar.gz
(7.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exn_report_sdk-0.1.15.tar.gz.
File metadata
- Download URL: exn_report_sdk-0.1.15.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59a68c4f866700716ad586184c010ee5adcf5ee830a938ae995a0a0622d3b512
|
|
| MD5 |
7f2dafa50305b04e3f3c60e052c46f35
|
|
| BLAKE2b-256 |
bfbaf7e87f5f749d100bd54f26ceda9482c5dbf076a8c48f8b06804369db170a
|
File details
Details for the file exn_report_sdk-0.1.15-py3-none-any.whl.
File metadata
- Download URL: exn_report_sdk-0.1.15-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dce73e895aac70ea634dd6e9f031b1826a1d9b82fcc0025603426284cb3f1bc4
|
|
| MD5 |
674745f2aaf6ac41fa5d617a1ff9d6ea
|
|
| BLAKE2b-256 |
197b041a2dd545aff0b617e71606d3b19f0fc720a83282b2bb6b57ea92875b7e
|