Skip to main content

Admin extension for V2Hub VPN Subscription API client

Project description

V2Hub Admin - Admin Extension for VPN Subscription API

Admin API extension for V2Hub with HMAC-SHA256 authentication for privileged operations.

Features

  • 🔐 HMAC Authentication: SHA-256 signature-based authentication
  • 🎯 Admin Operations: Manage all subscriptions across the system
  • 🔄 Async & Sync: Both AsyncAdminClient and AdminClient
  • 📦 Inherits V2Hub: Built on top of the main v2hub library
  • 🛡️ Type Safe: Full type hints and Pydantic models

Installation

# Install v2hub-admin (will automatically install v2hub as dependency)
pip install v2hub-admin

Quick Start

Async Usage

from v2hub_admin import AsyncAdminClient

async with AsyncAdminClient(
    base_url="https://api.example.com",
    api_token="your-admin-token",
    hmac_secret="your-hmac-secret"
) as admin:
    # List all subscriptions in the system
    all_subs = await admin.list_all_subscriptions()

    # Get any subscription by token
    sub = await admin.get_any_subscription("sub_token_123")

    # Delete any subscription (admin privilege)
    await admin.delete_any_subscription("sub_token_123")

Sync Usage

from v2hub_admin import AdminClient

with AdminClient(
    base_url="https://api.example.com",
    api_token="your-admin-token",
    hmac_secret="your-hmac-secret"
) as admin:
    # List all subscriptions
    all_subs = admin.list_all_subscriptions()

    # Get statistics
    stats = admin.get_statistics()
    print(f"Total subscriptions: {stats['total_subscriptions']}")

HMAC Authentication

The admin client uses HMAC-SHA256 for request signing:

import hmac
import hashlib
from datetime import datetime

# The library handles this automatically
# This is just for understanding

timestamp = datetime.utcnow().isoformat()
message = f"DELETE:/admin/subscriptions/{token}:{timestamp}"
signature = hmac.new(
    secret.encode(),
    message.encode(),
    hashlib.sha256
).hexdigest()

Admin API Endpoints

Subscriptions

  • list_all_subscriptions() - List all subscriptions in system
  • get_any_subscription(token) - Get any subscription (bypass ownership)
  • delete_any_subscription(token) - Delete any subscription (admin privilege)

Statistics (if available)

  • get_statistics() - Get system-wide statistics
  • get_user_stats(user_id) - Get stats for specific user

Error Handling

Inherits all exception types from v2hub:

from v2hub import VPNAPIError, AuthenticationError, AuthorizationError
from v2hub_admin import AsyncAdminClient

async with AsyncAdminClient(base_url, token, secret) as admin:
    try:
        await admin.delete_any_subscription("token123")
    except AuthenticationError:
        print("Invalid HMAC signature or credentials")
    except AuthorizationError:
        print("Insufficient admin privileges")
    except VPNAPIError as e:
        print(f"API error: {e}")

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Type checking
mypy src/

Requirements

  • v2hub >= 1.0.0 (automatically installed)
  • Python >= 3.9

CLI Integration

Works seamlessly with v2hub-cli:

# Install CLI with admin support
pip install v2hub-cli[admin]

# Use admin commands
v2hub admin list-all
v2hub admin delete-any <token>
v2hub admin stats

Security Notes

⚠️ Important:

  • Store HMAC secrets securely (environment variables, secret managers)
  • Never commit secrets to version control
  • Use HTTPS in production
  • Rotate secrets regularly
  • Admin tokens have elevated privileges - protect them carefully

License

MIT License - see LICENSE file for details.

Author

nestt

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

v2hub_admin-1.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

v2hub_admin-1.0.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file v2hub_admin-1.0.0.tar.gz.

File metadata

  • Download URL: v2hub_admin-1.0.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for v2hub_admin-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5b17a9e299f536cd870efd6d39ef706f2af701d84eda06c2c2647fbaca5b0b0b
MD5 7105d4ff393327337fa2998f4c46dfc4
BLAKE2b-256 86aa6c17acb1726ddadd331d6b2e2d18d5d92eb8b1f057e40b617638ad06a8ec

See more details on using hashes here.

File details

Details for the file v2hub_admin-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: v2hub_admin-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for v2hub_admin-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74bee531956ee3407bf688e8e1cf1db5691fdb703cf08633697182350e72877b
MD5 2eb4e5ad34cbef60d81eeea23ea023cb
BLAKE2b-256 5f68a228c9d274788ed91c91b72f3595cb2f281679f9d22022fe0e9fec20e576

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