api-foundry 0.1.0__tar.gz → 0.1.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.

Potentially problematic release.


This version of api-foundry might be problematic. Click here for more details.

Files changed (64) hide show
  1. {api_foundry-0.1.0/src/api_foundry.egg-info → api_foundry-0.1.2}/PKG-INFO +13 -8
  2. {api_foundry-0.1.0 → api_foundry-0.1.2}/pyproject.toml +19 -14
  3. api_foundry-0.1.2/src/api_foundry/adapters/adapter.py +67 -0
  4. api_foundry-0.1.2/src/api_foundry/adapters/case_change_adapter.py +79 -0
  5. api_foundry-0.1.2/src/api_foundry/adapters/gateway_adapter.py +112 -0
  6. {api_foundry-0.1.0 → api_foundry-0.1.2/src/api_foundry/api_foundry.egg-info}/PKG-INFO +13 -8
  7. api_foundry-0.1.2/src/api_foundry/api_foundry.egg-info/SOURCES.txt +58 -0
  8. api_foundry-0.1.2/src/api_foundry/api_foundry.egg-info/entry_points.txt +2 -0
  9. api_foundry-0.1.2/src/api_foundry/api_foundry.egg-info/requires.txt +8 -0
  10. api_foundry-0.1.2/src/api_foundry/api_foundry.egg-info/top_level.txt +8 -0
  11. api_foundry-0.1.2/src/api_foundry/cloudprints/archive_builder.py +8 -0
  12. api_foundry-0.1.2/src/api_foundry/cloudprints/aws_cdk/iam_execution_role.py +267 -0
  13. api_foundry-0.1.2/src/api_foundry/cloudprints/hash_comparator.py +90 -0
  14. api_foundry-0.1.2/src/api_foundry/cloudprints/pulumi/lambda_.py +106 -0
  15. api_foundry-0.1.2/src/api_foundry/cloudprints/pulumi/rest_api.py +17 -0
  16. api_foundry-0.1.2/src/api_foundry/cloudprints/python_archive_builder.py +198 -0
  17. api_foundry-0.1.2/src/api_foundry/connectors/connection.py +38 -0
  18. api_foundry-0.1.2/src/api_foundry/connectors/connection_factory.py +110 -0
  19. api_foundry-0.1.2/src/api_foundry/connectors/oracle_connector.py +29 -0
  20. api_foundry-0.1.2/src/api_foundry/connectors/postgres_connection.py +105 -0
  21. api_foundry-0.1.2/src/api_foundry/dao/dao.py +18 -0
  22. api_foundry-0.1.2/src/api_foundry/dao/operation_dao.py +139 -0
  23. api_foundry-0.1.2/src/api_foundry/dao/sql_custom_query_handler.py +66 -0
  24. api_foundry-0.1.2/src/api_foundry/dao/sql_delete_query_handler.py +36 -0
  25. api_foundry-0.1.2/src/api_foundry/dao/sql_insert_query_handler.py +102 -0
  26. api_foundry-0.1.2/src/api_foundry/dao/sql_query_handler.py +374 -0
  27. api_foundry-0.1.2/src/api_foundry/dao/sql_select_query_handler.py +303 -0
  28. api_foundry-0.1.2/src/api_foundry/dao/sql_subselect_query_handler.py +61 -0
  29. api_foundry-0.1.2/src/api_foundry/dao/sql_update_query_handler.py +59 -0
  30. api_foundry-0.1.2/src/api_foundry/iac/gateway_spec.py +585 -0
  31. api_foundry-0.1.2/src/api_foundry/iac/handler.py +42 -0
  32. api_foundry-0.1.2/src/api_foundry/iac/pulumi/api_maker.py +90 -0
  33. api_foundry-0.1.2/src/api_foundry/scripts/postgres_to_openapi.py +216 -0
  34. api_foundry-0.1.2/src/api_foundry/services/service.py +60 -0
  35. api_foundry-0.1.2/src/api_foundry/services/transactional_service.py +35 -0
  36. api_foundry-0.1.2/src/api_foundry/utils/app_exception.py +22 -0
  37. api_foundry-0.1.2/src/api_foundry/utils/logger.py +58 -0
  38. api_foundry-0.1.2/src/api_foundry/utils/model_factory.py +461 -0
  39. api_foundry-0.1.2/src/api_foundry/utils/spec_handler.py +74 -0
  40. api_foundry-0.1.2/tests/test_adapter.py +42 -0
  41. api_foundry-0.1.2/tests/test_association_operations.py +199 -0
  42. api_foundry-0.1.2/tests/test_connection_factory.py +18 -0
  43. api_foundry-0.1.2/tests/test_custom_operations.py +77 -0
  44. api_foundry-0.1.2/tests/test_custom_sql.py +125 -0
  45. api_foundry-0.1.2/tests/test_fixtures.py +74 -0
  46. api_foundry-0.1.2/tests/test_gateway_adapter.py +79 -0
  47. api_foundry-0.1.2/tests/test_gateway_spec.py +101 -0
  48. api_foundry-0.1.2/tests/test_handler.py +60 -0
  49. api_foundry-0.1.2/tests/test_metadata_operations.py +175 -0
  50. api_foundry-0.1.2/tests/test_model_factory.py +102 -0
  51. api_foundry-0.1.2/tests/test_query_operations.py +203 -0
  52. api_foundry-0.1.2/tests/test_schema_objects_fixtures.py +106 -0
  53. api_foundry-0.1.2/tests/test_spec_handler.py +96 -0
  54. api_foundry-0.1.2/tests/test_sql_handler.py +531 -0
  55. api_foundry-0.1.2/tests/test_sql_insert_handler.py +546 -0
  56. api_foundry-0.1.2/tests/test_sql_update_handler.py +179 -0
  57. api_foundry-0.1.2/tests/test_transactional_service.py +324 -0
  58. api_foundry-0.1.0/src/__init__.py +0 -0
  59. api_foundry-0.1.0/src/api_foundry.egg-info/SOURCES.txt +0 -8
  60. api_foundry-0.1.0/src/api_foundry.egg-info/requires.txt +0 -6
  61. api_foundry-0.1.0/src/api_foundry.egg-info/top_level.txt +0 -1
  62. {api_foundry-0.1.0 → api_foundry-0.1.2}/LICENSE +0 -0
  63. {api_foundry-0.1.0 → api_foundry-0.1.2}/setup.cfg +0 -0
  64. {api_foundry-0.1.0/src → api_foundry-0.1.2/src/api_foundry}/api_foundry.egg-info/dependency_links.txt +0 -0
