Skip to content

Commit

Permalink
fix: misconfigured adapter in pyproject
Browse files Browse the repository at this point in the history
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
#31 (comment)

for how we got to this solution
Refs #31
  • Loading branch information
devraj committed May 14, 2024
1 parent 352eec1 commit 0ab83f5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
58 changes: 55 additions & 3 deletions gallagher/ext/shillelagh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):

Expand All @@ -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",
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 0ab83f5

Please sign in to comment.