Skip to main content

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


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.12.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exn_report_sdk-0.1.12-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file exn_report_sdk-0.1.12.tar.gz.

File metadata

  • Download URL: exn_report_sdk-0.1.12.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for exn_report_sdk-0.1.12.tar.gz
Algorithm Hash digest
SHA256 cba310904bbe2ef9f2ce73940b9c83556a181bdc93c74d7fe1f5226d08503114
MD5 ff308a3d9d383c588e3064d2448f8426
BLAKE2b-256 52f4c2b912326d140d11b0c1c10f6daee07b75a05609fbd066b85242249d95b0

See more details on using hashes here.

File details

Details for the file exn_report_sdk-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for exn_report_sdk-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 636af3c76f72d209e56774933196ec25b85a1e9e4408b922f4f928271e8c605d
MD5 4dc6250f3fd42804ad2b61dab65015e6
BLAKE2b-256 68a7203abdf90f6d40326e00b87a6cf921e921f1d8f5e2e40f997abef957a529

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page