@@ -1,17 +1,22 @@
1
1
  Metadata-Version: 2.1
2
- Name: api_foundry
3
- Version: 0.1.0
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.
2
+ Name: api-foundry
3
+ Version: 0.1.2
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
  Author-email: Daniel Repik <danrepik@icloud.com>
6
6
  Project-URL: Documentation, https://github.com/DanRepik/api-foundry
7
7
  Project-URL: Source, https://github.com/DanRepik/api-foundry
8
8
  Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
9
12
  Classifier: Operating System :: OS Independent
10
13
  Requires-Python: >=3.9
11
14
  License-File: LICENSE
12
- Requires-Dist: pyhumps~=3.8.0
13
- Requires-Dist: cryptography~=37.0.4
14
- Requires-Dist: requests~=2.28.2
15
- Requires-Dist: simplejson~=3.19.1
16
- Requires-Dist: pyyaml==6.0.1
15
+ Requires-Dist: pyhumps
16
+ Requires-Dist: cryptography
17
+ Requires-Dist: requests
18
+ Requires-Dist: simplejson
19
+ Requires-Dist: pyyaml
17
20
  Requires-Dist: boto3
21
+ Requires-Dist: pulumi
22
+ Requires-Dist: pulumi-aws
@@ -5,24 +5,29 @@ build-backend = "setuptools.build_meta"
5
5
  # build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
