|
| 1 | +""" |
| 2 | +Exoscale Partner API client |
| 3 | +
|
| 4 | +This module provides a client for the Exoscale Partner API, which allows |
| 5 | +distributors to manage sub-organizations. |
| 6 | +""" |
| 7 | + |
| 8 | +import json |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | +from .generator import create_client_class |
| 12 | +from .v2 import Client as V2Client |
| 13 | + |
| 14 | + |
| 15 | +with open(Path(__file__).parent.parent / "partner-api.json", "r") as f: |
| 16 | + partner_api_spec = json.load(f) |
| 17 | + BasePartnerClient = create_client_class(partner_api_spec) |
| 18 | + |
| 19 | + |
| 20 | +class Client(BasePartnerClient): |
| 21 | + """ |
| 22 | + Partner API client with Exoscale authentication. |
| 23 | +
|
| 24 | + This client provides access to distributor operations for managing |
| 25 | + sub-organizations. It uses the same authentication mechanism as the |
| 26 | + V2 API client. |
| 27 | +
|
| 28 | + Args: |
| 29 | + key (str): Exoscale API key |
| 30 | + secret (str): Exoscale API secret |
| 31 | + url (str): Override endpoint URL (optional) |
| 32 | + zone (str): Exoscale zone (optional) |
| 33 | +
|
| 34 | + Example: |
| 35 | + >>> from exoscale.api.partner import Client |
| 36 | + >>> client = Client("EXO...", "secret") |
| 37 | + >>> orgs = client.list_distributor_organizations() |
| 38 | + """ |
| 39 | + |
| 40 | + def __init__(self, key, secret, *args, url=None, **kwargs): |
| 41 | + # Initialize with Partner API endpoint |
| 42 | + partner_url = ( |
| 43 | + url if url else "https://partner-api.exoscale.com/v1.alpha" |
| 44 | + ) |
| 45 | + super().__init__(*args, url=partner_url, **kwargs) |
| 46 | + |
| 47 | + # Reuse the v2 client's authentication mechanism |
| 48 | + v2_client = V2Client(key, secret, *args, url=url, **kwargs) |
| 49 | + |
| 50 | + self.http_client = v2_client.http_client |
| 51 | + self.key = key |
| 52 | + |
| 53 | + self._v2_client = v2_client |
| 54 | + |
| 55 | + def __repr__(self): |
| 56 | + return ( |
| 57 | + f"<Client endpoint={self.endpoint} " |
| 58 | + f"key={self.key} secret=**masked**>" |
| 59 | + ) |
0 commit comments