api-foundry-query-engine 0.8.84__tar.gz → 0.8.85__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/PKG-INFO +1 -1
- api_foundry_query_engine-0.8.85/api_foundry_query_engine/__init__.py +1 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/connectors/postgres_connection.py +13 -1
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/lambda_handler.py +11 -3
- api_foundry_query_engine-0.8.85/api_foundry_query_engine/services/transactional_service.py +81 -0
- api_foundry_query_engine-0.8.84/api_foundry_query_engine/__init__.py +0 -1
- api_foundry_query_engine-0.8.84/api_foundry_query_engine/services/transactional_service.py +0 -52
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/.gitignore +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/LICENSE +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/.pre-commit-config.yaml +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/adapters/adapter.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/adapters/gateway_adapter.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/connectors/connection.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/connectors/connection_factory.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/connectors/data_api_connection.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/batch_operation_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/dao.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/operation_dao.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_custom_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_delete_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_insert_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_restore_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_select_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_subselect_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/dao/sql_update_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/operation.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/services/service.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/api_model.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/app_exception.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/claims_check.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/dependency_resolver.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/logger.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/reference_resolver.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/api_foundry_query_engine/utils/token_decoder.py +0 -0
- {api_foundry_query_engine-0.8.84 → api_foundry_query_engine-0.8.85}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: api-foundry-query-engine
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.85
|
|
4
4
|
Summary: The AWS lambda service handler use by the `api_foundry` project is a powerful tool designed to automate the deployment of REST APIs on AWS using Lambda services to access and interact with relational databases (RDBMS). This project leverages the OpenAPI specification to define and manage the APIs
|
|
5
5
|
Project-URL: Documentation, https://github.com/DanRepik/api-foundry
|
|
6
6
|
Project-URL: Source, https://github.com/DanRepik/api-foundry
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.8.85"
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
1
3
|
from api_foundry_query_engine.connectors.connection import (
|
|
2
4
|
Connection,
|
|
3
5
|
Cursor,
|
|
@@ -8,6 +10,16 @@ from api_foundry_query_engine.utils.logger import logger
|
|
|
8
10
|
# Initialize the logger
|
|
9
11
|
log = logger(__name__)
|
|
10
12
|
|
|
13
|
+
# postgresql://user:secret@host/db and "... password=secret ..."
|
|
14
|
+
_URI_PASSWORD = re.compile(r"(://[^:/@\s]*:)[^@\s]*(@)")
|
|
15
|
+
_KEYWORD_PASSWORD = re.compile(r"(\bpassword\s*=\s*)('(?:[^'\\]|\\.)*'|\S+)", re.IGNORECASE)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def redact_dsn(dsn: str) -> str:
|
|
19
|
+
"""The DSN with its password replaced, so it can be logged."""
|
|
20
|
+
dsn = _URI_PASSWORD.sub(r"\1***\2", dsn)
|
|
21
|
+
return _KEYWORD_PASSWORD.sub(r"\1***", dsn)
|
|
22
|
+
|
|
11
23
|
|
|
12
24
|
class PostgresCursor(Cursor):
|
|
13
25
|
def __init__(self, cursor):
|
|
@@ -121,7 +133,7 @@ class PostgresConnection(Connection):
|
|
|
121
133
|
|
|
122
134
|
# If DSN is provided, use it directly (simplifies fixture_foundry integration)
|
|
123
135
|
if "dsn" in self.db_config:
|
|
124
|
-
log.info("Connecting using DSN: %s", self.db_config["dsn"])
|
|
136
|
+
log.info("Connecting using DSN: %s", redact_dsn(self.db_config["dsn"]))
|
|
125
137
|
return connect(self.db_config["dsn"])
|
|
126
138
|
|
|
127
139
|
# Otherwise, build connection from individual parameters
|
|
@@ -80,13 +80,21 @@ class QueryEngine:
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
|
|
83
|
+
def load_engine_config():
|
|
84
|
+
log.info("Loading engine config from environment variables")
|
|
85
|
+
config = os.environ
|
|
86
|
+
# Names only: the Lambda environment holds the execution role's
|
|
87
|
+
# credentials (AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN) and often
|
|
88
|
+
# database DSNs with passwords.
|
|
89
|
+
log.debug("engine_config keys: %s", sorted(config))
|
|
90
|
+
return config
|
|
91
|
+
|
|
92
|
+
|
|
83
93
|
@token_decoder()
|
|
84
94
|
@claims_check(validate_path_scope=False, validate_scope_format=False)
|
|
85
95
|
def handler(event, _):
|
|
86
96
|
if not hasattr(handler, "engine_config"):
|
|
87
|
-
|
|
88
|
-
handler.engine_config = os.environ
|
|
89
|
-
log.info("engine_config: %s", handler.engine_config)
|
|
97
|
+
handler.engine_config = load_engine_config()
|
|
90
98
|
|
|
91
99
|
if not hasattr(handler, "query_engine"):
|
|
92
100
|
set_api_model(handler.engine_config)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import traceback
|
|
2
|
+
from typing import Mapping, Optional
|
|
3
|
+
|
|
4
|
+
from api_foundry_query_engine.utils.logger import logger
|
|
5
|
+
from api_foundry_query_engine.utils.app_exception import ApplicationException
|
|
6
|
+
from api_foundry_query_engine.operation import Operation
|
|
7
|
+
from api_foundry_query_engine.services.service import ServiceAdapter
|
|
8
|
+
from api_foundry_query_engine.connectors.connection_factory import ConnectionFactory
|
|
9
|
+
from api_foundry_query_engine.dao.operation_dao import OperationDAO
|
|
10
|
+
from api_foundry_query_engine.utils.api_model import (
|
|
11
|
+
get_path_operation,
|
|
12
|
+
get_schema_object,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
log = logger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TransactionalService(ServiceAdapter):
|
|
19
|
+
def __init__(self, config: Mapping[str, str]):
|
|
20
|
+
super().__init__()
|
|
21
|
+
self.config = config
|
|
22
|
+
self.connection_factory = ConnectionFactory(config)
|
|
23
|
+
|
|
24
|
+
def execute(self, operation: Operation) -> list[dict]:
|
|
25
|
+
if operation.entity == "batch" and operation.action == "create":
|
|
26
|
+
database = self._batch_database(operation)
|
|
27
|
+
else:
|
|
28
|
+
database = self._database(operation.entity, operation.action)
|
|
29
|
+
if database is None:
|
|
30
|
+
raise ApplicationException(500, f"Unknown operation: {operation.entity}")
|
|
31
|
+
|
|
32
|
+
# Pass config to connection_factory if needed (future extension)
|
|
33
|
+
connection = self.connection_factory.get_connection(database)
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
result = OperationDAO(operation, connection.engine()).execute(connection)
|
|
37
|
+
if operation.action != "read":
|
|
38
|
+
connection.commit()
|
|
39
|
+
if isinstance(result, dict):
|
|
40
|
+
return [result]
|
|
41
|
+
return result
|
|
42
|
+
except Exception as error:
|
|
43
|
+
log.error("transaction exception: %s", error)
|
|
44
|
+
log.error("traceback: %s", traceback.format_exc())
|
|
45
|
+
raise error
|
|
46
|
+
finally:
|
|
47
|
+
connection.close()
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def _database(entity, action) -> Optional[str]:
|
|
51
|
+
path_operation = get_path_operation(entity, action)
|
|
52
|
+
if path_operation:
|
|
53
|
+
return path_operation.database
|
|
54
|
+
schema_object = get_schema_object(entity)
|
|
55
|
+
if schema_object:
|
|
56
|
+
return schema_object.database
|
|
57
|
+
return None
|
|
58
|
+
|
|
59
|
+
def _batch_database(self, operation: Operation) -> str:
|
|
60
|
+
"""The database a batch runs against.
|
|
61
|
+
|
|
62
|
+
"batch" is not an entity in the API model, so the database comes
|
|
63
|
+
from the sub-operations. They share one connection, so they must all
|
|
64
|
+
resolve to the same database. A sub-operation naming an unknown
|
|
65
|
+
entity doesn't pick the database; it fails on its own inside the
|
|
66
|
+
batch, where continueOnError decides what happens next.
|
|
67
|
+
"""
|
|
68
|
+
operations = (operation.store_params or {}).get("operations")
|
|
69
|
+
if not isinstance(operations, list) or not operations:
|
|
70
|
+
raise ApplicationException(400, "Batch request must contain at least one operation")
|
|
71
|
+
|
|
72
|
+
databases = {self._database(op.get("entity"), op.get("action")) for op in operations if isinstance(op, dict)}
|
|
73
|
+
databases.discard(None)
|
|
74
|
+
if not databases:
|
|
75
|
+
raise ApplicationException(500, "Unknown operation: no batch operation names a known entity")
|
|
76
|
+
if len(databases) > 1:
|
|
77
|
+
raise ApplicationException(
|
|
78
|
+
400,
|
|
79
|
+
"Batch operations must all use the same database; got " + ", ".join(sorted(databases)),
|
|
80
|
+
)
|
|
81
|
+
return databases.pop()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.8.84"
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import traceback
|
|
2
|
-
from typing import Mapping
|
|
3
|
-
|
|
4
|
-
from api_foundry_query_engine.utils.logger import logger
|
|
5
|
-
from api_foundry_query_engine.utils.app_exception import ApplicationException
|
|
6
|
-
from api_foundry_query_engine.operation import Operation
|
|
7
|
-
from api_foundry_query_engine.services.service import ServiceAdapter
|
|
8
|
-
from api_foundry_query_engine.connectors.connection_factory import ConnectionFactory
|
|
9
|
-
from api_foundry_query_engine.dao.operation_dao import OperationDAO
|
|
10
|
-
from api_foundry_query_engine.utils.api_model import (
|
|
11
|
-
get_path_operation,
|
|
12
|
-
get_schema_object,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
log = logger(__name__)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class TransactionalService(ServiceAdapter):
|
|
19
|
-
def __init__(self, config: Mapping[str, str]):
|
|
20
|
-
super().__init__()
|
|
21
|
-
self.config = config
|
|
22
|
-
self.connection_factory = ConnectionFactory(config)
|
|
23
|
-
|
|
24
|
-
def execute(self, operation: Operation) -> list[dict]:
|
|
25
|
-
path_operation = get_path_operation(operation.entity, operation.action)
|
|
26
|
-
if path_operation:
|
|
27
|
-
database = path_operation.database
|
|
28
|
-
else:
|
|
29
|
-
schema_object = get_schema_object(operation.entity)
|
|
30
|
-
if schema_object:
|
|
31
|
-
database = schema_object.database
|
|
32
|
-
else:
|
|
33
|
-
raise ApplicationException(
|
|
34
|
-
500, f"Unknown operation: {operation.entity}"
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
# Pass config to connection_factory if needed (future extension)
|
|
38
|
-
connection = self.connection_factory.get_connection(database)
|
|
39
|
-
|
|
40
|
-
try:
|
|
41
|
-
result = OperationDAO(operation, connection.engine()).execute(connection)
|
|
42
|
-
if operation.action != "read":
|
|
43
|
-
connection.commit()
|
|
44
|
-
if isinstance(result, dict):
|
|
45
|
-
return [result]
|
|
46
|
-
return result
|
|
47
|
-
except Exception as error:
|
|
48
|
-
log.error("transaction exception: %s", error)
|
|
49
|
-
log.error("traceback: %s", traceback.format_exc())
|
|
50
|
-
raise error
|
|
51
|
-
finally:
|
|
52
|
-
connection.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|