- name = "api_foundry"
9
- version = "0.1.0"
8
+ name = "api-foundry"
9
+ version = "0.1.2"
10
10
  authors = [
11
11
  { name="Daniel Repik", email="danrepik@icloud.com" },
12
12
  ]
13
13
  dependencies = [
14
- 'pyhumps~=3.8.0',
15
- 'cryptography~=37.0.4',
16
- 'requests~=2.28.2',
17
- 'simplejson~=3.19.1',
18
- 'pyyaml==6.0.1',
19
- 'boto3'
14
+ 'pyhumps',
15
+ 'cryptography',
16
+ 'requests',
17
+ 'simplejson',
18
+ 'pyyaml',
19
+ 'boto3',
20
+ 'pulumi',
21
+ 'pulumi-aws'
20
22
  ]
21
23
 
22
- description = "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."
24
+ description = "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"
23
25
  requires-python = ">=3.9"
24
26
  classifiers = [
25
27
  "Programming Language :: Python :: 3.9",
28
+ "Programming Language :: Python :: 3.10",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
26
31
  "Operating System :: OS Independent",
27
32
  ]
28
33
 
@@ -31,14 +36,14 @@ Documentation = "https://github.com/DanRepik/api-foundry"
31
36
  Source = "https://github.com/DanRepik/api-foundry"
32
37
 
33
38
 
34
- #[project.scripts]
35
- #postgres_to_openapi = "api_maker.scripts.postgres_to_openapi:main"
39
+ [project.scripts]
40
+ postgres_to_openapi = "api_foundry.scripts.postgres_to_openapi:main"
36
41
 
37
- # [tool.setuptools.packages.find]
38
- # where = ["src/api_maker"]
42
+ [tool.setuptools.packages.find]
43
+ where = ["src/api_foundry"]
39
44
 
40
45
  [tool.pytest.ini_options]
41
46
  markers = [
42
- "unit: marks tests as slow (deselect with '-m \"not slow\"')",
47
+ "unit: marks tests as unit tests that do not require a database",
43
48
  "integration: marks tests that operate on real database"
44
49
  ]
