api-foundry 0.1.21__tar.gz → 0.1.30__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-0.1.21 → api_foundry-0.1.30}/PKG-INFO +1 -1
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/iac/pulumi/api_foundry.py +3 -7
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/utils/model_factory.py +28 -51
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/utils/schema_validator.py +27 -14
- {api_foundry-0.1.21 → api_foundry-0.1.30}/pyproject.toml +1 -1
- {api_foundry-0.1.21 → api_foundry-0.1.30}/.gitignore +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/LICENSE +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/__init__.py +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/iac/gateway_spec.py +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/scripts/install_secret.py +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/scripts/postgres_to_openapi.py +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.1.21 → api_foundry-0.1.30}/api_foundry/utils/logger.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: api-foundry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.30
|
|
4
4
|
Summary: 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
|
|
@@ -83,9 +83,7 @@ def load_api_spec(api_spec: Union[str, list[str]]) -> dict:
|
|
|
83
83
|
try:
|
|
84
84
|
as_yaml = yaml.safe_load(spec)
|
|
85
85
|
except yaml.YAMLError as exc: # not YAML
|
|
86
|
-
raise ValueError(
|
|
87
|
-
f"Invalid OpenAPI spec source: {spec}"
|
|
88
|
-
) from exc
|
|
86
|
+
raise ValueError(f"Invalid OpenAPI spec source: {spec}") from exc
|
|
89
87
|
|
|
90
88
|
if is_valid_openapi_spec(as_yaml):
|
|
91
89
|
inputs.append(as_yaml)
|
|
@@ -124,9 +122,7 @@ class APIFoundry(ComponentResource):
|
|
|
124
122
|
*,
|
|
125
123
|
api_spec: Union[str, list[str]],
|
|
126
124
|
secrets: Optional[str] = None,
|
|
127
|
-
environment: Optional[
|
|
128
|
-
dict[str, Union[str, pulumi.Output[str]]]
|
|
129
|
-
] = None,
|
|
125
|
+
environment: Optional[dict[str, Union[str, pulumi.Output[str]]]] = None,
|
|
130
126
|
integrations: Optional[list[dict]] = None,
|
|
131
127
|
token_validators: Optional[list[dict]] = None,
|
|
132
128
|
policy_statements: Optional[list] = None,
|
|
@@ -154,7 +150,7 @@ class APIFoundry(ComponentResource):
|
|
|
154
150
|
|
|
155
151
|
env_vars["SECRETS"] = secrets
|
|
156
152
|
|
|
157
|
-
|
|
153
|
+
# Grant read access to referenced secrets (single broad stmt)
|
|
158
154
|
if json.loads(secrets):
|
|
159
155
|
policy_statements.append(
|
|
160
156
|
{
|
|
@@ -112,9 +112,7 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
112
112
|
"double",
|
|
113
113
|
}:
|
|
114
114
|
self.column_type = (
|
|
115
|
-
"real"
|
|
116
|
-
if self.numeric_format == "float"
|
|
117
|
-
else "double precision"
|
|
115
|
+
"real" if self.numeric_format == "float" else "double precision"
|
|
118
116
|
)
|
|
119
117
|
else:
|
|
120
118
|
self.column_type = prop.get("type") or "string"
|
|
@@ -128,13 +126,9 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
128
126
|
self.concurrency_control = self._concurrency_control(schema_name, prop)
|
|
129
127
|
# For embedded objects/arrays
|
|
130
128
|
self.sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
|
|
131
|
-
self.items_sub_properties: Optional[
|
|
132
|
-
Dict[str, SchemaObjectProperty]
|
|
133
|
-
] = None
|
|
129
|
+
self.items_sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
|
|
134
130
|
|
|
135
|
-
def _concurrency_control(
|
|
136
|
-
self, schema_name: str, prop_dict: dict
|
|
137
|
-
) -> Optional[str]:
|
|
131
|
+
def _concurrency_control(self, schema_name: str, prop_dict: dict) -> Optional[str]:
|
|
138
132
|
concurrency_control = prop_dict.get("x-af-concurrency-control", None)
|
|
139
133
|
if concurrency_control:
|
|
140
134
|
concurrency_control = concurrency_control.lower()
|
|
@@ -153,9 +147,7 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
153
147
|
class SchemaObjectKey(SchemaObjectProperty):
|
|
154
148
|
"""Represents a primary key in a schema object."""
|
|
155
149
|
|
|
156
|
-
def __init__(
|
|
157
|
-
self, schema_name: str, name: str, properties: Dict[str, Any]
|
|
158
|
-
):
|
|
150
|
+
def __init__(self, schema_name: str, name: str, properties: Dict[str, Any]):
|
|
159
151
|
super().__init__(schema_name, name, properties)
|
|
160
152
|
self.key_type = properties.get("x-af-primary-key", "auto")
|
|
161
153
|
|
|
@@ -212,9 +204,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
212
204
|
self.properties = self._resolve_properties(schema_object)
|
|
213
205
|
self.primary_key = self._get_primary_key(schema_object)
|
|
214
206
|
self.relations = self._resolve_relations(schema_object)
|
|
215
|
-
self.concurrency_property = self._get_concurrency_property(
|
|
216
|
-
schema_object
|
|
217
|
-
)
|
|
207
|
+
self.concurrency_property = self._get_concurrency_property(schema_object)
|
|
218
208
|
self.permissions = self._get_permissions(schema_object)
|
|
219
209
|
|
|
220
210
|
def _get_table_name(self, schema_object: dict) -> str:
|
|
@@ -305,19 +295,14 @@ class SchemaObject(OpenAPIElement):
|
|
|
305
295
|
property_name, prop, self.primary_key
|
|
306
296
|
)
|
|
307
297
|
# Array of $ref (array relation)
|
|
308
|
-
elif (
|
|
309
|
-
prop.get("type") == "array"
|
|
310
|
-
and "$ref" in prop.get("items", {})
|
|
311
|
-
):
|
|
298
|
+
elif prop.get("type") == "array" and "$ref" in prop.get("items", {}):
|
|
312
299
|
relations[property_name.lower()] = SchemaObjectAssociation(
|
|
313
300
|
property_name, prop, self.primary_key
|
|
314
301
|
)
|
|
315
302
|
return relations
|
|
316
303
|
|
|
317
304
|
def _get_concurrency_property(self, schema_object: dict) -> Optional[str]:
|
|
318
|
-
concurrency_property_name = schema_object.get(
|
|
319
|
-
"x-af-concurrency-control"
|
|
320
|
-
)
|
|
305
|
+
concurrency_property_name = schema_object.get("x-af-concurrency-control")
|
|
321
306
|
if (
|
|
322
307
|
concurrency_property_name
|
|
323
308
|
and concurrency_property_name not in self.properties
|
|
@@ -332,14 +317,10 @@ class SchemaObject(OpenAPIElement):
|
|
|
332
317
|
return concurrency_property_name
|
|
333
318
|
|
|
334
319
|
def _get_primary_key(self, schema_object: dict) -> Optional[str]:
|
|
335
|
-
for property_name, properties in schema_object.get(
|
|
336
|
-
"properties", {}
|
|
337
|
-
).items():
|
|
320
|
+
for property_name, properties in schema_object.get("properties", {}).items():
|
|
338
321
|
if "x-af-primary-key" in properties:
|
|
339
322
|
prop_obj = self.properties[property_name]
|
|
340
|
-
prop_obj.key_type = properties.get(
|
|
341
|
-
"x-af-primary-key", "auto"
|
|
342
|
-
)
|
|
323
|
+
prop_obj.key_type = properties.get("x-af-primary-key", "auto")
|
|
343
324
|
|
|
344
325
|
if prop_obj.key_type not in [
|
|
345
326
|
"manual",
|
|
@@ -357,9 +338,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
357
338
|
)
|
|
358
339
|
|
|
359
340
|
if prop_obj.key_type == "sequence":
|
|
360
|
-
prop_obj.sequence_name = properties.get(
|
|
361
|
-
"x-af-sequence-name", None
|
|
362
|
-
)
|
|
341
|
+
prop_obj.sequence_name = properties.get("x-af-sequence-name", None)
|
|
363
342
|
if not prop_obj.sequence_name:
|
|
364
343
|
raise ApplicationException(
|
|
365
344
|
500,
|
|
@@ -395,11 +374,13 @@ class SchemaObject(OpenAPIElement):
|
|
|
395
374
|
if isinstance(v, dict):
|
|
396
375
|
# Any dict that looks like action->rule (value not dict)
|
|
397
376
|
for k2, v2 in v.items():
|
|
398
|
-
if
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
377
|
+
if k2 in {
|
|
378
|
+
"read",
|
|
379
|
+
"write",
|
|
380
|
+
"delete",
|
|
381
|
+
"create",
|
|
382
|
+
"update",
|
|
383
|
+
} and not isinstance(v2, dict):
|
|
403
384
|
return True
|
|
404
385
|
return False
|
|
405
386
|
|
|
@@ -429,9 +410,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
429
410
|
def to_dict(self) -> Dict[str, Any]:
|
|
430
411
|
"""Recursively convert this schema object and its properties."""
|
|
431
412
|
data = super().to_dict()
|
|
432
|
-
data["properties"] = {
|
|
433
|
-
k: v.to_dict() for k, v in self.properties.items()
|
|
434
|
-
}
|
|
413
|
+
data["properties"] = {k: v.to_dict() for k, v in self.properties.items()}
|
|
435
414
|
data["relations"] = {k: v.to_dict() for k, v in self.relations.items()}
|
|
436
415
|
if self.concurrency_property:
|
|
437
416
|
data["concurrency_property"] = self.concurrency_property
|
|
@@ -477,9 +456,7 @@ class PathOperation(OpenAPIElement):
|
|
|
477
456
|
for name, prop_schema in (
|
|
478
457
|
path_operation.get("requestBody", {}).get("content", {}) or {}
|
|
479
458
|
).items():
|
|
480
|
-
properties[name] = SchemaObjectProperty(
|
|
481
|
-
self.entity, name, prop_schema
|
|
482
|
-
)
|
|
459
|
+
properties[name] = SchemaObjectProperty(self.entity, name, prop_schema)
|
|
483
460
|
elif section == "parameters":
|
|
484
461
|
for param in path_operation.get("parameters", {}) or []:
|
|
485
462
|
properties[param["name"]] = SchemaObjectProperty(
|
|
@@ -524,11 +501,13 @@ class PathOperation(OpenAPIElement):
|
|
|
524
501
|
for v in obj.values():
|
|
525
502
|
if isinstance(v, dict):
|
|
526
503
|
for k2, v2 in v.items():
|
|
527
|
-
if
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
504
|
+
if k2 in {
|
|
505
|
+
"read",
|
|
506
|
+
"write",
|
|
507
|
+
"delete",
|
|
508
|
+
"create",
|
|
509
|
+
"update",
|
|
510
|
+
} and not isinstance(v2, dict):
|
|
532
511
|
return True
|
|
533
512
|
return False
|
|
534
513
|
|
|
@@ -632,11 +611,9 @@ class ModelFactory:
|
|
|
632
611
|
log.info("path_operations: %s", self.path_operations)
|
|
633
612
|
return {
|
|
634
613
|
"schema_objects": {
|
|
635
|
-
name: obj.to_dict()
|
|
636
|
-
for name, obj in self.schema_objects.items()
|
|
614
|
+
name: obj.to_dict() for name, obj in self.schema_objects.items()
|
|
637
615
|
},
|
|
638
616
|
"path_operations": {
|
|
639
|
-
name: obj.to_dict()
|
|
640
|
-
for name, obj in self.path_operations.items()
|
|
617
|
+
name: obj.to_dict() for name, obj in self.path_operations.items()
|
|
641
618
|
},
|
|
642
619
|
}
|
|
@@ -36,7 +36,7 @@ def validate_permissions(permissions):
|
|
|
36
36
|
def _validate_rule(action: str, role_name: str, rule):
|
|
37
37
|
if action in {"read", "write"}:
|
|
38
38
|
# Accept either a string regex or an object
|
|
39
|
-
# {
|
|
39
|
+
# {properties: regex, where?: string}
|
|
40
40
|
if isinstance(rule, str):
|
|
41
41
|
try:
|
|
42
42
|
re.compile(rule)
|
|
@@ -52,7 +52,8 @@ def validate_permissions(permissions):
|
|
|
52
52
|
+ str(e)
|
|
53
53
|
) from e
|
|
54
54
|
elif isinstance(rule, dict):
|
|
55
|
-
|
|
55
|
+
# Support both for backward compatibility
|
|
56
|
+
allowed_keys = {"properties", "fields", "where"}
|
|
56
57
|
unknown = set(rule.keys()) - allowed_keys
|
|
57
58
|
if unknown:
|
|
58
59
|
raise ValueError(
|
|
@@ -60,18 +61,19 @@ def validate_permissions(permissions):
|
|
|
60
61
|
f"'{role_name}' action '{action}'. "
|
|
61
62
|
f"Allowed keys: {allowed_keys}."
|
|
62
63
|
)
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
# Accept both 'properties' (preferred) and 'fields' (legacy)
|
|
65
|
+
properties = rule.get("properties") or rule.get("fields")
|
|
66
|
+
if not isinstance(properties, str):
|
|
65
67
|
raise ValueError(
|
|
66
68
|
f"Rule for role '{role_name}' action "
|
|
67
|
-
f"'{action}' must include '
|
|
69
|
+
f"'{action}' must include 'properties' as a regex "
|
|
68
70
|
f"string."
|
|
69
71
|
)
|
|
70
72
|
try:
|
|
71
|
-
re.compile(
|
|
73
|
+
re.compile(properties)
|
|
72
74
|
except re.error as e:
|
|
73
75
|
raise ValueError(
|
|
74
|
-
"Invalid regex pattern in '
|
|
76
|
+
"Invalid regex pattern in 'properties' for role '"
|
|
75
77
|
+ role_name
|
|
76
78
|
+ "' action '"
|
|
77
79
|
+ action
|
|
@@ -87,7 +89,7 @@ def validate_permissions(permissions):
|
|
|
87
89
|
else:
|
|
88
90
|
raise ValueError(
|
|
89
91
|
f"Rule for role '{role_name}' action '{action}' "
|
|
90
|
-
f"must be a string or object with '
|
|
92
|
+
f"must be a string or object with 'properties' "
|
|
91
93
|
f"(and optional 'where')."
|
|
92
94
|
)
|
|
93
95
|
|
|
@@ -130,22 +132,25 @@ def validate_permissions(permissions):
|
|
|
130
132
|
f"'read', 'write', and 'delete'."
|
|
131
133
|
)
|
|
132
134
|
|
|
133
|
-
# Detect legacy form: role -> {action: rule}
|
|
135
|
+
# Detect legacy form: role -> {action: rule} or role with 'where'
|
|
134
136
|
def _is_legacy_form(obj: dict) -> bool:
|
|
135
137
|
if not obj:
|
|
136
138
|
return False
|
|
137
139
|
# If any top-level value is a dict where an action maps to a non-dict
|
|
138
140
|
# rule (e.g., string/bool/object rule), it's the legacy form.
|
|
141
|
+
# Also detect if there's a 'where' key at the role level.
|
|
139
142
|
for v in obj.values():
|
|
140
143
|
if isinstance(v, dict):
|
|
144
|
+
# Check for role-level 'where' clause (hybrid approach)
|
|
145
|
+
if "where" in v:
|
|
146
|
+
return True
|
|
141
147
|
for k2, v2 in v.items():
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
):
|
|
148
|
+
actions = {"read", "write", "delete"}
|
|
149
|
+
if k2 in actions and not isinstance(v2, dict):
|
|
145
150
|
return True
|
|
146
151
|
return False
|
|
147
152
|
|
|
148
|
-
# Legacy path: {role: {read|write|delete: rule}}
|
|
153
|
+
# Legacy path: {role: {read|write|delete: rule, where?: string}}
|
|
149
154
|
if _is_legacy_form(permissions):
|
|
150
155
|
for role_name, actions in permissions.items():
|
|
151
156
|
if not isinstance(role_name, str):
|
|
@@ -156,7 +161,15 @@ def validate_permissions(permissions):
|
|
|
156
161
|
f"of actions."
|
|
157
162
|
)
|
|
158
163
|
for action, rule in actions.items():
|
|
159
|
-
|
|
164
|
+
if action == "where":
|
|
165
|
+
# Validate role-level WHERE clause
|
|
166
|
+
if not isinstance(rule, str):
|
|
167
|
+
raise ValueError(
|
|
168
|
+
f"Role-level 'where' clause for role "
|
|
169
|
+
f"'{role_name}' must be a string."
|
|
170
|
+
)
|
|
171
|
+
else:
|
|
172
|
+
_validate_rule(action, role_name, rule)
|
|
160
173
|
return True
|
|
161
174
|
|
|
162
175
|
# New form: {provider: {action: {role: rule}}}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|