New service

This commit is contained in:
Roberto Alsina 2023-05-16 12:35:02 -03:00
parent 61893d8c77
commit f775068850
6 changed files with 89 additions and 0 deletions

View File

@ -11,3 +11,7 @@ functions:
lang: python3-flask lang: python3-flask
handler: ./historico handler: ./historico
image: ralsina/nombres_historico:latest image: ralsina/nombres_historico:latest
tapas:
lang: python3-flask
handler: ./tapas
image: ralsina/tapas:latest

View File

32
nombres/tapas/handler.py Normal file
View File

@ -0,0 +1,32 @@
from json import loads
from tapita import Cover
from io import BytesIO
import base64
def handle(req):
"""handle a request to the function
Args:
req (str): request body
{
"title": "foo",
"subtitle": "bar",
"author": "bat",
}
"""
try:
args = loads(req)
except Exception:
return "Bad Request", 400
c = Cover(**args)
byte_arr = BytesIO()
c.image.save(byte_arr, format="JPEG")
# return Response(chart.render(is_unicode=True), mimetype="image/svg+xml")
return (
f'<img src="data:image/jpeg;base64, {base64.b64encode(byte_arr.getvalue()).decode("utf-8")}">',
200,
{"Content-Type": "text/html"},
)

View File

@ -0,0 +1,11 @@
from .handler import handle
# Test your handler here
# To disable testing, you can set the build_arg `TEST_ENABLED=false` on the CLI or in your stack.yml
# https://docs.openfaas.com/reference/yaml/#function-build-args-build-args
def test_handle():
# assert handle("input") == "input"
pass

View File

@ -0,0 +1 @@
tapita

41
nombres/tapas/tox.ini Normal file
View File

@ -0,0 +1,41 @@
# If you would like to disable
# automated testing during faas-cli build,
# Replace the content of this file with
# [tox]
# skipsdist = true
# You can also edit, remove, or add additional test steps
# by editing, removing, or adding new testenv sections
# find out more about tox: https://tox.readthedocs.io/en/latest/
[tox]
envlist = lint,test
skipsdist = true
[testenv:test]
deps =
flask
pytest
-rrequirements.txt
commands =
# run unit tests with pytest
# https://docs.pytest.org/en/stable/
# configure by adding a pytest.ini to your handler
pytest
[testenv:lint]
deps =
flake8
commands =
flake8 .
[flake8]
count = true
max-line-length = 127
max-complexity = 10
statistics = true
# stop the build if there are Python syntax errors or undefined names
select = E9,F63,F7,F82
show-source = true