@@ -0,0 +1,67 @@
1
+ import abc
2
+ from typing import Optional
3
+
4
+ from api_foundry.operation import Operation
5
+ from api_foundry.services.transactional_service import TransactionalService
6
+ from api_foundry.utils.logger import logger
7
+ from api_foundry.services.service import Service
8
+
9
+ log = logger(__name__)
10
+
11
+
12
+ class Adapter(metaclass=abc.ABCMeta):
13
+ service: Service
14
+
15
+ @classmethod
16
+ def __subclasshook__(cls, __subclass: type) -> bool:
17
+ return (
18
+ hasattr(__subclass, "marshal")
19
+ and callable(__subclass.marshal)
20
+ and hasattr(__subclass, "umarshal")
21
+ and callable(__subclass.unmarshal)
22
+ )
23
+
24
+ def __init__(self, service: Optional[Service] = None) -> None:
25
+ self.service = service if service is not None else TransactionalService()
26
+
27
+ def unmarshal(self, event) -> Operation:
28
+ """
29
+ Unmarshal the event in a tuple for processing
30
+
31
+ Parameters:
32
+ - event (dict): Lambda event object.
33
+
34
+ Returns:
35
+ - Operation containing the entity, action, and parameters
36
+ """
37
+ raise NotImplementedError
38
+
39
+ def marshal(self, result: list[dict]):
40
+ """
41
+ Marshal the result into a event response
42
+
43
+ Parameters:
44
+ - result (list): the data set to return in the response
45
+
46
+ Returns:
47
+ - the event response
48
+ """
49
+ return result
50
+
51
+ def process_event(self, event):
52
+ """
53
+ Process Lambda event using a domain function.
54
+
55
+ Parameters:
56
+ - service_function (callable): The service function to be executed.
57
+ - event (dict): Lambda event object.
58
+
59
+ Returns:
60
+ - any: Result of the domain function.
61
+ """
62
+ operation = self.unmarshal(event)
63
+
64
+ result = self.service.execute(operation)
65
+ log.debug(f"adapter result: {result}")
66
+
67
+ return self.marshal(result)
@@ -0,0 +1,79 @@
1
+ from humps import camelize, decamelize
2
+
3
+ from api_foundry.adapters.adapter import Adapter
4
+ from api_foundry.utils.logger import logger
5
+ from api_foundry.operation import Operation
6
+
7
+ log = logger(__name__)
8
+
9
+
10
+ class CaseChangeAdapter(Adapter):
11
+ """
12
+ Handles changing case from snake to camel and back
13
+ """
14
+
15
+ def unmarshal(self, event) -> Operation:
16
+ """
17
+ Unmarshal the event in a tuple for processing
18
+
19
+ Parameters:
20
+ - event (dict): Lambda event object.
21
+
22
+ Returns:
23
+ - tuple: Tuple containing entity operation, store_params, query_params and metadata params.
24
+ """
25
+ operation = super().unmarshal(event)
26
+
27
+ # determine case
28
+ self.camel_case = (
29
+ operation.metadata_params.get("_case", "snake") == "camel"
30
+ or self.__check_camel_case(operation.store_params)
31
+ or self.__check_camel_case(operation.query_params)
32
+ )
33
+ log.info(f"camel_case: {self.camel_case}")
34
+
35
+ if self.camel_case:
36
+ return Operation(
37
+ operation_id=operation.operation_id,
38
+ action=operation.action,
39
+ store_params=decamelize(operation.store_params),
40
+ query_params=decamelize(operation.query_params),
41
+ metadata_params=operation.metadata_params,
42
+ )
43
+
44
+ return operation
45
+
46
+ def marshal(self, result: list[dict]):
47
+ """
48
+ Marshal the result into a event response
49
+
50
+ Parameters:
51
+ - result (list): the data set to return in the response
52
+
53
+ Returns:
54
+ - the event response
55
+ """
56
+ super().marshal(result)
57
+
58
+ if not self.camel_case:
59
+ return result
60
+
61
+ converted_result = []
62
+ for item in result:
63
+ converted_result.append(camelize(item))
64
+
65
+ # convert back to camel case if needed
66
+ return converted_result
67
+
68
+ def __check_camel_case(self, params: dict) -> bool:
69
+ if params is not None:
70
+ # check the keys for an upper case character
71
+ for param in params:
72
+ if (
73
+ param != param.lower()
74
+ and param != param.upper()
75
+ and "_" not in param
76
+ ):
77
+ return True
78
+
79
+ return False
@@ -0,0 +1,112 @@
1
+ import json
2
+
3
+ from api_foundry.adapters.adapter import Adapter
4
+ from api_foundry.operation import Operation
5
+
6
+ actions_map = {
7
+ "GET": "read",
8
+ "POST": "create",
9
+ "PUT": "update",
10
+ "DELETE": "delete",
11
+ }
12
+
13
+
14
+ class GatewayAdapter(Adapter):
15
+ def marshal(self, result: list[dict]):
16
+ """
17
+ Marshal the result into a event response
18
+
19
+ Parameters:
20
+ - result (list): the data set to return in the response
21
+
22
+ Returns:
23
+ - the event response
24
+ """
25
+ return super().marshal(result)
26
+
27
+ def unmarshal(self, event):
28
+ """
29
+ Get parameters from the Lambda event.
30
+
31
+ Parameters:
32
+ - event (dict): Lambda event object.
33
+
34
+ Returns:
35
+ - tuple: Tuple containing data, query and metadata parameters.
36
+ """
37
+ entity = event.get("resource").split("/")[1]
38
+ action = actions_map.get(event.get("httpMethod").upper(), "read")
39
+
40
+ event_params = {}
41
+
42
+ path_parameters = self._convert_parameters(event.get("pathParameters"))
43
+ if path_parameters is not None:
44
+ event_params.update(path_parameters)
45
+
46
+ queryStringParameters = self._convert_parameters(
47
+ event.get("queryStringParameters")
48
+ )
49
+ if queryStringParameters is not None:
50
+ event_params.update(queryStringParameters)
51
+
52
+ query_params, metadata_params = self.split_params(event_params)
53
+
54
+ store_params = {}
55
+ body = event.get("body")
56
+ if body is not None and len(body) > 0:
57
+ store_params = json.loads(body)
58
+
59
+ return Operation(
60
+ operation_id=entity,
61
+ action=action,
62
+ store_params=store_params,
63
+ query_params=query_params,
64
+ metadata_params=metadata_params,
65
+ )
66
+
67
+ def _convert_parameters(self, parameters):
68
+ """
69
+ Convert parameters to appropriate types.
70
+
71
+ Parameters:
72
+ - parameters (dict): Dictionary of parameters.
73
+
74
+ Returns:
75
+ - dict: Dictionary with parameters converted to appropriate types.
76
+ """
77
+ if parameters is None:
78
+ return None
79
+
80
+ result = {}
81
+ for parameter, value in parameters.items():
82
+ try:
83
+ result[parameter] = int(value)
84
+ except ValueError:
85
+ try:
86
+ result[parameter] = float(value)
87
+ except ValueError:
88
+ result[parameter] = value
89
+ return result
90
+
91
+ def split_params(self, parameters: dict):
92
+ """
93
+ Split a dictionary into two dictionaries based on keys.
94
+
95
+ Parameters:
96
+ - dictionary (dict): Input dictionary.
97
+
98
+ Returns:
99
+ - tuple: A tuple containing two dictionaries.
100
+ The first dictionary contains metadata_params,
101
+ and the second dictionary query_params.
102
+ """
103
+ query_params = {}
104
+ metadata_params = {}
105
+
106
+ for key, value in parameters.items():
107
+ if key.startswith("__"):
108
+ metadata_params[key] = value
109
+ else:
110
+ query_params[key] = value
111
+
112
+ return query_params, metadata_params
@@ -1,17 +1,22 @@
1
1
  Metadata-Version: 2.1
