api-foundry 0.8.6__tar.gz → 0.8.8__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.8.6 → api_foundry-0.8.8}/PKG-INFO +1 -1
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/__init__.py +1 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/iac/gateway_spec.py +68 -6
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/iac/pulumi/api_foundry.py +38 -1
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/utils/model_factory.py +17 -8
- {api_foundry-0.8.6 → api_foundry-0.8.8}/pyproject.toml +5 -1
- {api_foundry-0.8.6 → api_foundry-0.8.8}/.gitignore +0 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/LICENSE +0 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/scripts/install_secret.py +0 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/scripts/postgres_to_openapi.py +0 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/api_foundry/utils/logger.py +0 -0
- {api_foundry-0.8.6 → api_foundry-0.8.8}/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.8.
|
|
3
|
+
Version: 0.8.8
|
|
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
|
|
@@ -38,7 +38,8 @@ class APISpecEditor:
|
|
|
38
38
|
def _get_validators_for_schema(self, schema_object: dict) -> list[str]:
|
|
39
39
|
"""Extract validator names from schema object.
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Uses the global security scheme from the OpenAPI spec instead of
|
|
42
|
+
x-af-permissions provider keys.
|
|
42
43
|
"""
|
|
43
44
|
validators = []
|
|
44
45
|
|
|
@@ -46,16 +47,77 @@ class APISpecEditor:
|
|
|
46
47
|
if not isinstance(schema_object, dict):
|
|
47
48
|
return validators
|
|
48
49
|
|
|
49
|
-
#
|
|
50
|
+
# Check if schema has permissions (indicating it needs auth)
|
|
50
51
|
if "x-af-permissions" in schema_object:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
# Use the global security scheme from the spec
|
|
53
|
+
global_security = self.editor.get_spec_part(["security"], create=False)
|
|
54
|
+
if (
|
|
55
|
+
global_security
|
|
56
|
+
and isinstance(global_security, list)
|
|
57
|
+
and len(global_security) > 0
|
|
58
|
+
):
|
|
59
|
+
# Extract security scheme names from global security
|
|
60
|
+
# Format: [{"auth": []}, {"other": []}]
|
|
61
|
+
for sec_item in global_security:
|
|
62
|
+
if isinstance(sec_item, dict):
|
|
63
|
+
validators.extend(sec_item.keys())
|
|
64
|
+
|
|
65
|
+
# Fallback: if no global security, look for securitySchemes
|
|
66
|
+
if not validators:
|
|
67
|
+
security_schemes = self.editor.get_spec_part(
|
|
68
|
+
["components", "securitySchemes"], create=False
|
|
69
|
+
)
|
|
70
|
+
if security_schemes and isinstance(security_schemes, dict):
|
|
71
|
+
validators = list(security_schemes.keys())
|
|
55
72
|
|
|
56
73
|
return validators
|
|
57
74
|
|
|
75
|
+
def process_existing_path_operations(self):
|
|
76
|
+
"""Process existing path operations with x-af-database.
|
|
77
|
+
|
|
78
|
+
Scans the OpenAPI spec's paths section and adds integrations for
|
|
79
|
+
any custom SQL operations (those with x-af-database attribute).
|
|
80
|
+
This ensures custom path operations get Lambda integrations just
|
|
81
|
+
like auto-generated CRUD operations.
|
|
82
|
+
"""
|
|
83
|
+
paths = self.editor.get_spec_part(["paths"], create=False)
|
|
84
|
+
if not paths or not isinstance(paths, dict):
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
for path, path_item in paths.items():
|
|
88
|
+
if not isinstance(path_item, dict):
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
# Check each HTTP method
|
|
92
|
+
for method in ["get", "post", "put", "delete", "patch"]:
|
|
93
|
+
operation = path_item.get(method)
|
|
94
|
+
if not operation or not isinstance(operation, dict):
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
# Only process operations with x-af-database
|
|
98
|
+
# (indicates custom SQL managed by API Foundry)
|
|
99
|
+
if "x-af-database" not in operation:
|
|
100
|
+
continue
|
|
101
|
+
|
|
102
|
+
# Add to integrations list so cloud_foundry.rest_api
|
|
103
|
+
# will create the x-amazon-apigateway-integration
|
|
104
|
+
self.integrations.append(
|
|
105
|
+
{
|
|
106
|
+
"path": path,
|
|
107
|
+
"method": method,
|
|
108
|
+
"function": self.function,
|
|
109
|
+
}
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
log.info(
|
|
113
|
+
f"Added integration for custom SQL operation: "
|
|
114
|
+
f"{method.upper()} {path}"
|
|
115
|
+
)
|
|
116
|
+
|
|
58
117
|
def rest_api_spec(self) -> str:
|
|
118
|
+
# Process existing path operations with x-af-database (custom SQL operations)
|
|
119
|
+
self.process_existing_path_operations()
|
|
120
|
+
|
|
59
121
|
schemas = self.editor.get_spec_part(["components", "schemas"], create=False)
|
|
60
122
|
if schemas:
|
|
61
123
|
if isinstance(schemas, dict):
|
|
@@ -123,11 +123,15 @@ class APIFoundry(ComponentResource):
|
|
|
123
123
|
api_spec: Union[str, list[str]],
|
|
124
124
|
batch_path: Optional[str] = None,
|
|
125
125
|
secrets: Optional[str] = None,
|
|
126
|
+
path_prefix: Optional[str] = None,
|
|
126
127
|
environment: Optional[dict[str, Union[str, pulumi.Output[str]]]] = None,
|
|
127
128
|
integrations: Optional[list[dict]] = None,
|
|
128
129
|
token_validators: Optional[list[dict]] = None,
|
|
130
|
+
timeout_seconds: Optional[int] = None,
|
|
129
131
|
policy_statements: Optional[list] = None,
|
|
130
132
|
vpc_config: Optional[dict] = None,
|
|
133
|
+
hosted_zone_id: Optional[str] = None,
|
|
134
|
+
subdomain: Optional[str] = None,
|
|
131
135
|
export_api: Optional[str] = None,
|
|
132
136
|
opts=None,
|
|
133
137
|
):
|
|
@@ -175,14 +179,43 @@ class APIFoundry(ComponentResource):
|
|
|
175
179
|
)
|
|
176
180
|
|
|
177
181
|
requirements.extend(
|
|
178
|
-
[
|
|
182
|
+
[
|
|
183
|
+
"psycopg2-binary",
|
|
184
|
+
"pyyaml",
|
|
185
|
+
"api_foundry_query_engine",
|
|
186
|
+
]
|
|
179
187
|
)
|
|
188
|
+
|
|
189
|
+
# Configure Lambda-based token validation if validators are provided
|
|
190
|
+
if token_validators:
|
|
191
|
+
# Get the first validator function (primary validator)
|
|
192
|
+
primary_validator = token_validators[0]
|
|
193
|
+
validator_function = primary_validator.get("function")
|
|
194
|
+
|
|
195
|
+
if validator_function:
|
|
196
|
+
# Check if validator_function has 'arn' attribute
|
|
197
|
+
# (Pulumi Output)
|
|
198
|
+
if hasattr(validator_function, "arn"):
|
|
199
|
+
# Store the ARN for the query engine to invoke
|
|
200
|
+
env_vars["TOKEN_VALIDATOR_LAMBDA_ARN"] = validator_function.arn
|
|
201
|
+
|
|
202
|
+
# Grant invoke permission for the query lambda
|
|
203
|
+
policy_statements.append(
|
|
204
|
+
{
|
|
205
|
+
"Effect": "Allow",
|
|
206
|
+
"Actions": ["lambda:InvokeFunction"],
|
|
207
|
+
"Resources": [validator_function.arn],
|
|
208
|
+
}
|
|
209
|
+
)
|
|
210
|
+
log.info("Configured Lambda token validator for query engine")
|
|
211
|
+
|
|
180
212
|
if env_vars.get("JWKS_HOST"):
|
|
181
213
|
requirements.extend(["PyJWT", "cryptography", "requests"])
|
|
182
214
|
|
|
183
215
|
self.api_function = cloud_foundry.python_function(
|
|
184
216
|
name=name,
|
|
185
217
|
environment=env_vars,
|
|
218
|
+
runtime="python3.12",
|
|
186
219
|
handler="api_foundry_query_engine.lambda_handler.handler",
|
|
187
220
|
sources={
|
|
188
221
|
"api_spec.yaml": yaml.safe_dump(
|
|
@@ -190,6 +223,7 @@ class APIFoundry(ComponentResource):
|
|
|
190
223
|
),
|
|
191
224
|
},
|
|
192
225
|
requirements=requirements,
|
|
226
|
+
timeout=timeout_seconds or 30,
|
|
193
227
|
policy_statements=policy_statements,
|
|
194
228
|
vpc_config=vpc_config,
|
|
195
229
|
)
|
|
@@ -211,6 +245,9 @@ class APIFoundry(ComponentResource):
|
|
|
211
245
|
integrations=merged_integrations,
|
|
212
246
|
token_validators=token_validators or [],
|
|
213
247
|
export_api=export_api,
|
|
248
|
+
path_prefix=path_prefix,
|
|
249
|
+
hosted_zone_id=hosted_zone_id,
|
|
250
|
+
subdomain=subdomain,
|
|
214
251
|
opts=pulumi.ResourceOptions(parent=self),
|
|
215
252
|
)
|
|
216
253
|
|
|
@@ -620,9 +620,17 @@ class PathOperation(OpenAPIElement):
|
|
|
620
620
|
|
|
621
621
|
def __init__(self, path: str, method: str, path_operation: Dict[str, Any]):
|
|
622
622
|
super().__init__()
|
|
623
|
-
self.entity = path.lower().rsplit("/", 1)[-1]
|
|
624
623
|
self.action = METHODS_TO_ACTIONS[method]
|
|
625
624
|
|
|
625
|
+
parts = [p for p in path.lower().split("/") if p]
|
|
626
|
+
api_prefixes = {"api", "v1", "v2", "v3"}
|
|
627
|
+
literal_parts = [
|
|
628
|
+
p
|
|
629
|
+
for p in parts
|
|
630
|
+
if p not in api_prefixes and not (p.startswith("{") and p.endswith("}"))
|
|
631
|
+
]
|
|
632
|
+
self.entity = "_".join(literal_parts)
|
|
633
|
+
|
|
626
634
|
# Validate required x-af-database attribute
|
|
627
635
|
if "x-af-database" not in path_operation:
|
|
628
636
|
raise ApplicationException(
|
|
@@ -803,13 +811,14 @@ class ModelFactory:
|
|
|
803
811
|
"""Loads all path operations from the OpenAPI specification."""
|
|
804
812
|
path_operations = {}
|
|
805
813
|
paths = self.spec.get("paths", {})
|
|
806
|
-
|
|
807
|
-
for
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
814
|
+
if paths:
|
|
815
|
+
for path, methods in paths.items():
|
|
816
|
+
for method, operation in methods.items():
|
|
817
|
+
if "x-af-database" in operation:
|
|
818
|
+
path_operation = PathOperation(path, method, operation)
|
|
819
|
+
path_operations[
|
|
820
|
+
f"{path_operation.entity}_{path_operation.action}"
|
|
821
|
+
] = path_operation
|
|
813
822
|
return path_operations
|
|
814
823
|
|
|
815
824
|
def get_config_output(self) -> Dict[str, Any]:
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "api-foundry"
|
|
7
|
-
|
|
7
|
+
dynamic = ["version"]
|
|
8
8
|
authors = [
|
|
9
9
|
{ name="Daniel Repik", email="danrepik@icloud.com" },
|
|
10
10
|
]
|
|
@@ -54,6 +54,10 @@ install_secret = "api_foundry.scripts.install_secret:main"
|
|
|
54
54
|
[tool.hatch.metadata]
|
|
55
55
|
allow-direct-references = true
|
|
56
56
|
|
|
57
|
+
[tool.hatch.version]
|
|
58
|
+
path = "api_foundry/__init__.py"
|
|
59
|
+
|
|
60
|
+
|
|
57
61
|
[tool.pytest.ini_options]
|
|
58
62
|
markers = [
|
|
59
63
|
"unit: marks tests as unit tests that do not require a database",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|