Comments (4)
This is awesome! Thanks for the heads up, and let me know if you have any questions, I'm happy to help.
from gallagher.
Quick note for anyone else working with shillelagh
and attempting to debug their adapter
, my general strategy for development is:
- Start a
virtualenv
- Install
shillelagh
to use the interactive console - Install my adapter using
pip
in editable mode from the local folder e.gpip install -e ~/Work/Lib/gallagher
- Use the console to test as I build the adapter
I figured it would be easier to this before I get into building a SQLAlchemy dialect #9
At first attempt it all looked well and when I ran:
π> SELECT * FROM "https://commandcentre-api-au.security.gallagher.cloud/api/cardholders";
Unsupported table: https://commandcentre-api-au.security.gallagher.cloud/api/cardholders
I got the unsupported table
error and could not figure out what was wrong. For obvious reasons the console suppresses log messages, I decided to enable logging and set it to DEBUG
, this was added to the top of the file containing my adapter.
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s')
upon restarting the console, I saw the following, and found that my adapter wasn't registering properly:
π>
GoodBye!
(shillelagh) β ~ shillelagh
2024-05-15 07:51:36,627 ERROR test
2024-05-15 07:51:36,628 DEBUG No module named 'gallagher.ext.shillelagh.GallagherCommandCentreAPI'
2024-05-15 07:51:36,641 DEBUG Using selector: KqueueSelector
Upon inspecting my pyproject.toml
I found that I had a syntax error where I was referring to the module as gallagher.ext.shillelagh.GallagherCommandCentreAPI
instead of gallagher.ext.shillelagh:GallagherCommandCentreAPI
, the fixed version is:
[tool.poetry.plugins."shillelagh.adapter"]
gacc = "gallagher.ext.shillelagh:GallagherCommandCentreAPI"
And given that it returns the required rows of data, the logs should make it easier to debug the adapter.
TypeError: missing a required argument: 'api_key'
(shillelagh) β ~ shillelagh
2024-05-15 07:55:03,649 ERROR test
2024-05-15 07:55:03,666 DEBUG Using selector: KqueueSelector
π> SELECT * FROM "https://commandcentre-api-au.security.gallagher.cloud/api/cardholders";
2024-05-15 07:55:09,149 DEBUG Instantiating adapter with deserialized arguments: ['https://commandcentre-api-au.security.gallagher.cloud/api/cardholders', 'api_key']
authorised first_name id last_name
------------ ------------ ---- -----------
True Dev 1 Mukherjee
(1 row in 0.05s)
2024-05-15 07:55:09,150 DEBUG Using selector: KqueueSelector
Make sure that this isn't enabled when the adapter ships, even better find a way to dynamically configure the logger
from gallagher.
From my initial reading, the way we should approach this is to write a customer adapter for shillelagh
which also allows for a custom sqlalchemy dialect.
The references the following
Sharks have been around for a long time. Theyβre older than trees and the rings of Saturn, actually! The reason they havenβt changed that much in hundreds of millions of years is because theyβre really good at what they do.
SQL has been around for some 50 years for the same reason: itβs really good at what it does.
as their philosophy for Why SQL
.
from gallagher.
utils.py
in the dto
package currently uses the py3.9
__annotation__
property to access the annotations:
@classmethod
def _accumulated_annotations(cls) -> dict:
"""Return a dictionary of all annotations
This method is used to return a dictionary of all the
annotations from itself and it's parent classes.
It is intended for use by the shillelagh extension
"""
annotations = cls.__annotations__.copy() # TODO: should we make copies?
for base in cls.__bases__:
if issubclass(base, BaseModel):
# Copy annotations from classes that are pydantic models
# they are the only things that form part of the response
annotations.update(base.__annotations__)
return annotations.items()
This recommendation has changes in py3.10
see this article.
Looking at the inspect
package get_annotations
returns the annotations of the class itself, where as typing.get_type_hints
returns typing definitions from itself and parent classes.
>>> import typing
>>> typing.get_type_honest(CardholderSummary)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'typing' has no attribute 'get_type_honest'. Did you mean: 'get_type_hints'?
>>> typing.get_type_hints(CardholderSummary)
{'href': <class 'pydantic_core._pydantic_core.Url'>, 'id': <class 'str'>, '_good_known_since': typing.Optional[datetime.datetime], 'first_name': <class 'str'>, 'last_name': <class 'str'>, 'short_name': typing.Optional[str], 'description': typing.Optional[str], 'authorised': <class 'bool'>}
We should refactor this method to use a py3.10+
solution.
from gallagher.
Related Issues (20)
- Provide a runnable TUI demo interface via `textual-web` for users to try against the Anomaly license HOT 2
- Study and adapt Software Package Data Exchange Specification
- Move to `hatch` as a python project tool HOT 4
- Investigate the use of `keyring` to store API Keys
- Provide `brew` (or other installer) packages for installing the the `cli` and `tui` HOT 2
- Add `--json` option to cli tool to output structure data, also consider `--csv` and `--markdown`
- Make the list of fields in a response configurable
- Investigate `logfire` integration at an `httpx` and `sqlalchemy` level
- Refactor (if required, and doesn't break anything) the use of `reserved` keywords as `attribute` names in `pyndatic` models HOT 2
- Provide a set of examples references from the documentation
- Integrate standard python logging across the library and applications to ease debugging
- Add social cards for mkdocs
- Provide a set of utility scripts that populates developer data via the REST API
- Implement a paradigm for implementing search endpoints for the SDK and CLI
- Investigate and document strategies to debug cloud gateway outages or potential misconfiguration of Command Centre
- Document the missing portions of the WAN configuration in `HARDWARE` configuration, additionally document a `VPN/L2TP` based setup to avoid exposing WAN ports HOT 1
- Allow range as parameters in the CLI for batch operations e.g provide IDs as multiple values or ranges like `2200-2210` HOT 1
- Reconsider use of `DELETE` HTTP Verb where the REST API has a `remove` operation for objects
- Update REST endpoints to match up with Command Centre 9.10 updates
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gallagher.