Skip to content

Commit 00b2db0

Browse files
committed
feat(splat): add uptick_splat library
1 parent 0d01ffa commit 00b2db0

File tree

8 files changed

+408
-14
lines changed

8 files changed

+408
-14
lines changed

lambda_function.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,30 @@ def lambda_handler(event, context):
322322

323323

324324
def check_license():
325-
tree = ET.parse('./prince-engine/license/license.dat')
326-
parsed_license = {child.tag: (child.attrib, child.text) for child in tree.getroot() if child.tag != 'signature'}
327-
is_demo_license = bool(list(filter(lambda x: x[0] == 'option' and x[1].get('id') == 'demo', parsed_license)))
328-
329-
return respond({
330-
"statusCode": 200,
331-
"headers": {
332-
"Content-Type": "application/json",
333-
},
334-
"body": json.dumps({**parsed_license, 'is_demo_license': is_demo_license}),
335-
"isBase64Encoded": False,
336-
})
325+
tree = ET.parse("./prince-engine/license/license.dat")
326+
parsed_license = {
327+
child.tag: (child.attrib, child.text)
328+
for child in tree.getroot()
329+
if child.tag != "signature"
330+
}
331+
is_demo_license = bool(
332+
list(
333+
filter(
334+
lambda x: x[0] == "option" and x[1].get("id") == "demo", parsed_license
335+
)
336+
)
337+
)
338+
339+
return respond(
340+
{
341+
"statusCode": 200,
342+
"headers": {
343+
"Content-Type": "application/json",
344+
},
345+
"body": json.dumps({**parsed_license, "is_demo_license": is_demo_license}),
346+
"isBase64Encoded": False,
347+
}
348+
)
337349

338350

339351
if __name__ == "__main__":

poetry.lock

+200
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[tool.poetry]
22
name = "uptick-splat"
33
version = "0.1.0"
4-
description = "Splat library"
4+
description = "Django library for invoking splat"
55
authors = ["william chu <[email protected]>"]
66
readme = "README.md"
7-
packages = [{include = "uptick_splat"}]
7+
packages = [{ include = "uptick_splat" }]
88

99
[tool.poetry.dependencies]
1010
python = "^3.9"
11+
django = ">=3.1, <5.0.0"
12+
boto3 = "*"
1113

1214

1315
[build-system]

uptick_splat/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from .config import config # noqa
2+
from .utils import SplatPDFGenerationFailure, pdf_with_splat # noqa
3+
4+
__version__ = "0.1.0"
5+
6+
__all__ = [
7+
"config",
8+
"SplatPDFGenerationFailure",
9+
"pdf_with_splat",
10+
"__version__",
11+
]

uptick_splat/config.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from dataclasses import dataclass
2+
from typing import Any, Callable
3+
4+
import boto3
5+
6+
from .logging import logger
7+
8+
9+
def get_session() -> Any:
10+
"""This function can be overridden to provide a custom session"""
11+
session = boto3.session.Session()
12+
return session
13+
14+
15+
def delete_key(bucket_name: str, path: str) -> None:
16+
"""This function can be overriden to provide a custom delete key function"""
17+
session = config.get_session()
18+
s3_client = session.client("s3")
19+
try:
20+
s3_client.delete_object(Bucket=bucket_name, Key=path)
21+
except Exception as e:
22+
logger.warning(f"Failed to delete {path} from s3: {e}")
23+
24+
25+
@dataclass
26+
class Config:
27+
function_region: str = "ap-southeast-2"
28+
function_name: str = "splat-prod"
29+
default_bucket_name: str = ""
30+
default_html_key: str = "ExpireAfter=1w"
31+
32+
get_session: Callable[[], Any] = get_session
33+
delete_key: Callable[[str, str], None] = delete_key
34+
35+
36+
config = Config()

uptick_splat/exceptions.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class SplatPDFGenerationFailure(Exception):
2+
pass

uptick_splat/logging.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import logging
2+
3+
metrics = logging.getLogger("metrics")
4+
logger = logging.getLogger("splat")

0 commit comments

Comments
 (0)