New service
This commit is contained in:
parent
61893d8c77
commit
f775068850
@ -11,3 +11,7 @@ functions:
|
||||
lang: python3-flask
|
||||
handler: ./historico
|
||||
image: ralsina/nombres_historico:latest
|
||||
tapas:
|
||||
lang: python3-flask
|
||||
handler: ./tapas
|
||||
image: ralsina/tapas:latest
|
||||
|
0
nombres/tapas/__init__.py
Normal file
0
nombres/tapas/__init__.py
Normal file
32
nombres/tapas/handler.py
Normal file
32
nombres/tapas/handler.py
Normal 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"},
|
||||
)
|
11
nombres/tapas/handler_test.py
Normal file
11
nombres/tapas/handler_test.py
Normal 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
|
1
nombres/tapas/requirements.txt
Normal file
1
nombres/tapas/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
tapita
|
41
nombres/tapas/tox.ini
Normal file
41
nombres/tapas/tox.ini
Normal 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
|
Loading…
Reference in New Issue
Block a user