2
- Name: api_foundry
3
- Version: 0.1.0
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.
2
+ Name: api-foundry
3
+ Version: 0.1.2
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
  Author-email: Daniel Repik <danrepik@icloud.com>
6
6
  Project-URL: Documentation, https://github.com/DanRepik/api-foundry
7
7
  Project-URL: Source, https://github.com/DanRepik/api-foundry
8
8
  Classifier: Programming Language :: Python :: 3.9
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
9
12
  Classifier: Operating System :: OS Independent
10
13
  Requires-Python: >=3.9
11
14
  License-File: LICENSE
12
- Requires-Dist: pyhumps~=3.8.0
13
- Requires-Dist: cryptography~=37.0.4
14
- Requires-Dist: requests~=2.28.2
15
- Requires-Dist: simplejson~=3.19.1
16
- Requires-Dist: pyyaml==6.0.1
15
+ Requires-Dist: pyhumps
16
+ Requires-Dist: cryptography
17
+ Requires-Dist: requests
18
+ Requires-Dist: simplejson
19
+ Requires-Dist: pyyaml
17
20
  Requires-Dist: boto3
21
+ Requires-Dist: pulumi
22
+ Requires-Dist: pulumi-aws
@@ -0,0 +1,58 @@
1
+ LICENSE
2
+ pyproject.toml
3
+ src/api_foundry/adapters/adapter.py
4
+ src/api_foundry/adapters/case_change_adapter.py
5
+ src/api_foundry/adapters/gateway_adapter.py
6
+ src/api_foundry/api_foundry.egg-info/PKG-INFO
7
+ src/api_foundry/api_foundry.egg-info/SOURCES.txt
8
+ src/api_foundry/api_foundry.egg-info/dependency_links.txt
9
+ src/api_foundry/api_foundry.egg-info/entry_points.txt
10
+ src/api_foundry/api_foundry.egg-info/requires.txt
11
+ src/api_foundry/api_foundry.egg-info/top_level.txt
12
+ src/api_foundry/cloudprints/archive_builder.py
13
+ src/api_foundry/cloudprints/hash_comparator.py
14
+ src/api_foundry/cloudprints/python_archive_builder.py
15
+ src/api_foundry/cloudprints/aws_cdk/iam_execution_role.py
16
+ src/api_foundry/cloudprints/pulumi/lambda_.py
17
+ src/api_foundry/cloudprints/pulumi/rest_api.py
18
+ src/api_foundry/connectors/connection.py
19
+ src/api_foundry/connectors/connection_factory.py
20
+ src/api_foundry/connectors/oracle_connector.py
21
+ src/api_foundry/connectors/postgres_connection.py
22
+ src/api_foundry/dao/dao.py
23
+ src/api_foundry/dao/operation_dao.py
24
+ src/api_foundry/dao/sql_custom_query_handler.py
25
+ src/api_foundry/dao/sql_delete_query_handler.py
26
+ src/api_foundry/dao/sql_insert_query_handler.py
27
+ src/api_foundry/dao/sql_query_handler.py
28
+ src/api_foundry/dao/sql_select_query_handler.py
29
+ src/api_foundry/dao/sql_subselect_query_handler.py
30
+ src/api_foundry/dao/sql_update_query_handler.py
31
+ src/api_foundry/iac/gateway_spec.py
32
+ src/api_foundry/iac/handler.py
33
+ src/api_foundry/iac/pulumi/api_maker.py
34
+ src/api_foundry/scripts/postgres_to_openapi.py
35
+ src/api_foundry/services/service.py
36
+ src/api_foundry/services/transactional_service.py
37
+ src/api_foundry/utils/app_exception.py
38
+ src/api_foundry/utils/logger.py
39
+ src/api_foundry/utils/model_factory.py
40
+ src/api_foundry/utils/spec_handler.py
41
+ tests/test_adapter.py
42
+ tests/test_association_operations.py
43
+ tests/test_connection_factory.py
44
+ tests/test_custom_operations.py
45
+ tests/test_custom_sql.py
46
+ tests/test_fixtures.py
47
+ tests/test_gateway_adapter.py
48
+ tests/test_gateway_spec.py
49
+ tests/test_handler.py
50
+ tests/test_metadata_operations.py
51
+ tests/test_model_factory.py
52
+ tests/test_query_operations.py
53
+ tests/test_schema_objects_fixtures.py
54
+ tests/test_spec_handler.py
55
+ tests/test_sql_handler.py
56
+ tests/test_sql_insert_handler.py
57
+ tests/test_sql_update_handler.py
58
+ tests/test_transactional_service.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ postgres_to_openapi = api_foundry.scripts.postgres_to_openapi:main
@@ -0,0 +1,8 @@
1
+ pyhumps
2
+ cryptography
3
+ requests
4
+ simplejson
5
+ pyyaml
6
+ boto3
7
+ pulumi
8
+ pulumi-aws
@@ -0,0 +1,8 @@
1
+ adapters
2
+ cloudprints
3
+ connectors
4
+ dao
5
+ iac
6
+ scripts
7
+ services
8
+ utils
@@ -0,0 +1,8 @@
1
+
2
+ class ArchiveBuilder:
3
+
4
+ def hash(self) -> str:
5
+ raise NotImplementedError
6
+
7
+ def location(self) -> str:
8
+ raise NotImplementedError