api-foundry-query-engine 0.8.85__tar.gz → 0.8.87__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.85 → api_foundry_query_engine-0.8.87}/PKG-INFO +1 -1
- api_foundry_query_engine-0.8.87/api_foundry_query_engine/__init__.py +1 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/connectors/data_api_connection.py +5 -3
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_query_handler.py +15 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_select_query_handler.py +6 -2
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/operation.py +35 -21
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/api_model.py +47 -0
- api_foundry_query_engine-0.8.85/api_foundry_query_engine/__init__.py +0 -1
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/.gitignore +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/LICENSE +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/.pre-commit-config.yaml +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/adapters/adapter.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/adapters/gateway_adapter.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/connectors/connection.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/connectors/connection_factory.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/connectors/postgres_connection.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/batch_operation_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/dao.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/operation_dao.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_custom_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_delete_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_insert_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_restore_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_subselect_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/dao/sql_update_query_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/lambda_handler.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/services/service.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/services/transactional_service.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/app_exception.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/claims_check.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/dependency_resolver.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/logger.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/reference_resolver.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/api_foundry_query_engine/utils/token_decoder.py +0 -0
- {api_foundry_query_engine-0.8.85 → api_foundry_query_engine-0.8.87}/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.87
|
|
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.87"
|
|
@@ -66,9 +66,11 @@ def _encode_parameter(value: Any) -> dict:
|
|
|
66
66
|
if isinstance(value, time_type):
|
|
67
67
|
return {"stringValue": value.strftime("%H:%M:%S.%f")}
|
|
68
68
|
if isinstance(value, (dict, list)):
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
#
|
|
69
|
+
# Postgres array columns (x-af-column-type "text[]" and the like)
|
|
70
|
+
# arrive as lists: the Data API has no array parameter, so they
|
|
71
|
+
# travel as JSON text and SQLQueryHandler.placeholder unpacks them.
|
|
72
|
+
# Embedded objects are already JSON text by now; dumping is also the
|
|
73
|
+
# only non-lossy fallback for anything else.
|
|
72
74
|
return {"stringValue": json.dumps(value)}
|
|
73
75
|
return {"stringValue": str(value)}
|
|
74
76
|
|
|
@@ -185,6 +185,21 @@ class SQLQueryHandler:
|
|
|
185
185
|
elif property.column_type == "time":
|
|
186
186
|
return f"TO_TIME(:{param}, 'HH24:MI:SS.FF')"
|
|
187
187
|
return f":{param}"
|
|
188
|
+
element_type = getattr(property, "array_element_type", None)
|
|
189
|
+
if element_type and self.dialect == "postgres":
|
|
190
|
+
# A Postgres array column (x-af-column-type "text[]" and the
|
|
191
|
+
# like). The Data API can't bind an array parameter, so the
|
|
192
|
+
# value travels as JSON text (data_api_connection dumps a
|
|
193
|
+
# list) and is unpacked into an array of the column's element
|
|
194
|
+
# type; NULL stays NULL and [] becomes an empty array.
|
|
195
|
+
# psycopg2 adapts a list to ARRAY[...] itself; the cast types
|
|
196
|
+
# an empty list.
|
|
197
|
+
if self.driver == "data-api":
|
|
198
|
+
return (
|
|
199
|
+
f"CASE WHEN :{param}::jsonb IS NULL THEN NULL ELSE "
|
|
200
|
+
f"CAST(ARRAY(SELECT jsonb_array_elements_text(:{param}::jsonb)) AS {element_type}[]) END"
|
|
201
|
+
)
|
|
202
|
+
return f"CAST(%({param})s AS {element_type}[])"
|
|
188
203
|
if self.driver == "data-api":
|
|
189
204
|
# JSON-serialized properties (embedded objects/arrays, see
|
|
190
205
|
# SQLInsertSchemaQueryHandler.insert_values) always need a
|
|
@@ -417,16 +417,20 @@ class SQLSelectSchemaQueryHandler(SQLSchemaQueryHandler):
|
|
|
417
417
|
|
|
418
418
|
@property
|
|
419
419
|
def limit_expression(self) -> str:
|
|
420
|
+
"""__limit, capped at the schema object's row limit, which also
|
|
421
|
+
applies when __limit is left out."""
|
|
422
|
+
cap = getattr(self.schema_object, "limit", None)
|
|
420
423
|
limit_str = self.operation.metadata_params.get("limit", None)
|
|
421
424
|
if not limit_str:
|
|
422
|
-
return ""
|
|
425
|
+
return f" LIMIT {int(cap)}" if cap else ""
|
|
423
426
|
|
|
424
427
|
if isinstance(limit_str, str) and not limit_str.isdigit():
|
|
425
428
|
raise ApplicationException(
|
|
426
429
|
400, f"Limit is not an valid integer {limit_str}"
|
|
427
430
|
)
|
|
428
431
|
|
|
429
|
-
|
|
432
|
+
limit = int(limit_str)
|
|
433
|
+
return f" LIMIT {min(limit, int(cap)) if cap else limit}"
|
|
430
434
|
|
|
431
435
|
@property
|
|
432
436
|
def offset_expression(self) -> str:
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import re
|
|
2
3
|
from typing import Any, Dict, List, Optional
|
|
3
4
|
|
|
4
5
|
from api_foundry_query_engine.utils.logger import logger
|
|
@@ -98,14 +99,18 @@ class Operation:
|
|
|
98
99
|
def roles(self) -> List[str]:
|
|
99
100
|
"""Get the roles from claims.
|
|
100
101
|
|
|
101
|
-
Falls back to a singular `role` claim plus `groups`
|
|
102
|
-
plural `roles` key itself isn't present
|
|
103
|
-
a custom Lambda TOKEN authorizer
|
|
104
|
-
of a `role` string and a `groups`
|
|
102
|
+
Falls back to a singular `role` claim plus `groups` and
|
|
103
|
+
`cognito:groups` when the plural `roles` key itself isn't present
|
|
104
|
+
-- some authorizers (e.g. a custom Lambda TOKEN authorizer
|
|
105
|
+
following AWS's own convention of a `role` string and a `groups`
|
|
106
|
+
list, or API Gateway's Cognito user pool authorizer, which passes
|
|
107
|
+
the pool's groups as `cognito:groups`) never populate `roles`,
|
|
105
108
|
which previously made every such caller look role-less even with
|
|
106
|
-
a perfectly valid, correctly-scoped token.
|
|
107
|
-
|
|
108
|
-
context (whose values must be strings), a JSON-encoded
|
|
109
|
+
a perfectly valid, correctly-scoped token. Groups may arrive as a
|
|
110
|
+
real list or, when they passed through an API Gateway authorizer
|
|
111
|
+
context (whose values must be strings), as a JSON-encoded list, a
|
|
112
|
+
bracketed list ("[admin member]", "[admin, member]"), a
|
|
113
|
+
comma-separated string, or one group name.
|
|
109
114
|
"""
|
|
110
115
|
if not self.claims:
|
|
111
116
|
return []
|
|
@@ -118,20 +123,10 @@ class Operation:
|
|
|
118
123
|
if role:
|
|
119
124
|
fallback.append(str(role))
|
|
120
125
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
parsed = json.loads(groups_raw)
|
|
126
|
-
groups = [str(item) for item in parsed] if isinstance(parsed, list) else [groups_raw]
|
|
127
|
-
except (TypeError, ValueError):
|
|
128
|
-
groups = [groups_raw]
|
|
129
|
-
elif isinstance(groups_raw, list):
|
|
130
|
-
groups = [str(item) for item in groups_raw]
|
|
131
|
-
|
|
132
|
-
for group in groups:
|
|
133
|
-
if group not in fallback:
|
|
134
|
-
fallback.append(group)
|
|
126
|
+
for key in ("groups", "cognito:groups"):
|
|
127
|
+
for group in _parse_groups(self.claims.get(key)):
|
|
128
|
+
if group not in fallback:
|
|
129
|
+
fallback.append(group)
|
|
135
130
|
return fallback
|
|
136
131
|
|
|
137
132
|
def subject(self) -> Optional[str]:
|
|
@@ -141,3 +136,22 @@ class Operation:
|
|
|
141
136
|
def groups(self) -> List[str]:
|
|
142
137
|
"""Get the groups from claims."""
|
|
143
138
|
return self.claims.get("groups", []) if self.claims else []
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _parse_groups(raw: Any) -> List[str]:
|
|
142
|
+
"""Group names from a groups claim, in any of the shapes an authorizer
|
|
143
|
+
passes them (see Operation.roles)."""
|
|
144
|
+
if isinstance(raw, (list, tuple)):
|
|
145
|
+
return [str(item) for item in raw if str(item).strip()]
|
|
146
|
+
if not isinstance(raw, str) or not raw.strip():
|
|
147
|
+
return []
|
|
148
|
+
text = raw.strip()
|
|
149
|
+
try:
|
|
150
|
+
parsed = json.loads(text)
|
|
151
|
+
if isinstance(parsed, list):
|
|
152
|
+
return [str(item) for item in parsed if str(item).strip()]
|
|
153
|
+
except (TypeError, ValueError):
|
|
154
|
+
pass
|
|
155
|
+
if text.startswith("[") and text.endswith("]"):
|
|
156
|
+
text = text[1:-1]
|
|
157
|
+
return [part for part in re.split(r"[\s,]+", text) if part]
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import os
|
|
3
|
+
import re
|
|
2
4
|
import yaml
|
|
3
5
|
|
|
4
6
|
from datetime import datetime
|
|
5
7
|
from typing import Any, Dict, List, Mapping, Optional
|
|
6
8
|
|
|
9
|
+
from api_foundry_query_engine.utils.app_exception import ApplicationException
|
|
7
10
|
from api_foundry_query_engine.utils.logger import logger
|
|
8
11
|
|
|
9
12
|
log = logger(__name__)
|
|
10
13
|
|
|
14
|
+
# A Postgres array column type: an element type followed by "[]", as in
|
|
15
|
+
# "text[]", "integer[]" or "character varying[]". The element type is
|
|
16
|
+
# interpolated into SQL casts, so only letters, digits, underscores and
|
|
17
|
+
# inner spaces are accepted.
|
|
18
|
+
_ARRAY_COLUMN_TYPE = re.compile(r"^\s*([A-Za-z][A-Za-z0-9_ ]*?)\s*\[\]\s*$")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def array_element_type(column_type: Optional[str]) -> Optional[str]:
|
|
22
|
+
"""The element type of an array column type ("text" for "text[]"), or
|
|
23
|
+
None when the column is not an array."""
|
|
24
|
+
if not isinstance(column_type, str):
|
|
25
|
+
return None
|
|
26
|
+
match = _ARRAY_COLUMN_TYPE.match(column_type)
|
|
27
|
+
return " ".join(match.group(1).lower().split()) if match else None
|
|
28
|
+
|
|
11
29
|
api_model = None
|
|
12
30
|
|
|
13
31
|
|
|
@@ -49,10 +67,19 @@ class SchemaObjectProperty:
|
|
|
49
67
|
def __repr__(self):
|
|
50
68
|
return f"SchemaObjectProperty(api_name={self.api_name}, column_name={self.column_name}, type={self.type})"
|
|
51
69
|
|
|
70
|
+
@property
|
|
71
|
+
def array_element_type(self) -> Optional[str]:
|
|
72
|
+
"""The element type when the column is a Postgres array
|
|
73
|
+
(x-af-column-type "text[]" and the like), else None."""
|
|
74
|
+
return array_element_type(self.column_type)
|
|
75
|
+
|
|
52
76
|
def convert_to_db_value(self, value) -> Optional[Any]:
|
|
53
77
|
if value is None:
|
|
54
78
|
return None
|
|
55
79
|
|
|
80
|
+
if self.array_element_type:
|
|
81
|
+
return self._convert_array(value)
|
|
82
|
+
|
|
56
83
|
column_type = self.column_type if self.column_type is not None else "string"
|
|
57
84
|
|
|
58
85
|
# Handle string types
|
|
@@ -105,6 +132,23 @@ class SchemaObjectProperty:
|
|
|
105
132
|
else:
|
|
106
133
|
return value
|
|
107
134
|
|
|
135
|
+
def _convert_array(self, value) -> list:
|
|
136
|
+
"""An array column's value: a list of scalars. A string (a query
|
|
137
|
+
parameter) must hold a JSON array."""
|
|
138
|
+
if isinstance(value, str):
|
|
139
|
+
try:
|
|
140
|
+
value = json.loads(value)
|
|
141
|
+
except ValueError:
|
|
142
|
+
value = None
|
|
143
|
+
if not isinstance(value, (list, tuple)) or any(
|
|
144
|
+
isinstance(item, (list, tuple, dict)) for item in value
|
|
145
|
+
):
|
|
146
|
+
raise ApplicationException(
|
|
147
|
+
400,
|
|
148
|
+
f"Property '{self.api_name}' is a {self.column_type} column and takes an array of scalar values",
|
|
149
|
+
)
|
|
150
|
+
return list(value)
|
|
151
|
+
|
|
108
152
|
def is_soft_delete_field(self) -> bool:
|
|
109
153
|
"""Check if this property is configured for soft delete."""
|
|
110
154
|
return self.soft_delete is not None
|
|
@@ -267,6 +311,9 @@ class SchemaObject:
|
|
|
267
311
|
)
|
|
268
312
|
self._primary_key: str = str(data.get("primary_key"))
|
|
269
313
|
self.permissions = data.get("permissions")
|
|
314
|
+
# Most rows one read returns (api_foundry's x-af-limit). None in a
|
|
315
|
+
# config from an api_foundry before 0.8.13: no cap.
|
|
316
|
+
self.limit: Optional[int] = data.get("limit")
|
|
270
317
|
|
|
271
318
|
def __repr__(self):
|
|
272
319
|
return f"SchemaObject(table_name={self.table_name}, primary_key={self.primary_key})"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.8.85"
|
|
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
|