pygrestqlambda 0.0.0__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.
- pygrestqlambda-0.0.0/.github/workflows/publish.yml +28 -0
- pygrestqlambda-0.0.0/.github/workflows/validate.yml +25 -0
- pygrestqlambda-0.0.0/.gitignore +10 -0
- pygrestqlambda-0.0.0/LICENSE +21 -0
- pygrestqlambda-0.0.0/PKG-INFO +34 -0
- pygrestqlambda-0.0.0/README.md +11 -0
- pygrestqlambda-0.0.0/pyproject.toml +37 -0
- pygrestqlambda-0.0.0/scripts/validate.sh +29 -0
- pygrestqlambda-0.0.0/src/__init__.py +0 -0
- pygrestqlambda-0.0.0/src/pygrestqlambda/__init__.py +0 -0
- pygrestqlambda-0.0.0/src/pygrestqlambda/aws/lambda_function/json_transform.py +18 -0
- pygrestqlambda-0.0.0/src/pygrestqlambda/aws/lambda_function/proxy_integration_respose.py +54 -0
- pygrestqlambda-0.0.0/src/pygrestqlambda/db/record.py +66 -0
- pygrestqlambda-0.0.0/tests/__init__.py +0 -0
- pygrestqlambda-0.0.0/tests/aws/__init__.py +0 -0
- pygrestqlambda-0.0.0/tests/aws/lambda_function/__init__.py +0 -0
- pygrestqlambda-0.0.0/tests/aws/lambda_function/test_json_transform.py +27 -0
- pygrestqlambda-0.0.0/tests/test_record.py +8 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
name: Publish
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags: [ '*.*.*' ]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
publish:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
permissions:
|
11
|
+
id-token: write
|
12
|
+
contents: read
|
13
|
+
steps:
|
14
|
+
# Checkout project code
|
15
|
+
- uses: actions/checkout@v4
|
16
|
+
|
17
|
+
# Set up python environment
|
18
|
+
- uses: actions/setup-python@v5
|
19
|
+
with:
|
20
|
+
python-version: '3.11'
|
21
|
+
|
22
|
+
# Re-run validation and build
|
23
|
+
- name: Validate
|
24
|
+
run: ./scripts/validate.sh
|
25
|
+
|
26
|
+
# Get pypi credentials and publish
|
27
|
+
- name: Publish package distributions to PyPI
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Validate
|
2
|
+
|
3
|
+
# Only run on PRs to the main branch
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
branches: [ main ]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
validate:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
# Checkout project code
|
13
|
+
- uses: actions/checkout@v3
|
14
|
+
|
15
|
+
# Install and run shellcheck for all shell scripts
|
16
|
+
- run: sudo apt install shellcheck
|
17
|
+
- run: for f in $(find scripts -type f -name *.sh); do shellcheck $f; done;
|
18
|
+
|
19
|
+
# Use python setup action to configure version
|
20
|
+
- uses: actions/setup-python@v3
|
21
|
+
with:
|
22
|
+
python-version: '3.x'
|
23
|
+
|
24
|
+
# Install python poetry and dependencies for use in later steps
|
25
|
+
- run: ./scripts/validate.sh
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Voquis Limited
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: pygrestqlambda
|
3
|
+
Version: 0.0.0
|
4
|
+
Summary: PostgreSQL REST API framework for AWS Lambda functions
|
5
|
+
Project-URL: Homepage, https://github.com/mesogate/pygrestqlambda
|
6
|
+
Project-URL: Issues, https://github.com/mesogate/pygrestqlambda/issues
|
7
|
+
Author-email: Voquis Limited <opensource@voquis.com>
|
8
|
+
License-File: LICENSE
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
12
|
+
Requires-Python: >=3.11
|
13
|
+
Requires-Dist: aws-xray-sdk
|
14
|
+
Requires-Dist: boto3
|
15
|
+
Provides-Extra: dev
|
16
|
+
Requires-Dist: build; extra == 'dev'
|
17
|
+
Requires-Dist: pylint; extra == 'dev'
|
18
|
+
Requires-Dist: pytest; extra == 'dev'
|
19
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
20
|
+
Requires-Dist: ruff; extra == 'dev'
|
21
|
+
Requires-Dist: twine; extra == 'dev'
|
22
|
+
Description-Content-Type: text/markdown
|
23
|
+
|
24
|
+
# Python PostgreSQL REST API framework for AWS Lambda functions
|
25
|
+
> [!NOTE]
|
26
|
+
> Project status: `Alpha`
|
27
|
+
|
28
|
+
A REST API web framework for persisting records in a PostgreSQL database.
|
29
|
+
|
30
|
+
## Supported features
|
31
|
+
- Automatic creation of `uid` fields
|
32
|
+
- Automatic setting of `created_at` and `last_updated_at` timestamps
|
33
|
+
- Automatic setting of `creator_uid` and `last_updater_uid`
|
34
|
+
- RDS with IAM credentials
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Python PostgreSQL REST API framework for AWS Lambda functions
|
2
|
+
> [!NOTE]
|
3
|
+
> Project status: `Alpha`
|
4
|
+
|
5
|
+
A REST API web framework for persisting records in a PostgreSQL database.
|
6
|
+
|
7
|
+
## Supported features
|
8
|
+
- Automatic creation of `uid` fields
|
9
|
+
- Automatic setting of `created_at` and `last_updated_at` timestamps
|
10
|
+
- Automatic setting of `creator_uid` and `last_updater_uid`
|
11
|
+
- RDS with IAM credentials
|
@@ -0,0 +1,37 @@
|
|
1
|
+
[build-system]
|
2
|
+
build-backend = "hatchling.build"
|
3
|
+
requires = ["hatchling"]
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "pygrestqlambda"
|
7
|
+
version = "0.0.0"
|
8
|
+
description = "PostgreSQL REST API framework for AWS Lambda functions"
|
9
|
+
readme = "README.md"
|
10
|
+
requires-python = ">=3.11"
|
11
|
+
|
12
|
+
authors = [{ name = "Voquis Limited", email = "opensource@voquis.com" }]
|
13
|
+
|
14
|
+
classifiers = [
|
15
|
+
"Programming Language :: Python :: 3",
|
16
|
+
"License :: OSI Approved :: MIT License",
|
17
|
+
"Operating System :: OS Independent",
|
18
|
+
]
|
19
|
+
|
20
|
+
dependencies = [
|
21
|
+
"aws-xray-sdk",
|
22
|
+
"boto3"
|
23
|
+
]
|
24
|
+
|
25
|
+
[project.optional-dependencies]
|
26
|
+
dev = [
|
27
|
+
"build",
|
28
|
+
"pylint",
|
29
|
+
"pytest",
|
30
|
+
"pytest-cov",
|
31
|
+
"ruff",
|
32
|
+
"twine"
|
33
|
+
]
|
34
|
+
|
35
|
+
[project.urls]
|
36
|
+
Homepage = "https://github.com/mesogate/pygrestqlambda"
|
37
|
+
Issues = "https://github.com/mesogate/pygrestqlambda/issues"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
|
4
|
+
# Assumes the src contains a single package to be built
|
5
|
+
PACKAGE_PATH=$(find src/* -type d -not -path "src/__*" | head -n 1)
|
6
|
+
PACKAGE_NAME=${PACKAGE_PATH#src/}
|
7
|
+
echo "Using package path: $PACKAGE_PATH"
|
8
|
+
echo "Using package name: $PACKAGE_NAME"
|
9
|
+
|
10
|
+
# Install development dependencies with pip
|
11
|
+
pip install .[dev]
|
12
|
+
|
13
|
+
# Run formatting checks
|
14
|
+
echo "Running ruff"
|
15
|
+
ruff check
|
16
|
+
|
17
|
+
echo "Running pylint"
|
18
|
+
pylint src tests
|
19
|
+
|
20
|
+
# Run tests and generate coverage reports
|
21
|
+
echo "Running pytest"
|
22
|
+
pytest --cov="$PACKAGE_NAME" \
|
23
|
+
--cov-report term \
|
24
|
+
--cov-report html \
|
25
|
+
--cov-fail-under=100.00
|
26
|
+
|
27
|
+
# Check the build
|
28
|
+
python -m build
|
29
|
+
twine check --strict dist/*
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from uuid import UUID
|
2
|
+
from datetime import datetime
|
3
|
+
|
4
|
+
|
5
|
+
def json_output(value: object) -> str:
|
6
|
+
"""
|
7
|
+
Calculates the serialised version of an object to return in a JSON response
|
8
|
+
"""
|
9
|
+
|
10
|
+
# Handle UUIDs
|
11
|
+
if isinstance(value, UUID):
|
12
|
+
value = str(value)
|
13
|
+
|
14
|
+
# Handle timestamps
|
15
|
+
if isinstance(value, datetime):
|
16
|
+
value = value.isoformat()
|
17
|
+
|
18
|
+
return value
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"""
|
2
|
+
Receives payload in format sent by AWS REST API Gateway
|
3
|
+
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
|
4
|
+
|
5
|
+
Returns payload structure expected by REST API Gateway
|
6
|
+
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format
|
7
|
+
"""
|
8
|
+
|
9
|
+
import logging
|
10
|
+
import json
|
11
|
+
from dataclasses import dataclass
|
12
|
+
from pygrestqlambda.aws.lambda_function.json_transform import json_output
|
13
|
+
from base64 import b64encode
|
14
|
+
|
15
|
+
|
16
|
+
@dataclass
|
17
|
+
class LambdaFunctionProxyIntegrationResponse:
|
18
|
+
"""
|
19
|
+
Lambda function response
|
20
|
+
"""
|
21
|
+
is_base64_encoded: bool | None = False
|
22
|
+
status_code: int | None = 401
|
23
|
+
headers: dict | None = None
|
24
|
+
multi_value_headers: dict | None = None
|
25
|
+
body: str | None = None
|
26
|
+
|
27
|
+
def get_payload(self) -> dict:
|
28
|
+
"""
|
29
|
+
Gets payload to send to REST API Gateway
|
30
|
+
"""
|
31
|
+
|
32
|
+
# Set headers
|
33
|
+
if self.headers is None:
|
34
|
+
self.headers = {}
|
35
|
+
|
36
|
+
if "Content-Type" not in self.headers:
|
37
|
+
self.headers["Content-Type"] = "application/json"
|
38
|
+
|
39
|
+
# Calculate body
|
40
|
+
if self.is_base64_encoded:
|
41
|
+
body = b64encode(self.body).decode("utf-8")
|
42
|
+
else:
|
43
|
+
body = json.dumps(self.body, default=json_output)
|
44
|
+
|
45
|
+
logging.debug("Transforming dataclass dictionary to JSON")
|
46
|
+
data = {
|
47
|
+
"isBase64Encoded": self.is_base64_encoded,
|
48
|
+
"statusCode": self.status_code,
|
49
|
+
"headers": self.headers,
|
50
|
+
"multiValueHeaders": self.multi_value_headers,
|
51
|
+
"body": body,
|
52
|
+
}
|
53
|
+
|
54
|
+
return data
|
@@ -0,0 +1,66 @@
|
|
1
|
+
from abc import ABCMeta
|
2
|
+
|
3
|
+
|
4
|
+
class Record(metaclass=ABCMeta):
|
5
|
+
"""
|
6
|
+
Generic record that maps to a row in a database table
|
7
|
+
"""
|
8
|
+
|
9
|
+
def __init__(self, conn: bool = False) -> None:
|
10
|
+
self.conn = conn
|
11
|
+
|
12
|
+
def before_create(self):
|
13
|
+
"""
|
14
|
+
Runs before a new record is created. Useful for mutating a new record
|
15
|
+
before being committed.
|
16
|
+
"""
|
17
|
+
pass
|
18
|
+
|
19
|
+
def before_read(self):
|
20
|
+
"""
|
21
|
+
Before a record is retrieved from the database. Useful for injecting
|
22
|
+
filters or sorting.
|
23
|
+
"""
|
24
|
+
pass
|
25
|
+
|
26
|
+
def before_update(self):
|
27
|
+
"""
|
28
|
+
Before a new record is created. Useful for mutating a record before it
|
29
|
+
is committed.
|
30
|
+
"""
|
31
|
+
pass
|
32
|
+
|
33
|
+
def before_delete(self):
|
34
|
+
"""
|
35
|
+
Before an existing record is deleted. Useful for e.g. updating counters
|
36
|
+
or other aggregate fields in other tables.
|
37
|
+
"""
|
38
|
+
pass
|
39
|
+
|
40
|
+
def after_create(self):
|
41
|
+
"""
|
42
|
+
Runs after a new record is created. Useful for updating e.g. counters
|
43
|
+
tables.
|
44
|
+
"""
|
45
|
+
pass
|
46
|
+
|
47
|
+
def after_read(self):
|
48
|
+
"""
|
49
|
+
After a record is retrieved from the database. Useful for transforming
|
50
|
+
retrieved data.
|
51
|
+
"""
|
52
|
+
pass
|
53
|
+
|
54
|
+
def after_update(self):
|
55
|
+
"""
|
56
|
+
Runs after a new record is updated. Useful for updating e.g. counters
|
57
|
+
tables.
|
58
|
+
"""
|
59
|
+
pass
|
60
|
+
|
61
|
+
def after_delete(self):
|
62
|
+
"""
|
63
|
+
Runs after an existing record is deleted. Useful for updating e.g.
|
64
|
+
counters tables.
|
65
|
+
"""
|
66
|
+
pass
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"""
|
2
|
+
Test JSON transformation for lambda proxy integration response
|
3
|
+
"""
|
4
|
+
|
5
|
+
from uuid import uuid4
|
6
|
+
from datetime import datetime
|
7
|
+
from pygrestqlambda.aws.lambda_function.json_transform import json_output
|
8
|
+
|
9
|
+
|
10
|
+
def test_uuid():
|
11
|
+
"""
|
12
|
+
Test UUIDs are transformed correctly
|
13
|
+
"""
|
14
|
+
|
15
|
+
uid = uuid4()
|
16
|
+
|
17
|
+
assert json_output(uid) == str(uid)
|
18
|
+
|
19
|
+
|
20
|
+
def test_datetime():
|
21
|
+
"""
|
22
|
+
Test UUIDs are transformed correctly
|
23
|
+
"""
|
24
|
+
|
25
|
+
now = datetime.now()
|
26
|
+
|
27
|
+
assert json_output(now) == now.isoformat()
|