From 0ab83f583e130e364d1cfcce3899b0f977380d54 Mon Sep 17 00:00:00 2001 From: Dev Mukherjee Date: Wed, 15 May 2024 08:16:11 +1000 Subject: [PATCH] fix: misconfigured adapter in pyproject adds a few lines of logging to discover that the shillelagh adapter wasn't register due to a syntax error in pyproject, this change verifies that we can return rows of data back via the shillelagh adapter note this commit does not query the api for results, this is to come in subsequent commits, read the following comment https://github.com/anomaly/gallagher/issues/31#issuecomment-2111223261 for how we got to this solution Refs #31 --- gallagher/ext/shillelagh/__init__.py | 58 ++++++++++++++++++++++++++-- pyproject.toml | 2 +- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/gallagher/ext/shillelagh/__init__.py b/gallagher/ext/shillelagh/__init__.py index 67827a03..41babdc8 100644 --- a/gallagher/ext/shillelagh/__init__.py +++ b/gallagher/ext/shillelagh/__init__.py @@ -5,6 +5,13 @@ [shillelagh](https://github.com/betodealmeida/shillelagh) """ +import urllib + + +import logging +logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s') + +logging.error("test") from typing import ( Any, @@ -16,7 +23,24 @@ ) from shillelagh.adapters.base import Adapter +from shillelagh.typing import ( + RequestedOrder, + Row, +) +from shillelagh.filters import ( + Filter, + Impossible, + Operator, + Range, +) +from shillelagh.fields import ( + Float, + Integer, + String, + Order, + Boolean, +) class GallagherCommandCentreAPI(Adapter): @@ -32,14 +56,42 @@ class GallagherCommandCentreAPI(Adapter): # Check to see if we can do this using the partial column feature supports_requested_columns = False + # Columns + first_name = String() + last_name = String() + id = Integer() + authorised = Boolean() + + @staticmethod def supports(uri: str, fast: bool = True, **kwargs: Any) -> Optional[bool]: - return False + # return true if the url is acceptable to us + parsed = urllib.parse.urlparse(uri) + query_string = urllib.parse.parse_qs(parsed.query) + return ( + parsed.netloc == "commandcentre-api-au.security.gallagher.cloud" + ) @staticmethod def parse_uri(uri: str) -> Tuple[str]: - return (uri,) + return (uri, "api_key") - def __init__(self, uri: str): + def __init__(self, uri: str, api_key: Optional[str], **kwargs: Any): super().__init__() + self.uri = uri + self.api_key = api_key + + def get_data( # pylint: disable=too-many-locals + self, + bounds: Dict[str, Filter], + order: List[Tuple[str, RequestedOrder]], + **kwargs: Any, + ) -> Iterator[Dict[str, Any]]: + yield { + "rowid": 1, + "id": 1, + "authorised": True, + "first_name": "Dev", + "last_name": "Mukherjee", + } diff --git a/pyproject.toml b/pyproject.toml index dc83d5f3..03d14f26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -92,4 +92,4 @@ build-backend = "poetry.core.masonry.api" [tool.poetry.plugins."shillelagh.adapter"] -gacc = "gallagher.ext.shillelagh.GallagherCommandCentreAPI" +gacc = "gallagher.ext.shillelagh:GallagherCommandCentreAPI"