|
| 1 | +from typing import Any, Dict, Optional, Union |
| 2 | +import uuid |
| 3 | + |
| 4 | +from .calls import make_request, InvalidUrlSpec |
| 5 | +from .data import Method, Role, BugoutHumbugIntegrationsList |
| 6 | +from .settings import REQUESTS_TIMEOUT |
| 7 | + |
| 8 | + |
| 9 | +class Humbug: |
| 10 | + """ |
| 11 | + Represent a humbug from Bugout. |
| 12 | + """ |
| 13 | + |
| 14 | + def __init__( |
| 15 | + self, url: Optional[str] = None, timeout: float = REQUESTS_TIMEOUT |
| 16 | + ) -> None: |
| 17 | + if url is None: |
| 18 | + raise InvalidUrlSpec("Invalid spire url specified") |
| 19 | + self.url = url |
| 20 | + self.timeout = timeout |
| 21 | + |
| 22 | + def _call(self, method: Method, path: str, **kwargs): |
| 23 | + url = f"{self.url.rstrip('/')}/{path.rstrip('/')}" |
| 24 | + result = make_request(method=method, url=url, timeout=self.timeout, **kwargs) |
| 25 | + return result |
| 26 | + |
| 27 | + def get_humbug_integrations( |
| 28 | + self, |
| 29 | + token: Union[str, uuid.UUID], |
| 30 | + group_id: Optional[Union[str, uuid.UUID]] = None, |
| 31 | + ) -> BugoutHumbugIntegrationsList: |
| 32 | + humbug_path = "humbug/integrations" |
| 33 | + headers = { |
| 34 | + "Authorization": f"Bearer {token}", |
| 35 | + } |
| 36 | + query_params = {} |
| 37 | + if group_id is not None: |
| 38 | + query_params.update({"group_id": group_id}) |
| 39 | + result = self._call( |
| 40 | + method=Method.get, path=humbug_path, params=query_params, headers=headers |
| 41 | + ) |
| 42 | + return BugoutHumbugIntegrationsList(**result) |
0 commit comments