api-foundry 0.1.30__tar.gz → 0.8.2__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.30 → api_foundry-0.8.2}/PKG-INFO +1 -1
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/iac/pulumi/api_foundry.py +8 -5
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/utils/model_factory.py +75 -66
- {api_foundry-0.1.30 → api_foundry-0.8.2}/pyproject.toml +1 -1
- {api_foundry-0.1.30 → api_foundry-0.8.2}/.gitignore +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/LICENSE +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/__init__.py +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/iac/gateway_spec.py +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/scripts/install_secret.py +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/scripts/postgres_to_openapi.py +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/utils/logger.py +0 -0
- {api_foundry-0.1.30 → api_foundry-0.8.2}/api_foundry/utils/schema_validator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: api-foundry
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.2
|
|
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
|
|
@@ -149,6 +149,7 @@ class APIFoundry(ComponentResource):
|
|
|
149
149
|
vpc_config = vpc_config or config_defaults.get("vpc_config", {})
|
|
150
150
|
|
|
151
151
|
env_vars["SECRETS"] = secrets
|
|
152
|
+
requirements = []
|
|
152
153
|
|
|
153
154
|
# Grant read access to referenced secrets (single broad stmt)
|
|
154
155
|
if json.loads(secrets):
|
|
@@ -160,6 +161,12 @@ class APIFoundry(ComponentResource):
|
|
|
160
161
|
}
|
|
161
162
|
)
|
|
162
163
|
|
|
164
|
+
requirements.extend(
|
|
165
|
+
["psycopg2-binary", "pyyaml", "../api_foundry_query_engine"]
|
|
166
|
+
)
|
|
167
|
+
if env_vars.get("JWKS_HOST"):
|
|
168
|
+
requirements.extend(["PyJWT", "cryptography", "requests"])
|
|
169
|
+
|
|
163
170
|
self.api_function = cloud_foundry.python_function(
|
|
164
171
|
name=name,
|
|
165
172
|
environment=env_vars,
|
|
@@ -169,11 +176,7 @@ class APIFoundry(ComponentResource):
|
|
|
169
176
|
ModelFactory(api_spec_dict).get_config_output()
|
|
170
177
|
),
|
|
171
178
|
},
|
|
172
|
-
requirements=
|
|
173
|
-
"psycopg2-binary",
|
|
174
|
-
"pyyaml",
|
|
175
|
-
"api_foundry_query_engine",
|
|
176
|
-
],
|
|
179
|
+
requirements=requirements,
|
|
177
180
|
policy_statements=policy_statements,
|
|
178
181
|
vpc_config=vpc_config,
|
|
179
182
|
)
|
|
@@ -124,6 +124,9 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
124
124
|
self.key_type = None
|
|
125
125
|
self.sequence_name = None
|
|
126
126
|
self.concurrency_control = self._concurrency_control(schema_name, prop)
|
|
127
|
+
# Value injection attributes
|
|
128
|
+
self.inject_value = prop.get("x-af-inject-value", None)
|
|
129
|
+
self.inject_on = self._parse_inject_on(name, prop) or None
|
|
127
130
|
# For embedded objects/arrays
|
|
128
131
|
self.sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
|
|
129
132
|
self.items_sub_properties: Optional[Dict[str, SchemaObjectProperty]] = None
|
|
@@ -143,6 +146,47 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
143
146
|
)
|
|
144
147
|
return concurrency_control
|
|
145
148
|
|
|
149
|
+
def _parse_inject_on(self, property_name: str, prop_dict: dict) -> list[str]:
|
|
150
|
+
"""
|
|
151
|
+
Parse x-af-inject-on attribute or infer default behavior based on
|
|
152
|
+
property name and x-af-inject-value presence.
|
|
153
|
+
"""
|
|
154
|
+
inject_value = prop_dict.get("x-af-inject-value")
|
|
155
|
+
if not inject_value:
|
|
156
|
+
return []
|
|
157
|
+
|
|
158
|
+
# Explicit configuration takes precedence
|
|
159
|
+
if "x-af-inject-on" in prop_dict:
|
|
160
|
+
inject_on = prop_dict["x-af-inject-on"]
|
|
161
|
+
if isinstance(inject_on, list):
|
|
162
|
+
return inject_on
|
|
163
|
+
return [inject_on]
|
|
164
|
+
|
|
165
|
+
# Infer from property name patterns
|
|
166
|
+
# Properties starting with "created" default to create-only
|
|
167
|
+
if property_name.startswith("created_"):
|
|
168
|
+
return ["create"]
|
|
169
|
+
|
|
170
|
+
# Properties starting with "updated" default to update-only
|
|
171
|
+
if property_name.startswith("updated_"):
|
|
172
|
+
return ["update"]
|
|
173
|
+
|
|
174
|
+
# Properties ending with "_by" or "_at" default to create-only
|
|
175
|
+
if property_name.endswith(("_by", "_at")):
|
|
176
|
+
return ["create"]
|
|
177
|
+
|
|
178
|
+
# Tenant/owner fields default to create-only (immutable)
|
|
179
|
+
if property_name in [
|
|
180
|
+
"tenant_id",
|
|
181
|
+
"owner_id",
|
|
182
|
+
"organization_id",
|
|
183
|
+
"workspace_id",
|
|
184
|
+
]:
|
|
185
|
+
return ["create"]
|
|
186
|
+
|
|
187
|
+
# Default: inject only on create for safety
|
|
188
|
+
return ["create"]
|
|
189
|
+
|
|
146
190
|
|
|
147
191
|
class SchemaObjectKey(SchemaObjectProperty):
|
|
148
192
|
"""Represents a primary key in a schema object."""
|
|
@@ -206,6 +250,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
206
250
|
self.relations = self._resolve_relations(schema_object)
|
|
207
251
|
self.concurrency_property = self._get_concurrency_property(schema_object)
|
|
208
252
|
self.permissions = self._get_permissions(schema_object)
|
|
253
|
+
self.inject_properties = self._get_inject_properties()
|
|
209
254
|
|
|
210
255
|
def _get_table_name(self, schema_object: dict) -> str:
|
|
211
256
|
schema = schema_object.get("x-af-schema")
|
|
@@ -355,6 +400,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
355
400
|
def _get_permissions(self, schema_object: dict) -> dict:
|
|
356
401
|
"""Extract permissions from schema using x-af-permissions only.
|
|
357
402
|
|
|
403
|
+
Expects provider -> action -> role -> rule format.
|
|
358
404
|
Also normalizes action names so 'create'/'update' map to 'write'.
|
|
359
405
|
"""
|
|
360
406
|
raw_permissions = schema_object.get("x-af-permissions") or {}
|
|
@@ -366,47 +412,34 @@ class SchemaObject(OpenAPIElement):
|
|
|
366
412
|
result[key] = value
|
|
367
413
|
return result
|
|
368
414
|
|
|
369
|
-
def is_legacy_role_form(obj: Dict[str, Any]) -> bool:
|
|
370
|
-
# Legacy: role -> { action: rule }
|
|
371
|
-
if not isinstance(obj, dict):
|
|
372
|
-
return False
|
|
373
|
-
for v in obj.values():
|
|
374
|
-
if isinstance(v, dict):
|
|
375
|
-
# Any dict that looks like action->rule (value not dict)
|
|
376
|
-
for k2, v2 in v.items():
|
|
377
|
-
if k2 in {
|
|
378
|
-
"read",
|
|
379
|
-
"write",
|
|
380
|
-
"delete",
|
|
381
|
-
"create",
|
|
382
|
-
"update",
|
|
383
|
-
} and not isinstance(v2, dict):
|
|
384
|
-
return True
|
|
385
|
-
return False
|
|
386
|
-
|
|
387
415
|
normalized: Dict[str, Any] = {}
|
|
388
416
|
if isinstance(raw_permissions, dict):
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
normalized[role] = actions
|
|
396
|
-
else:
|
|
397
|
-
# New form: provider -> action -> role
|
|
398
|
-
for provider, actions in raw_permissions.items():
|
|
399
|
-
if isinstance(actions, dict):
|
|
400
|
-
normalized[provider] = normalize_actions(actions)
|
|
401
|
-
else:
|
|
402
|
-
normalized[provider] = actions
|
|
403
|
-
else:
|
|
404
|
-
normalized = {}
|
|
417
|
+
# Expected format: provider -> action -> role -> rule
|
|
418
|
+
for provider, actions in raw_permissions.items():
|
|
419
|
+
if isinstance(actions, dict):
|
|
420
|
+
normalized[provider] = normalize_actions(actions)
|
|
421
|
+
else:
|
|
422
|
+
normalized[provider] = actions
|
|
405
423
|
|
|
406
424
|
if normalized:
|
|
407
425
|
validate_permissions(normalized)
|
|
408
426
|
return normalized or {}
|
|
409
427
|
|
|
428
|
+
def _get_inject_properties(self) -> dict:
|
|
429
|
+
"""
|
|
430
|
+
Collect all properties that have injection attributes.
|
|
431
|
+
|
|
432
|
+
Returns a dictionary mapping property names to their injection metadata.
|
|
433
|
+
"""
|
|
434
|
+
inject_props = {}
|
|
435
|
+
for prop_name, prop in self.properties.items():
|
|
436
|
+
if hasattr(prop, "inject_value") and prop.inject_value:
|
|
437
|
+
inject_props[prop_name] = {
|
|
438
|
+
"inject_value": prop.inject_value,
|
|
439
|
+
"inject_on": getattr(prop, "inject_on", ["create"]),
|
|
440
|
+
}
|
|
441
|
+
return inject_props
|
|
442
|
+
|
|
410
443
|
def to_dict(self) -> Dict[str, Any]:
|
|
411
444
|
"""Recursively convert this schema object and its properties."""
|
|
412
445
|
data = super().to_dict()
|
|
@@ -483,8 +516,8 @@ class PathOperation(OpenAPIElement):
|
|
|
483
516
|
def _get_permissions(self, path_operation: dict) -> dict:
|
|
484
517
|
"""
|
|
485
518
|
Extract permissions from a path operation using x-af-permissions
|
|
486
|
-
only.
|
|
487
|
-
'write'.
|
|
519
|
+
only. Expects provider -> action -> role -> rule format.
|
|
520
|
+
Also normalizes action names so 'create'/'update' map to 'write'.
|
|
488
521
|
"""
|
|
489
522
|
raw_permissions = path_operation.get("x-af-permissions") or {}
|
|
490
523
|
|
|
@@ -495,38 +528,14 @@ class PathOperation(OpenAPIElement):
|
|
|
495
528
|
result[key] = value
|
|
496
529
|
return result
|
|
497
530
|
|
|
498
|
-
def is_legacy_role_form(obj: Dict[str, Any]) -> bool:
|
|
499
|
-
if not isinstance(obj, dict):
|
|
500
|
-
return False
|
|
501
|
-
for v in obj.values():
|
|
502
|
-
if isinstance(v, dict):
|
|
503
|
-
for k2, v2 in v.items():
|
|
504
|
-
if k2 in {
|
|
505
|
-
"read",
|
|
506
|
-
"write",
|
|
507
|
-
"delete",
|
|
508
|
-
"create",
|
|
509
|
-
"update",
|
|
510
|
-
} and not isinstance(v2, dict):
|
|
511
|
-
return True
|
|
512
|
-
return False
|
|
513
|
-
|
|
514
531
|
normalized: Dict[str, Any] = {}
|
|
515
532
|
if isinstance(raw_permissions, dict):
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
else:
|
|
523
|
-
for provider, actions in raw_permissions.items():
|
|
524
|
-
if isinstance(actions, dict):
|
|
525
|
-
normalized[provider] = normalize_actions(actions)
|
|
526
|
-
else:
|
|
527
|
-
normalized[provider] = actions
|
|
528
|
-
else:
|
|
529
|
-
normalized = {}
|
|
533
|
+
# Expected format: provider -> action -> role -> rule
|
|
534
|
+
for provider, actions in raw_permissions.items():
|
|
535
|
+
if isinstance(actions, dict):
|
|
536
|
+
normalized[provider] = normalize_actions(actions)
|
|
537
|
+
else:
|
|
538
|
+
normalized[provider] = actions
|
|
530
539
|
|
|
531
540
|
if normalized:
|
|
532
541
|
validate_permissions(normalized)
|
|
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
|