api-foundry 0.1.4__tar.gz → 0.1.5__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.
Potentially problematic release.
This version of api-foundry might be problematic. Click here for more details.
- {api_foundry-0.1.4 → api_foundry-0.1.5}/PKG-INFO +1 -1
- api_foundry-0.1.5/api_foundry/cloudprints/archive_builder.py +6 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/cloudprints/pulumi/log_group.pv +0 -1
- api_foundry-0.1.5/api_foundry/cloudprints/pulumi/rest_api.py +16 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/cloudprints/python_archive_builder.py +18 -9
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/connectors/connection.py +0 -6
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_query_handler.py +5 -1
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/iac/gateway_spec.py +49 -2
- api_foundry-0.1.4/api_foundry/iac/pulumi/api_maker.py → api_foundry-0.1.5/api_foundry/iac/pulumi/api_foundry.py +5 -7
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/scripts/postgres_to_openapi.py +4 -4
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/utils/logger.py +5 -3
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/utils/model_factory.py +22 -35
- {api_foundry-0.1.4 → api_foundry-0.1.5}/pyproject.toml +1 -1
- api_foundry-0.1.4/api_foundry/cloudprints/archive_builder.py +0 -8
- api_foundry-0.1.4/api_foundry/cloudprints/aws_cdk/iam_execution_role.py +0 -267
- api_foundry-0.1.4/api_foundry/cloudprints/pulumi/rest_api.py +0 -17
- {api_foundry-0.1.4 → api_foundry-0.1.5}/.gitignore +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/LICENSE +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/__init__.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/adapters/adapter.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/adapters/case_change_adapter.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/adapters/gateway_adapter.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/cloudprints/hash_comparator.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/cloudprints/pulumi/lambda_.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/connectors/connection_factory.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/connectors/oracle_connector.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/connectors/postgres_connection.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/dao.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/operation_dao.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_custom_query_handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_delete_query_handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_insert_query_handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_select_query_handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_subselect_query_handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/dao/sql_update_query_handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/iac/handler.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/operation.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/services/service.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/services/transactional_service.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/utils/app_exception.py +0 -0
- {api_foundry-0.1.4 → api_foundry-0.1.5}/api_foundry/utils/spec_handler.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: api-foundry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
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
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import pulumi
|
|
2
|
+
import pulumi_aws as aws
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class GatewayAPICloudprint(pulumi.ComponentResource):
|
|
6
|
+
rest_api: aws.apigateway.RestApi
|
|
7
|
+
|
|
8
|
+
def __init__(self, name, body: str, opts=None):
|
|
9
|
+
super().__init__("cloudprints:apigw:OpenAPIGateway", name, None, opts)
|
|
10
|
+
|
|
11
|
+
self.rest_api = aws.apigateway.RestApi(
|
|
12
|
+
f"{name}-http-api", name=f"{name}-http-api", body=body
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def id(self) -> pulumi.Output[str]:
|
|
16
|
+
return self.rest_api.id
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import json
|
|
2
1
|
import os
|
|
3
2
|
import shutil
|
|
4
3
|
import subprocess
|
|
@@ -42,7 +41,7 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
42
41
|
self.build_archive()
|
|
43
42
|
self._hash = new_hash
|
|
44
43
|
hash_comparator.write(self._hash, self._base_dir)
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
def hash(self) -> str:
|
|
47
46
|
return self._hash
|
|
48
47
|
|
|
@@ -71,7 +70,7 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
71
70
|
file_path = os.path.join(folder_name, filename)
|
|
72
71
|
archive_path = os.path.relpath(file_path, self._staging)
|
|
73
72
|
zipf.write(file_path, archive_path)
|
|
74
|
-
|
|
73
|
+
|
|
75
74
|
# Add installed libraries
|
|
76
75
|
for folder_name, _, filenames in os.walk(self._libs):
|
|
77
76
|
for filename in filenames:
|
|
@@ -90,7 +89,7 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
90
89
|
return
|
|
91
90
|
for destination, source in self._sources.items():
|
|
92
91
|
destination_path = os.path.join(self._staging, destination)
|
|
93
|
-
|
|
92
|
+
|
|
94
93
|
try:
|
|
95
94
|
if os.path.isdir(source):
|
|
96
95
|
shutil.copytree(source, destination_path)
|
|
@@ -99,12 +98,15 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
99
98
|
os.makedirs(os.path.dirname(destination_path), exist_ok=True)
|
|
100
99
|
shutil.copy2(source, destination_path)
|
|
101
100
|
log.info(f"File copied from {source} to {destination_path}")
|
|
102
|
-
else: #inline
|
|
101
|
+
else: # inline
|
|
103
102
|
try:
|
|
104
103
|
with open(destination_path, "w") as f:
|
|
105
104
|
f.write(source + "\n")
|
|
106
105
|
except Exception as e:
|
|
107
|
-
log.error(
|
|
106
|
+
log.error(
|
|
107
|
+
"Error writing requirements to "
|
|
108
|
+
+ f"{destination_path}: {e}"
|
|
109
|
+
)
|
|
108
110
|
raise
|
|
109
111
|
except Exception as e:
|
|
110
112
|
log.error(f"Error copying {source} to {destination_path}: {e}")
|
|
@@ -130,7 +132,12 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
130
132
|
log.warning(f"No requirements file found at {requirements_file}")
|
|
131
133
|
return
|
|
132
134
|
|
|
133
|
-
log.info(
|
|
135
|
+
log.info(
|
|
136
|
+
f"Installing packages using: {sys.executable} -m pip3 "
|
|
137
|
+
+ f"install --target {self._libs} --platform manylinux2010_x86_64 "
|
|
138
|
+
+ "--implementation cp --only-binary=:all: --upgrade "
|
|
139
|
+
+ f"--python-version 3.9 -r {requirements_file}"
|
|
140
|
+
)
|
|
134
141
|
self.clean_folder(self._libs)
|
|
135
142
|
|
|
136
143
|
try:
|
|
@@ -161,7 +168,8 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
161
168
|
|
|
162
169
|
def create_clean_folder(self, folder_path):
|
|
163
170
|
"""
|
|
164
|
-
Create a clean folder by removing existing contents or creating
|
|
171
|
+
Create a clean folder by removing existing contents or creating
|
|
172
|
+
the folder if it doesn't exist.
|
|
165
173
|
|
|
166
174
|
Args:
|
|
167
175
|
folder_path (str): Path to the folder to clean or create.
|
|
@@ -179,7 +187,8 @@ class PythonArchiveBuilder(ArchiveBuilder):
|
|
|
179
187
|
Remove all files and folders from the specified folder.
|
|
180
188
|
|
|
181
189
|
Args:
|
|
182
|
-
folder_path (str): Path to the folder from which to remove
|
|
190
|
+
folder_path (str): Path to the folder from which to remove
|
|
191
|
+
files and folders.
|
|
183
192
|
|
|
184
193
|
Returns:
|
|
185
194
|
None
|
|
@@ -370,5 +370,9 @@ class SQLSchemaQueryHandler(SQLQueryHandler):
|
|
|
370
370
|
return "UUID()"
|
|
371
371
|
return "gen_random_uuid()"
|
|
372
372
|
raise ApplicationException(
|
|
373
|
-
500,
|
|
373
|
+
500,
|
|
374
|
+
(
|
|
375
|
+
"Concurrency control property is unrecognized type"
|
|
376
|
+
+ f"name: {property.name}, type: {property.api_type}"
|
|
377
|
+
),
|
|
374
378
|
)
|
|
@@ -28,7 +28,11 @@ class GatewaySpec:
|
|
|
28
28
|
log.info(f"invoke_arn: {function_invoke_arn}")
|
|
29
29
|
document = ModelFactory.spec
|
|
30
30
|
|
|
31
|
-
self.api_spec = dict(
|
|
31
|
+
self.api_spec = dict(
|
|
32
|
+
self.remove_custom_attributes(
|
|
33
|
+
self.convert_component_schema_names(copy.deepcopy(document))
|
|
34
|
+
)
|
|
35
|
+
)
|
|
32
36
|
if enable_cors:
|
|
33
37
|
self.enable_cors()
|
|
34
38
|
|
|
@@ -44,7 +48,7 @@ class GatewaySpec:
|
|
|
44
48
|
return yaml.dump(self.api_spec, default_flow_style=False)
|
|
45
49
|
|
|
46
50
|
def remove_custom_attributes(self, obj):
|
|
47
|
-
return self.remove_attributes(obj, "^x-
|
|
51
|
+
return self.remove_attributes(obj, "^x-af-.*$")
|
|
48
52
|
|
|
49
53
|
def remove_attributes(self, obj, pattern) -> Union[dict, list]:
|
|
50
54
|
"""
|
|
@@ -68,6 +72,49 @@ class GatewaySpec:
|
|
|
68
72
|
else:
|
|
69
73
|
return obj
|
|
70
74
|
|
|
75
|
+
def convert_component_schema_names(self, openapi_doc) -> dict:
|
|
76
|
+
"""
|
|
77
|
+
Converts all component schema object names to lowercase in an OpenAPI document and updates any $ref references.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
openapi_doc (dict): The OpenAPI document as a dictionary.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
dict: The modified OpenAPI document with lowercase component schema names.
|
|
84
|
+
"""
|
|
85
|
+
# Step 1: Convert all schema names in the components section to lowercase
|
|
86
|
+
components = openapi_doc.get("components", {})
|
|
87
|
+
schemas = components.get("schemas", {})
|
|
88
|
+
|
|
89
|
+
new_schemas = {}
|
|
90
|
+
name_mapping = {} # To map old names to new lowercase names
|
|
91
|
+
|
|
92
|
+
for schema_name, schema_content in schemas.items():
|
|
93
|
+
lowercase_name = schema_name.lower()
|
|
94
|
+
new_schemas[lowercase_name] = schema_content
|
|
95
|
+
name_mapping[
|
|
96
|
+
f"#/components/schemas/{schema_name}"
|
|
97
|
+
] = f"#/components/schemas/{lowercase_name}"
|
|
98
|
+
|
|
99
|
+
components["schemas"] = new_schemas
|
|
100
|
+
openapi_doc["components"] = components
|
|
101
|
+
|
|
102
|
+
# Step 2: Fix $ref references throughout the document
|
|
103
|
+
def fix_refs(obj):
|
|
104
|
+
if isinstance(obj, dict):
|
|
105
|
+
for key, value in obj.items():
|
|
106
|
+
if key == "$ref" and value in name_mapping:
|
|
107
|
+
obj[key] = name_mapping[value]
|
|
108
|
+
else:
|
|
109
|
+
fix_refs(value)
|
|
110
|
+
elif isinstance(obj, list):
|
|
111
|
+
for item in obj:
|
|
112
|
+
fix_refs(item)
|
|
113
|
+
|
|
114
|
+
fix_refs(openapi_doc)
|
|
115
|
+
|
|
116
|
+
return openapi_doc
|
|
117
|
+
|
|
71
118
|
def add_custom_authentication(self, authentication_invoke_arn: str):
|
|
72
119
|
components = self.api_spec.get("components", None)
|
|
73
120
|
if components:
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import json
|
|
2
1
|
import pkgutil
|
|
3
|
-
from typing import Any, Awaitable, Mapping
|
|
4
|
-
from zipfile import ZipFile
|
|
2
|
+
from typing import Any, Awaitable, Mapping
|
|
5
3
|
|
|
6
4
|
import pulumi
|
|
7
|
-
from pulumi.output import Inputs
|
|
8
5
|
import pulumi_aws as aws
|
|
9
6
|
|
|
10
7
|
from api_foundry.utils.logger import logger, DEBUG, write_logging_file
|
|
@@ -12,12 +9,11 @@ from api_foundry.utils.model_factory import ModelFactory
|
|
|
12
9
|
from api_foundry.iac.gateway_spec import GatewaySpec
|
|
13
10
|
from api_foundry.cloudprints.python_archive_builder import PythonArchiveBuilder
|
|
14
11
|
from api_foundry.cloudprints.pulumi.lambda_ import PythonFunctionCloudprint
|
|
15
|
-
from api_foundry.cloudprints.pulumi.rest_api import GatewayAPICloudprint
|
|
16
12
|
|
|
17
13
|
log = logger(__name__)
|
|
18
14
|
|
|
19
15
|
|
|
20
|
-
class
|
|
16
|
+
class APIFoundry(pulumi.ComponentResource):
|
|
21
17
|
def __init__(
|
|
22
18
|
self,
|
|
23
19
|
name: str,
|
|
@@ -32,7 +28,9 @@ class APIMaker(pulumi.ComponentResource):
|
|
|
32
28
|
|
|
33
29
|
assert "secrets" in props, "Missing secrets map"
|
|
34
30
|
|
|
35
|
-
api_foundry_source =
|
|
31
|
+
api_foundry_source = (
|
|
32
|
+
"/Users/clydedanielrepik/workspace/api_foundry/src/api_foundry"
|
|
33
|
+
)
|
|
36
34
|
|
|
37
35
|
self.archive_builder = PythonArchiveBuilder(
|
|
38
36
|
name=f"{name}-archive-builder",
|
|
@@ -116,7 +116,7 @@ class PostgresSchemaToOpenAPI:
|
|
|
116
116
|
column_info = self.map_data_type(column["data_type"])
|
|
117
117
|
|
|
118
118
|
if column_name in primary_keys:
|
|
119
|
-
column_info["x-
|
|
119
|
+
column_info["x-af-primary-key"] = primary_keys[column_name]
|
|
120
120
|
if primary_keys[column_name] == "auto":
|
|
121
121
|
column_info[
|
|
122
122
|
"description"
|
|
@@ -139,7 +139,7 @@ class PostgresSchemaToOpenAPI:
|
|
|
139
139
|
foreign_table = column["foreign_table"]
|
|
140
140
|
properties[foreign_table] = {
|
|
141
141
|
"$ref": f"#/components/schemas/{foreign_table}",
|
|
142
|
-
"x-
|
|
142
|
+
"x-af-parent-property": column_name,
|
|
143
143
|
"description": f"{foreign_table.capitalize()} associated with the {table}.",
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -152,7 +152,7 @@ class PostgresSchemaToOpenAPI:
|
|
|
152
152
|
"type": "object",
|
|
153
153
|
"properties": properties,
|
|
154
154
|
"required": required,
|
|
155
|
-
"x-
|
|
155
|
+
"x-af-database": self.database,
|
|
156
156
|
}
|
|
157
157
|
openapi_schema["components"]["schemas"][table] = schema_object
|
|
158
158
|
|
|
@@ -166,7 +166,7 @@ class PostgresSchemaToOpenAPI:
|
|
|
166
166
|
"type": "array",
|
|
167
167
|
"items": {
|
|
168
168
|
"$ref": f"#/components/schemas/{child_table}",
|
|
169
|
-
"x-
|
|
169
|
+
"x-af-child-property": foreign_key,
|
|
170
170
|
},
|
|
171
171
|
"description": f"List of {child_table} items associated with this {parent_table}.",
|
|
172
172
|
}
|
|
@@ -14,6 +14,7 @@ WARN = logging.WARN
|
|
|
14
14
|
INFO = logging.INFO
|
|
15
15
|
DEBUG = logging.DEBUG
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
def logger(name=None):
|
|
18
19
|
"""
|
|
19
20
|
Function to create a logger with a specified name or default name.
|
|
@@ -35,6 +36,7 @@ def logger(name=None):
|
|
|
35
36
|
# Returning a logger object with the specified name or the root logger
|
|
36
37
|
return logging.getLogger(name)
|
|
37
38
|
|
|
39
|
+
|
|
38
40
|
def write_logging_file(file_name, content):
|
|
39
41
|
"""
|
|
40
42
|
Function to write a given string to a file in the temp/logging folder.
|
|
@@ -46,13 +48,13 @@ def write_logging_file(file_name, content):
|
|
|
46
48
|
"""
|
|
47
49
|
# Define the directory path
|
|
48
50
|
dir_path = os.path.join("temp", "logging")
|
|
49
|
-
|
|
51
|
+
|
|
50
52
|
# Ensure the directory exists
|
|
51
53
|
os.makedirs(dir_path, exist_ok=True)
|
|
52
|
-
|
|
54
|
+
|
|
53
55
|
# Define the file path
|
|
54
56
|
file_path = os.path.join(dir_path, file_name)
|
|
55
|
-
|
|
57
|
+
|
|
56
58
|
# Write the content to the file
|
|
57
59
|
with open(file_path, "w") as file:
|
|
58
60
|
file.write(content + "\n")
|
|
@@ -4,7 +4,7 @@ from typing import Any, Dict, Optional, List, Union
|
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
from api_foundry.utils.app_exception import ApplicationException
|
|
6
6
|
from api_foundry.utils.spec_handler import SpecificationHandler
|
|
7
|
-
from api_foundry.utils.logger import logger
|
|
7
|
+
from api_foundry.utils.logger import logger, DEBUG
|
|
8
8
|
|
|
9
9
|
log = logger(__name__)
|
|
10
10
|
|
|
@@ -44,16 +44,16 @@ class SchemaObjectProperty(OpenAPIElement):
|
|
|
44
44
|
super().__init__(properties, spec)
|
|
45
45
|
self.operation_id = operation_id
|
|
46
46
|
self.name = name
|
|
47
|
-
self.column_name = self.get("x-
|
|
47
|
+
self.column_name = self.get("x-af-column-name") or name
|
|
48
48
|
self.type = self.get("type") or "string"
|
|
49
49
|
self.api_type = self.get("format") or self.type
|
|
50
|
-
self.column_type = self.get("x-
|
|
51
|
-
self.is_primary_key = self.get("x-
|
|
50
|
+
self.column_type = self.get("x-af-column-type") or self.api_type
|
|
51
|
+
self.is_primary_key = self.get("x-af-primary-key") or False
|
|
52
52
|
self.min_length = self.get("minLength")
|
|
53
53
|
self.max_length = self.get("maxLength")
|
|
54
54
|
self.pattern = self.get("pattern")
|
|
55
55
|
|
|
56
|
-
self.concurrency_control = self.get("x-
|
|
56
|
+
self.concurrency_control = self.get("x-af-concurrency-control")
|
|
57
57
|
if self.concurrency_control:
|
|
58
58
|
self.concurrency_control = self.concurrency_control.lower()
|
|
59
59
|
assert self.concurrency_control in [
|
|
@@ -111,7 +111,7 @@ class SchemaObjectKey(SchemaObjectProperty):
|
|
|
111
111
|
spec: Dict[str, Any],
|
|
112
112
|
):
|
|
113
113
|
super().__init__(operation_id, name, properties, spec)
|
|
114
|
-
self.key_type = self.get("x-
|
|
114
|
+
self.key_type = self.get("x-af-primary-key", default="auto")
|
|
115
115
|
if self.key_type not in ["required", "auto", "sequence"]:
|
|
116
116
|
raise ApplicationException(
|
|
117
117
|
500,
|
|
@@ -121,7 +121,7 @@ class SchemaObjectKey(SchemaObjectProperty):
|
|
|
121
121
|
)
|
|
122
122
|
|
|
123
123
|
self.sequence_name = (
|
|
124
|
-
self.get("x-
|
|
124
|
+
self.get("x-af-sequence-name") if self.key_type == "sequence" else None
|
|
125
125
|
)
|
|
126
126
|
if self.key_type == "sequence" and not self.sequence_name:
|
|
127
127
|
raise ApplicationException(
|
|
@@ -145,7 +145,7 @@ class SchemaObjectAssociation(OpenAPIElement):
|
|
|
145
145
|
|
|
146
146
|
@property
|
|
147
147
|
def child_property(self) -> "SchemaObjectProperty":
|
|
148
|
-
child_property = self.get("x-
|
|
148
|
+
child_property = self.get("x-af-child-property", None)
|
|
149
149
|
if not child_property:
|
|
150
150
|
return self.child_schema_object.primary_key
|
|
151
151
|
return self.child_schema_object.get_property(child_property)
|
|
@@ -162,7 +162,7 @@ class SchemaObjectAssociation(OpenAPIElement):
|
|
|
162
162
|
f"attribute: {self.name}"
|
|
163
163
|
),
|
|
164
164
|
)
|
|
165
|
-
parent = self.get("x-
|
|
165
|
+
parent = self.get("x-af-parent-property")
|
|
166
166
|
if parent:
|
|
167
167
|
return parent_schema_object.get_property(parent)
|
|
168
168
|
return parent_schema_object.primary_key
|
|
@@ -192,7 +192,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
192
192
|
super().__init__(schema_object, spec)
|
|
193
193
|
self.operation_id = operation_id
|
|
194
194
|
self.schema_object = schema_object
|
|
195
|
-
database = schema_object.get("x-
|
|
195
|
+
database = schema_object.get("x-af-database")
|
|
196
196
|
if database:
|
|
197
197
|
self.database = database.lower()
|
|
198
198
|
self.primary_key = None
|
|
@@ -256,7 +256,7 @@ class SchemaObject(OpenAPIElement):
|
|
|
256
256
|
def concurrency_property(self) -> Optional[SchemaObjectProperty]:
|
|
257
257
|
if not hasattr(self, "_concurrency_property"):
|
|
258
258
|
concurrency_prop_name = self.schema_object.get(
|
|
259
|
-
"x-
|
|
259
|
+
"x-af-concurrency-control", None
|
|
260
260
|
)
|
|
261
261
|
if concurrency_prop_name:
|
|
262
262
|
try:
|
|
@@ -274,10 +274,10 @@ class SchemaObject(OpenAPIElement):
|
|
|
274
274
|
|
|
275
275
|
@property
|
|
276
276
|
def table_name(self) -> str:
|
|
277
|
-
schema = self.schema_object.get("x-
|
|
277
|
+
schema = self.schema_object.get("x-af-schema")
|
|
278
278
|
return (
|
|
279
279
|
f"{schema}." if schema else ""
|
|
280
|
-
) + f"{self.schema_object.get('x-
|
|
280
|
+
) + f"{self.schema_object.get('x-af-table', self.operation_id)}"
|
|
281
281
|
|
|
282
282
|
def get_property(self, property_name: str) -> Optional[SchemaObjectProperty]:
|
|
283
283
|
return self.properties.get(property_name)
|
|
@@ -307,11 +307,11 @@ class PathOperation(OpenAPIElement):
|
|
|
307
307
|
|
|
308
308
|
@property
|
|
309
309
|
def database(self) -> str:
|
|
310
|
-
return self.path_operation["x-
|
|
310
|
+
return self.path_operation["x-af-database"]
|
|
311
311
|
|
|
312
312
|
@property
|
|
313
313
|
def sql(self) -> str:
|
|
314
|
-
return self.path_operation["x-
|
|
314
|
+
return self.path_operation["x-af-sql"]
|
|
315
315
|
|
|
316
316
|
@property
|
|
317
317
|
def inputs(self) -> Dict[str, SchemaObjectProperty]:
|
|
@@ -351,7 +351,8 @@ class PathOperation(OpenAPIElement):
|
|
|
351
351
|
pattern = re.compile(r"2\d{2}|2xx")
|
|
352
352
|
for status_code, response in responses.items():
|
|
353
353
|
if pattern.fullmatch(status_code):
|
|
354
|
-
log.
|
|
354
|
+
if log.isEnabledFor(DEBUG):
|
|
355
|
+
log.debug(f"response: {response}")
|
|
355
356
|
content = (
|
|
356
357
|
self.get(
|
|
357
358
|
[
|
|
@@ -365,7 +366,8 @@ class PathOperation(OpenAPIElement):
|
|
|
365
366
|
)
|
|
366
367
|
or {}
|
|
367
368
|
)
|
|
368
|
-
log.
|
|
369
|
+
if log.isEnabledFor(DEBUG):
|
|
370
|
+
log.debug(f"content: {content}")
|
|
369
371
|
for name, property in content.items():
|
|
370
372
|
properties[name] = SchemaObjectProperty(
|
|
371
373
|
self.path, name, property, self.spec
|
|
@@ -408,35 +410,20 @@ class ModelFactory:
|
|
|
408
410
|
|
|
409
411
|
schemas = cls.spec.get("components", {}).get("schemas", {})
|
|
410
412
|
for name, schema in schemas.items():
|
|
411
|
-
if "x-
|
|
412
|
-
cls.schema_objects[name
|
|
413
|
+
if "x-af-database" in schema:
|
|
414
|
+
cls.schema_objects[name] = SchemaObject(name, schema, cls.spec)
|
|
413
415
|
|
|
414
|
-
cls.initialize_schema_objects()
|
|
415
|
-
cls.initialize_path_operations()
|
|
416
|
-
|
|
417
|
-
@classmethod
|
|
418
|
-
def initialize_schema_objects(cls):
|
|
419
|
-
for name, schema in cls.schema_objects.items():
|
|
420
|
-
cls.schema_objects[name] = SchemaObject(name, schema, cls.spec)
|
|
421
|
-
|
|
422
|
-
@classmethod
|
|
423
|
-
def initialize_path_operations(cls):
|
|
424
416
|
paths = cls.spec.get("paths", {})
|
|
425
417
|
cls.path_operations = {}
|
|
426
418
|
for path, operations in paths.items():
|
|
427
419
|
for method, operation in operations.items():
|
|
428
|
-
if "x-
|
|
420
|
+
if "x-af-database" in operation:
|
|
429
421
|
cls.path_operations[
|
|
430
422
|
f"{path.lstrip('/')}:{methods_to_actions[method.lower()]}"
|
|
431
423
|
] = PathOperation(path, method, operation, cls.spec)
|
|
432
424
|
|
|
433
425
|
@classmethod
|
|
434
426
|
def get_schema_object(cls, name: str) -> SchemaObject:
|
|
435
|
-
if name not in cls.schema_objects:
|
|
436
|
-
cls.schema_objects[name] = SchemaObject(
|
|
437
|
-
name, cls.schema_objects[name], cls.spec
|
|
438
|
-
)
|
|
439
|
-
|
|
440
427
|
return cls.schema_objects[name]
|
|
441
428
|
|
|
442
429
|
@classmethod
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
|
-
from constructs import Construct
|
|
4
|
-
|
|
5
|
-
from imports.aws.iam_role import IamRole
|
|
6
|
-
from imports.aws.iam_role_policy import IamRolePolicy
|
|
7
|
-
from imports.aws.iam_role_policy_attachment import IamRolePolicyAttachment
|
|
8
|
-
|
|
9
|
-
from ..lib.logger import logger, INFO
|
|
10
|
-
from ..lib.common import make_name, make_tags, make_id, make_resource
|
|
11
|
-
|
|
12
|
-
log = logger(__name__)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class LambdaExecutionRole(Construct):
|
|
16
|
-
role: IamRole
|
|
17
|
-
|
|
18
|
-
def __init__(self, scope: Construct, id: str):
|
|
19
|
-
"""
|
|
20
|
-
Create an AWS IAM Role for Lambda execution and attach policies to it.
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
scope (Construct): The scope of the construct.
|
|
24
|
-
id (str): The unique identifier for this construct.
|
|
25
|
-
"""
|
|
26
|
-
super().__init__(scope, make_id(scope, id))
|
|
27
|
-
|
|
28
|
-
# Create the execution role for Lambda
|
|
29
|
-
self.role = self.create_execution_role(scope, id)
|
|
30
|
-
self.attach_policy = self.attach_policy(scope, id)
|
|
31
|
-
|
|
32
|
-
# Attach IAM policies to the role
|
|
33
|
-
self.attach_policy_to_role(
|
|
34
|
-
scope,
|
|
35
|
-
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
|
|
36
|
-
"lambdaBasicExecPolicyAtch",
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
self.attach_policy_to_role(
|
|
40
|
-
scope,
|
|
41
|
-
"arn:aws:iam::aws:policy/AWSLambdaExecute",
|
|
42
|
-
"lambdaExecPolicyAtch",
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
def create_execution_role(self, scope: Construct, id: str) -> IamRole:
|
|
46
|
-
"""
|
|
47
|
-
Create an IAM role with an assume role policy for Lambda service.
|
|
48
|
-
|
|
49
|
-
Args:
|
|
50
|
-
scope (Construct): The scope of the construct.
|
|
51
|
-
id (str): The unique identifier for this role.
|
|
52
|
-
|
|
53
|
-
Returns:
|
|
54
|
-
IamRole: The IAM role created for Lambda execution.
|
|
55
|
-
"""
|
|
56
|
-
if log.isEnabledFor(INFO):
|
|
57
|
-
log.info(f"Creating execution_role role_name: {id}")
|
|
58
|
-
|
|
59
|
-
# Define the policy that allows Lambda service to assume this role
|
|
60
|
-
assume_role_policy = {
|
|
61
|
-
"Version": "2012-10-17",
|
|
62
|
-
"Statement": [
|
|
63
|
-
{
|
|
64
|
-
"Action": ["sts:AssumeRole"],
|
|
65
|
-
"Principal": {
|
|
66
|
-
"Service": [
|
|
67
|
-
"lambda.amazonaws.com",
|
|
68
|
-
"edgelambda.amazonaws.com",
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
"Effect": "Allow",
|
|
72
|
-
}
|
|
73
|
-
],
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
# Create the IAM role with the defined policy
|
|
77
|
-
return IamRole(
|
|
78
|
-
scope,
|
|
79
|
-
make_id(scope, f"{id}-role"),
|
|
80
|
-
name=make_resource(scope, id),
|
|
81
|
-
assume_role_policy=json.dumps(assume_role_policy),
|
|
82
|
-
tags=make_tags(scope, id),
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
def attach_policy_to_role(
|
|
86
|
-
self, scope: Construct, policy_arn: str, policy_name: str
|
|
87
|
-
):
|
|
88
|
-
"""
|
|
89
|
-
Attach an IAM policy to the IAM role.
|
|
90
|
-
|
|
91
|
-
Args:
|
|
92
|
-
scope (Construct): The scope of the construct.
|
|
93
|
-
policy_arn (str): The ARN of the IAM policy to attach.
|
|
94
|
-
policy_name (str): The name of the policy attachment.
|
|
95
|
-
"""
|
|
96
|
-
if log.isEnabledFor(INFO):
|
|
97
|
-
log.info(f"Creating policy attachment: policy_arg: {policy_arn}")
|
|
98
|
-
|
|
99
|
-
IamRolePolicyAttachment(
|
|
100
|
-
scope,
|
|
101
|
-
make_id(scope, policy_name),
|
|
102
|
-
role=self.role.name,
|
|
103
|
-
policy_arn=policy_arn,
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
def attach_policy(self, scope: Construct, id: str) -> IamRolePolicy:
|
|
107
|
-
return IamRolePolicy(
|
|
108
|
-
scope,
|
|
109
|
-
make_id(scope, f"{id}-role-policy"),
|
|
110
|
-
role=self.role.id,
|
|
111
|
-
name=make_resource(scope, f"{id}-role-policy"),
|
|
112
|
-
policy=json.dumps(
|
|
113
|
-
{
|
|
114
|
-
"Version": "2012-10-17",
|
|
115
|
-
"Statement": [
|
|
116
|
-
{
|
|
117
|
-
"Sid": "AllowLambdaFunctionInvocation",
|
|
118
|
-
"Effect": "Allow",
|
|
119
|
-
"Action": ["lambda:InvokeFunction"],
|
|
120
|
-
"Resource": ["*"],
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
# lambda@edge
|
|
124
|
-
"Sid": "AllowEdgeFunction",
|
|
125
|
-
"Effect": "Allow",
|
|
126
|
-
"Action": [
|
|
127
|
-
"lambda:EnableReplication*",
|
|
128
|
-
"lambda:GetFunction",
|
|
129
|
-
"iam:CreateServiceLinkedRole",
|
|
130
|
-
],
|
|
131
|
-
"Resource": ["*"],
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
"Sid": "AllowWsManagementInvocation",
|
|
135
|
-
"Effect": "Allow",
|
|
136
|
-
"Action": [
|
|
137
|
-
"execute-api:Invoke",
|
|
138
|
-
"execute-api:ManageConnections",
|
|
139
|
-
],
|
|
140
|
-
"Resource": ["arn:aws:execute-api:*:*:*/*"],
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
"Sid": "Logs",
|
|
144
|
-
"Effect": "Allow",
|
|
145
|
-
"Action": [
|
|
146
|
-
"logs:CreateLogGroup",
|
|
147
|
-
"logs:CreateLogStream",
|
|
148
|
-
"logs:DescribeLogGroups",
|
|
149
|
-
"logs:DescribeLogStreams",
|
|
150
|
-
"logs:PutLogEvents",
|
|
151
|
-
"logs:GetLogEvents",
|
|
152
|
-
"logs:FilterLogEvents",
|
|
153
|
-
],
|
|
154
|
-
"Resource": "arn:aws:logs:*:*:*",
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
"Sid": "StateMachines",
|
|
158
|
-
"Effect": "Allow",
|
|
159
|
-
"Action": [
|
|
160
|
-
"states:DescribeStateMachine",
|
|
161
|
-
"states:StartExecution",
|
|
162
|
-
"states:SendTaskSuccess",
|
|
163
|
-
"states:SendTaskFailure",
|
|
164
|
-
"states:ListExecution",
|
|
165
|
-
"states:DescribeExecution",
|
|
166
|
-
"states:DescribeStateMachineForExecution",
|
|
167
|
-
"states:GetExecutionHistory",
|
|
168
|
-
"states:SendTaskHeartbeat",
|
|
169
|
-
"states:GetActivityTask",
|
|
170
|
-
],
|
|
171
|
-
"Resource": "arn:aws:states:*:*:*:*",
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
"Sid": "AllowAccessObjectsToS3",
|
|
175
|
-
"Effect": "Allow",
|
|
176
|
-
"Action": [
|
|
177
|
-
"s3:GetObject",
|
|
178
|
-
"s3:PutObject",
|
|
179
|
-
"s3:DeleteObject",
|
|
180
|
-
],
|
|
181
|
-
"Resource": "*",
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
"Sid": "AllowSqsAccess",
|
|
185
|
-
"Effect": "Allow",
|
|
186
|
-
"Action": [
|
|
187
|
-
"sqs:DeleteMessage",
|
|
188
|
-
"sqs:GetQueueAttributes",
|
|
189
|
-
"sqs:GetQueueUrl",
|
|
190
|
-
"sqs:ReceiveMessage",
|
|
191
|
-
],
|
|
192
|
-
"Resource": "*",
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"Sid": "AllowAssumeRole",
|
|
196
|
-
"Effect": "Allow",
|
|
197
|
-
"Action": "sts:AssumeRole",
|
|
198
|
-
"Resource": "*",
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
"Sid": "DDB",
|
|
202
|
-
"Effect": "Allow",
|
|
203
|
-
"Action": [
|
|
204
|
-
"dynamodb:BatchGet*",
|
|
205
|
-
"dynamodb:BatchGetItem",
|
|
206
|
-
"dynamodb:BatchWriteItem",
|
|
207
|
-
"dynamodb:ConditionCheckItem",
|
|
208
|
-
"dynamodb:DescribeTable",
|
|
209
|
-
"dynamodb:GetRecords",
|
|
210
|
-
"dynamodb:DeleteItem",
|
|
211
|
-
"dynamodb:DescribeTable",
|
|
212
|
-
"dynamodb:DescribeStream",
|
|
213
|
-
"dynamodb:DescribeGlobalTable",
|
|
214
|
-
"dynamodb:GetShardIterator",
|
|
215
|
-
"dynamodb:ListStreams",
|
|
216
|
-
"dynamodb:Query",
|
|
217
|
-
"dynamodb:PutItem",
|
|
218
|
-
"dynamodb:GetItem",
|
|
219
|
-
"dynamodb:UpdateItem",
|
|
220
|
-
"dynamodb:Scan",
|
|
221
|
-
],
|
|
222
|
-
"Resource": "*",
|
|
223
|
-
},
|
|
224
|
-
{
|
|
225
|
-
"Sid": "AllowVPCAccess",
|
|
226
|
-
"Effect": "Allow",
|
|
227
|
-
"Action": [
|
|
228
|
-
"ec2:CreateNetworkInterface",
|
|
229
|
-
"ec2:DescribeNetworkInterfaces",
|
|
230
|
-
"ec2:DeleteNetworkInterface",
|
|
231
|
-
"ec2:AssignPrivateIpAddresses",
|
|
232
|
-
"ec2:UnassignPrivateIpAddresses",
|
|
233
|
-
],
|
|
234
|
-
"Resource": "*",
|
|
235
|
-
},
|
|
236
|
-
{
|
|
237
|
-
"Sid": "TextractAccess",
|
|
238
|
-
"Effect": "Allow",
|
|
239
|
-
"Action": "textract:*",
|
|
240
|
-
"Resource": "*",
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
"Sid": "secretsmanager",
|
|
244
|
-
"Effect": "Allow",
|
|
245
|
-
"Action": "secretsmanager:GetSecretValue",
|
|
246
|
-
"Resource": ["*"],
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
"Sid": "sns",
|
|
250
|
-
"Effect": "Allow",
|
|
251
|
-
"Action": "sns:*",
|
|
252
|
-
"Resource": ["*"],
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
"Sid": "ssm",
|
|
256
|
-
"Effect": "Allow",
|
|
257
|
-
"Action": [
|
|
258
|
-
"ssm:GetParametersByPath",
|
|
259
|
-
"ssm:GetParameter",
|
|
260
|
-
"kms:Decrypt",
|
|
261
|
-
],
|
|
262
|
-
"Resource": ["*"],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
}
|
|
266
|
-
),
|
|
267
|
-
)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import pulumi
|
|
3
|
-
import pulumi_aws as aws
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class GatewayAPICloudprint(pulumi.ComponentResource):
|
|
7
|
-
rest_api: aws.apigateway.RestApi
|
|
8
|
-
|
|
9
|
-
def __init__(self, name, body:str, opts = None):
|
|
10
|
-
super().__init__('cloudprints:apigw:OpenAPIGateway', name, None, opts)
|
|
11
|
-
|
|
12
|
-
self.rest_api = aws.apigateway.RestApi(f"{name}-http-api",
|
|
13
|
-
name=f"{name}-http-api",
|
|
14
|
-
body=body)
|
|
15
|
-
|
|
16
|
-
def id(self) -> pulumi.Output[str]:
|
|
17
|
-
return self.rest_api.id
|
|
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
|