Name | exn-report-sdk JSON |
Version |
0.1.4
JSON |
| download |
home_page | None |
Summary | Python SDK for Report Service. |
upload_time | 2025-01-21 07:39:59 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT |
keywords |
report
sdk
api
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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
```
Raw data
{
"_id": null,
"home_page": null,
"name": "exn-report-sdk",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "report, sdk, api",
"author": null,
"author_email": "Exnodes <ryan@exnodes.vn>",
"download_url": "https://files.pythonhosted.org/packages/e3/3d/d0a18a04a7a721c4c8fa75b551a519d67daeedac44ee173aefc70ad9b7f7/exn_report_sdk-0.1.4.tar.gz",
"platform": null,
"description": "# Exnodes Report Service SDK\n\nVersion: 0.1.0\n\n# Kh\u1edfi t\u1ea1o client - install SDK\n```\nfrom exn_salon_report_sdk import ReportClient, ReportSDKException\n\napi_key = \"your_api_key\"\nsecret_key = \"your_secret_key\"\nclient = ReportClient(api_key, secret_key)\n\n# G\u1ecdi API \u0111\u1ec3 l\u1ea5y b\u00e1o c\u00e1o\ntry:\n report_id = \"12345\"\n report = client.get_report(report_id)\n print(\"Report:\", report)\n\n # T\u1ea1o m\u1edbi m\u1ed9t b\u00e1o c\u00e1o\n new_report_data = {\n \"name\": \"Sales Report\",\n \"filters\": {\"date_range\": \"2025-01-01 to 2025-01-20\"},\n }\n new_report = client.create_report(new_report_data)\n print(\"New Report Created:\", new_report)\n \nexcept ReportSDKException as e:\n print(\"SDK Error:\", str(e))\n```\n\n---------------------------------\n\n\n# X\u1eed l\u00fd ph\u00eda Service Report\n## 1. L\u1ea5y API key t\u1eeb header.\n```\napi_key = request.headers.get(\"API-Key\")\nif not api_key:\n return {\"error\": \"API key is required\"}, 401\n\nsecret_key = get_secret_key_from_db(api_key)\nif not secret_key:\n return {\"error\": \"Invalid API key\"}, 401\n\n```\n\n## 2. X\u00e1c minh ch\u1eef k\u00fd\n```\nimport hmac\nimport hashlib\nimport base64\n\ndef verify_signature(secret_key, signature_payload, signature):\n expected_signature = hmac.new(\n secret_key.encode(), \n signature_payload.encode(), \n hashlib.sha256\n ).digest()\n expected_signature = base64.b64encode(expected_signature).decode()\n return hmac.compare_digest(expected_signature, signature)\n\n# X\u1eed l\u00fd ch\u1eef k\u00fd\nsignature_payload = f\"{api_key}{timestamp}{request_payload}\"\nif not verify_signature(secret_key, signature_payload, received_signature):\n return {\"error\": \"Invalid signature\"}, 401\n```\n\n## 3. Ki\u1ec3m tra timestamp (ch\u1ed1ng replay attack):\n```\nfrom datetime import datetime, timedelta\n\ndef is_timestamp_valid(request_timestamp, max_skew_minutes=5):\n try:\n timestamp = datetime.fromisoformat(request_timestamp)\n now = datetime.utcnow()\n return abs((now - timestamp).total_seconds()) <= max_skew_minutes * 60\n except ValueError:\n return False\n\nif not is_timestamp_valid(timestamp):\n return {\"error\": \"Invalid or expired timestamp\"}, 401\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python SDK for Report Service.",
"version": "0.1.4",
"project_urls": {
"Homepage": "https://github.com/Salonbookly/Report-SDK"
},
"split_keywords": [
"report",
" sdk",
" api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a7d315d34e85e2d8cbb06c331380a03d4130345b462dce31fa607b7aeaa37434",
"md5": "8a33119decaf9141d576037c1d757f89",
"sha256": "53d082d92740976238bc60c8e556d745ec34dfbf78d0545ce02f09728819f2a5"
},
"downloads": -1,
"filename": "exn_report_sdk-0.1.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8a33119decaf9141d576037c1d757f89",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 4521,
"upload_time": "2025-01-21T07:39:58",
"upload_time_iso_8601": "2025-01-21T07:39:58.043871Z",
"url": "https://files.pythonhosted.org/packages/a7/d3/15d34e85e2d8cbb06c331380a03d4130345b462dce31fa607b7aeaa37434/exn_report_sdk-0.1.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e33dd0a18a04a7a721c4c8fa75b551a519d67daeedac44ee173aefc70ad9b7f7",
"md5": "d92f20bc591b27b2c545877626d4f19b",
"sha256": "30c19d1d648fdfbfe5432191fbbae99c0791589057b0aa167b5482fd9011f309"
},
"downloads": -1,
"filename": "exn_report_sdk-0.1.4.tar.gz",
"has_sig": false,
"md5_digest": "d92f20bc591b27b2c545877626d4f19b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 3411,
"upload_time": "2025-01-21T07:39:59",
"upload_time_iso_8601": "2025-01-21T07:39:59.615895Z",
"url": "https://files.pythonhosted.org/packages/e3/3d/d0a18a04a7a721c4c8fa75b551a519d67daeedac44ee173aefc70ad9b7f7/exn_report_sdk-0.1.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 07:39:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Salonbookly",
"github_project": "Report-SDK",
"github_not_found": true,
"lcname": "exn-report-sdk"
}