api-foundry 0.8.9__tar.gz → 0.8.11__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.9 → api_foundry-0.8.11}/PKG-INFO +3 -2
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/__init__.py +1 -1
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/iac/gateway_spec.py +11 -5
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/iac/pulumi/api_foundry.py +34 -14
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/scripts/install_secret.py +16 -6
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/utils/model_factory.py +26 -33
- {api_foundry-0.8.9 → api_foundry-0.8.11}/pyproject.toml +3 -0
- {api_foundry-0.8.9 → api_foundry-0.8.11}/.gitignore +0 -0
- {api_foundry-0.8.9 → api_foundry-0.8.11}/LICENSE +0 -0
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/scripts/postgres_to_openapi.py +0 -0
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/utils/logger.py +0 -0
- {api_foundry-0.8.9 → api_foundry-0.8.11}/api_foundry/utils/schema_validator.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: api-foundry
|
|
3
|
-
Version: 0.8.
|
|
3
|
+
Version: 0.8.11
|
|
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
|
|
@@ -25,3 +25,4 @@ Requires-Dist: docker; extra == 'dev'
|
|
|
25
25
|
Requires-Dist: psycopg2-binary; extra == 'dev'
|
|
26
26
|
Requires-Dist: pulumi-automation; extra == 'dev'
|
|
27
27
|
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: simple-oauth-server; extra == 'dev'
|
|
@@ -177,7 +177,6 @@ class APISpecEditor:
|
|
|
177
177
|
|
|
178
178
|
def generate_regex(self, property: dict[str, Any]) -> str:
|
|
179
179
|
regex_pattern = ""
|
|
180
|
-
relational_patterns = []
|
|
181
180
|
|
|
182
181
|
# UUID (either explicit type 'uuid' or string with format 'uuid')
|
|
183
182
|
if property.get("type") == "uuid" or (
|
|
@@ -215,7 +214,7 @@ class APISpecEditor:
|
|
|
215
214
|
else:
|
|
216
215
|
max_length = property.get("max_length", 200)
|
|
217
216
|
min_length = property.get("min_length", 0)
|
|
218
|
-
regex_pattern = rf"[\w\s]{min_length},{max_length}"
|
|
217
|
+
regex_pattern = rf"[\w\s]{{{min_length},{max_length}}}"
|
|
219
218
|
# Allows letters, numbers, and underscores
|
|
220
219
|
|
|
221
220
|
elif property["type"] == "integer":
|
|
@@ -228,17 +227,24 @@ class APISpecEditor:
|
|
|
228
227
|
if len(regex_pattern) == 0:
|
|
229
228
|
regex_pattern = ".*"
|
|
230
229
|
|
|
231
|
-
|
|
230
|
+
full_pattern = (
|
|
232
231
|
rf"^{regex_pattern}$"
|
|
233
232
|
+ rf"|^(?:lt::|le::|eq::|ne::|ge::|gt::)?{regex_pattern}$"
|
|
234
233
|
+ rf"|^between::{regex_pattern},{regex_pattern}$"
|
|
235
234
|
+ rf"|^not-between::{regex_pattern},{regex_pattern},"
|
|
236
235
|
+ rf"|^in::{regex_pattern}(,{regex_pattern})*$"
|
|
237
236
|
+ rf"|^not-in::{regex_pattern}(,{regex_pattern})*$"
|
|
238
|
-
+ rf"|^like::.+$"
|
|
239
|
-
+ rf"|^not-like::.+$"
|
|
240
237
|
)
|
|
241
238
|
|
|
239
|
+
# like/not-like only make sense for string-typed properties -- an
|
|
240
|
+
# integer or number property matching "like::123" is meaningless,
|
|
241
|
+
# and unconditionally allowing it let non-string filters through
|
|
242
|
+
# that the SQL layer can't actually execute as a LIKE comparison.
|
|
243
|
+
if property["type"] == "string":
|
|
244
|
+
full_pattern += r"|^like::.+$" + r"|^not-like::.+$"
|
|
245
|
+
|
|
246
|
+
return full_pattern
|
|
247
|
+
|
|
242
248
|
def generate_query_parameters(self, schema_object: dict[str, Any]):
|
|
243
249
|
parameters = []
|
|
244
250
|
for (
|
|
@@ -122,7 +122,7 @@ class APIFoundry(ComponentResource):
|
|
|
122
122
|
*,
|
|
123
123
|
api_spec: Union[str, list[str]],
|
|
124
124
|
batch_path: Optional[str] = None,
|
|
125
|
-
secrets: Optional[str] = None,
|
|
125
|
+
secrets: Optional[Union[str, pulumi.Output[str]]] = None,
|
|
126
126
|
path_prefix: Optional[str] = None,
|
|
127
127
|
environment: Optional[dict[str, Union[str, pulumi.Output[str]]]] = None,
|
|
128
128
|
integrations: Optional[list[dict]] = None,
|
|
@@ -158,25 +158,38 @@ class APIFoundry(ComponentResource):
|
|
|
158
158
|
|
|
159
159
|
# Grant read access to referenced secrets
|
|
160
160
|
if secrets:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
"Effect": "Allow",
|
|
166
|
-
"Actions": ["secretsmanager:GetSecretValue"],
|
|
167
|
-
"Resources": secret_arns,
|
|
168
|
-
}
|
|
169
|
-
)
|
|
170
|
-
except (json.JSONDecodeError, AttributeError):
|
|
171
|
-
# If secrets is an Output or invalid JSON, we can't parse it yet
|
|
172
|
-
# Add a broad policy (will be restricted during deployment)
|
|
161
|
+
if isinstance(secrets, pulumi.Output):
|
|
162
|
+
# Resolve the ARNs at deploy time rather than widening the
|
|
163
|
+
# grant to "*". The statement list is resolved as a whole
|
|
164
|
+
# before it reaches cloud_foundry (see below).
|
|
173
165
|
policy_statements.append(
|
|
174
166
|
{
|
|
175
167
|
"Effect": "Allow",
|
|
176
168
|
"Actions": ["secretsmanager:GetSecretValue"],
|
|
177
|
-
"Resources":
|
|
169
|
+
"Resources": secrets.apply(
|
|
170
|
+
lambda s: list(json.loads(s).values())
|
|
171
|
+
),
|
|
178
172
|
}
|
|
179
173
|
)
|
|
174
|
+
else:
|
|
175
|
+
try:
|
|
176
|
+
secret_arns = list(json.loads(secrets).values())
|
|
177
|
+
policy_statements.append(
|
|
178
|
+
{
|
|
179
|
+
"Effect": "Allow",
|
|
180
|
+
"Actions": ["secretsmanager:GetSecretValue"],
|
|
181
|
+
"Resources": secret_arns,
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
except (json.JSONDecodeError, AttributeError):
|
|
185
|
+
# Invalid JSON: fall back to a broad policy
|
|
186
|
+
policy_statements.append(
|
|
187
|
+
{
|
|
188
|
+
"Effect": "Allow",
|
|
189
|
+
"Actions": ["secretsmanager:GetSecretValue"],
|
|
190
|
+
"Resources": "*",
|
|
191
|
+
}
|
|
192
|
+
)
|
|
180
193
|
|
|
181
194
|
requirements.extend(
|
|
182
195
|
[
|
|
@@ -212,6 +225,12 @@ class APIFoundry(ComponentResource):
|
|
|
212
225
|
if env_vars.get("JWKS_HOST"):
|
|
213
226
|
requirements.extend(["PyJWT", "cryptography", "requests"])
|
|
214
227
|
|
|
228
|
+
if isinstance(secrets, pulumi.Output):
|
|
229
|
+
# cloud_foundry builds the role policy from plain statements, but
|
|
230
|
+
# accepts the statement list itself as an Output. Resolve the
|
|
231
|
+
# list (including Outputs nested in Resources) as one Output.
|
|
232
|
+
policy_statements = pulumi.Output.from_input(policy_statements)
|
|
233
|
+
|
|
215
234
|
self.api_function = cloud_foundry.python_function(
|
|
216
235
|
name=name,
|
|
217
236
|
environment=env_vars,
|
|
@@ -234,6 +253,7 @@ class APIFoundry(ComponentResource):
|
|
|
234
253
|
batch_path=batch_path,
|
|
235
254
|
token_validators=token_validators,
|
|
236
255
|
)
|
|
256
|
+
self.api_spec_editor = gateway_spec
|
|
237
257
|
|
|
238
258
|
# Merge gateway_spec.integrations with user-provided integrations
|
|
239
259
|
specification = gateway_spec.rest_api_spec()
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import argparse
|
|
2
|
+
import os
|
|
2
3
|
import boto3
|
|
3
4
|
import json
|
|
4
5
|
|
|
5
6
|
from botocore.exceptions import ClientError
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
def create_secret_if_not_exists(secret_name, secret_value):
|
|
9
|
-
# Create a Secrets Manager client
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
)
|
|
9
|
+
def create_secret_if_not_exists(secret_name, secret_value, endpoint_url=None):
|
|
10
|
+
# Create a Secrets Manager client. endpoint_url is None (real AWS
|
|
11
|
+
# Secrets Manager) unless explicitly overridden, e.g. for testing
|
|
12
|
+
# against LocalStack.
|
|
13
|
+
client = boto3.client("secretsmanager", endpoint_url=endpoint_url)
|
|
13
14
|
|
|
14
15
|
try:
|
|
15
16
|
# Check if the secret already exists
|
|
@@ -55,6 +56,15 @@ def main():
|
|
|
55
56
|
parser.add_argument(
|
|
56
57
|
"--schema", default="public", help="The database schema (default: public)"
|
|
57
58
|
)
|
|
59
|
+
parser.add_argument(
|
|
60
|
+
"--endpoint-url",
|
|
61
|
+
default=os.environ.get("AWS_ENDPOINT_URL"),
|
|
62
|
+
help=(
|
|
63
|
+
"Optional AWS endpoint URL override, e.g. for testing against "
|
|
64
|
+
"LocalStack. Defaults to the AWS_ENDPOINT_URL environment "
|
|
65
|
+
"variable, or real AWS Secrets Manager if unset."
|
|
66
|
+
),
|
|
67
|
+
)
|
|
58
68
|
|
|
59
69
|
args = parser.parse_args()
|
|
60
70
|
|
|
@@ -70,7 +80,7 @@ def main():
|
|
|
70
80
|
}
|
|
71
81
|
)
|
|
72
82
|
|
|
73
|
-
create_secret_if_not_exists(args.secret_name, secret_value)
|
|
83
|
+
create_secret_if_not_exists(args.secret_name, secret_value, args.endpoint_url)
|
|
74
84
|
|
|
75
85
|
|
|
76
86
|
if __name__ == "__main__":
|
|
@@ -263,38 +263,24 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
263
263
|
|
|
264
264
|
return soft_delete_config
|
|
265
265
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
(
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
),
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
self.sequence_name = (
|
|
285
|
-
properties.get("x-af-sequence-name")
|
|
286
|
-
if self.key_type == "sequence"
|
|
287
|
-
else None
|
|
288
|
-
)
|
|
289
|
-
if self.key_type == "sequence" and not self.sequence_name:
|
|
290
|
-
raise ApplicationException(
|
|
291
|
-
500,
|
|
292
|
-
(
|
|
293
|
-
"Sequence-based primary keys must have a sequence name in "
|
|
294
|
-
+ f"schema object '{schema_name}', "
|
|
295
|
-
+ f"property '{self.api_name}'"
|
|
296
|
-
),
|
|
297
|
-
)
|
|
266
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
267
|
+
"""
|
|
268
|
+
Convert to a dictionary, recursively converting sub_properties and
|
|
269
|
+
items_sub_properties (dicts of SchemaObjectProperty for embedded
|
|
270
|
+
objects and arrays of embedded objects), which the base
|
|
271
|
+
OpenAPIElement.to_dict() does not recurse into since they are
|
|
272
|
+
plain dicts rather than OpenAPIElement instances themselves.
|
|
273
|
+
"""
|
|
274
|
+
data = super().to_dict()
|
|
275
|
+
if self.sub_properties is not None:
|
|
276
|
+
data["sub_properties"] = {
|
|
277
|
+
k: v.to_dict() for k, v in self.sub_properties.items()
|
|
278
|
+
}
|
|
279
|
+
if self.items_sub_properties is not None:
|
|
280
|
+
data["items_sub_properties"] = {
|
|
281
|
+
k: v.to_dict() for k, v in self.items_sub_properties.items()
|
|
282
|
+
}
|
|
283
|
+
return data
|
|
298
284
|
|
|
299
285
|
|
|
300
286
|
class SchemaObjectAssociation(OpenAPIElement):
|
|
@@ -691,8 +677,15 @@ class PathOperation(OpenAPIElement):
|
|
|
691
677
|
properties[name] = SchemaObjectProperty(self.entity, name, prop_schema)
|
|
692
678
|
elif section == "parameters":
|
|
693
679
|
for param in path_operation.get("parameters", {}) or []:
|
|
680
|
+
# OpenAPI parameter objects nest type/default/etc. under
|
|
681
|
+
# `schema` (unlike requestBody/responses properties, which
|
|
682
|
+
# are already flat) -- merge schema over the parameter
|
|
683
|
+
# object so type/default/minLength/etc. are read from the
|
|
684
|
+
# right place while still keeping parameter-level fields
|
|
685
|
+
# like `required` and `description`.
|
|
686
|
+
merged = {**param, **(param.get("schema") or {})}
|
|
694
687
|
properties[param["name"]] = SchemaObjectProperty(
|
|
695
|
-
self.entity, param["name"],
|
|
688
|
+
self.entity, param["name"], merged
|
|
696
689
|
)
|
|
697
690
|
elif section == "responses":
|
|
698
691
|
responses = path_operation.get("responses", {})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|