summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoprDistGit <infra@openeuler.org>2023-06-20 08:02:38 +0000
committerCoprDistGit <infra@openeuler.org>2023-06-20 08:02:38 +0000
commit4a86288483e6ad993bdba77a007c83121545bc4f (patch)
tree31544d15b1fac98c47c75bf22587328fc87ac778
parent3559dce9fa2db3fec52f828cfdccf4bc5f9c2ebd (diff)
automatic import of python-lambda-proxyopeneuler20.03
-rw-r--r--.gitignore1
-rw-r--r--python-lambda-proxy.spec1236
-rw-r--r--sources1
3 files changed, 1238 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..865995e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/lambda-proxy-5.2.1.tar.gz
diff --git a/python-lambda-proxy.spec b/python-lambda-proxy.spec
new file mode 100644
index 0000000..adb6276
--- /dev/null
+++ b/python-lambda-proxy.spec
@@ -0,0 +1,1236 @@
+%global _empty_manifest_terminate_build 0
+Name: python-lambda-proxy
+Version: 5.2.1
+Release: 1
+Summary: Simple AWS Lambda proxy to handle API Gateway request
+License: BSD
+URL: https://github.com/vincentsarago/lambda-proxy
+Source0: https://mirrors.aliyun.com/pypi/web/packages/57/79/58a6927147afd1ce541c0c4ea950479cbb4224624ee2b641990a90f01359/lambda-proxy-5.2.1.tar.gz
+BuildArch: noarch
+
+
+%description
+# lambda-proxy
+
+[![Packaging status](https://badge.fury.io/py/lambda-proxy.svg)](https://badge.fury.io/py/lambda-proxy)
+[![CircleCI](https://circleci.com/gh/vincentsarago/lambda-proxy.svg?style=svg)](https://circleci.com/gh/vincentsarago/lambda-proxy)
+[![codecov](https://codecov.io/gh/vincentsarago/lambda-proxy/branch/master/graph/badge.svg)](https://codecov.io/gh/vincentsarago/lambda-proxy)
+
+A zero-requirement proxy linking AWS API Gateway `{proxy+}` requests and AWS Lambda.
+
+<img width="600" alt="" src="https://user-images.githubusercontent.com/10407788/58742966-6ff50480-83f7-11e9-81f7-3ba7aa2310bb.png">
+
+## Install
+
+```bash
+$ pip install -U pip
+$ pip install lambda-proxy
+```
+
+Or install from source:
+
+```bash
+$ git clone https://github.com/vincentsarag/lambda-proxy.git
+$ cd lambda-proxy
+$ pip install -U pip
+$ pip install -e .
+```
+
+# Usage
+
+Lambda proxy is designed to work well with both API Gateway's REST API and the
+newer and cheaper HTTP API. If you have issues using with the HTTP API, please
+open an issue.
+
+With GET request
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/tests/<id>', methods=['GET'], cors=True)
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+With POST request
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/tests/<id>', methods=['POST'], cors=True)
+def print_id(id, body):
+ return ('OK', 'plain/text', id)
+```
+
+**Note**
+
+Starting in version 5.2.0, users can now add route using `@APP.get` and `@APP.post` removing the need to add `methods=[**]`
+
+## Binary body
+
+Starting from version 5.0.0, lambda-proxy will decode base64 encoded body on POST message.
+
+Pre 5.0.0
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test', methods=['POST']e)
+def print_id(body):
+ body = json.loads(base64.b64decode(body).decode())
+```
+
+Post 5.0.0
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test', methods=['POST']e)
+def print_id(body):
+ body = json.loads(body)
+```
+
+# Routes
+
+Route schema is simmilar to the one used in [Flask](http://flask.pocoo.org/docs/1.0/api/#url-route-registrations)
+
+> Variable parts in the route can be specified with angular brackets `/user/<username>`. By default a variable part in the URL accepts any string without a slash however a different converter can be specified as well by using `<converter:name>`.
+
+Converters:
+- `int`: integer
+- `string`: string
+- `float`: float number
+- `uuid`: UUID
+
+example:
+- `/app/<user>/<id>` (`user` and `id` are variables)
+- `/app/<string:value>/<float:num>` (`value` will be a string, while `num` will be a float)
+
+## Regex
+You can also add regex parameters descriptions using special converter `regex()`
+
+example:
+```python
+@APP.get("/app/<regex([a-z]+):regularuser>")
+def print_user(regularuser):
+ return ('OK', 'plain/text', f"regular {regularuser}")
+
+@APP.get("/app/<regex([A-Z]+):capitaluser>")
+def print_user(capitaluser):
+ return ('OK', 'plain/text', f"CAPITAL {capitaluser}")
+```
+
+#### Warning
+
+when using **regex()** you must use different variable names or the route might not show up in the documentation.
+
+```python
+@APP.get("/app/<regex([a-z]+):user>")
+def print_user(user):
+ return ('OK', 'plain/text', f"regular {user}")
+
+@APP.get("/app/<regex([A-Z]+):user>")
+def print_user(user):
+ return ('OK', 'plain/text', f"CAPITAL {user}")
+```
+This app will work but the documentation will only show the second route because in `openapi.json`, route names will be `/app/{user}` for both routes.
+
+# Route Options
+
+- **path**: the URL rule as string
+- **methods**: list of HTTP methods allowed, default: ["GET"]
+- **cors**: allow CORS, default: `False`
+- **token**: set `access_token` validation
+- **payload_compression_method**: Enable and select an output body compression
+- **binary_b64encode**: base64 encode the output body (API Gateway)
+- **ttl**: Cache Control setting (Time to Live) **(Deprecated in 6.0.0)**
+- **cache_control**: Cache Control setting
+- **description**: route description (for documentation)
+- **tag**: list of tags (for documentation)
+
+## Cache Control
+
+Add a Cache Control header with a Time to Live (TTL) in seconds.
+
+```python
+from lambda_proxy.proxy import API
+APP = API(app_name="app")
+
+@APP.get('/test/tests/<id>', cors=True, cache_control="public,max-age=3600")
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+Note: If function returns other then "OK", Cache-Control will be set to `no-cache`
+
+## Binary responses
+
+When working with binary on API-Gateway we must return a base64 encoded string
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/test/tests/<filename>.jpg', cors=True, binary_b64encode=True)
+def print_id(filename):
+ with open(f"{filename}.jpg", "rb") as f:
+ return ('OK', 'image/jpeg', f.read())
+```
+
+## Compression
+
+Enable compression if "Accept-Encoding" if found in headers.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get(
+ '/test/tests/<filename>.jpg',
+ cors=True,
+ binary_b64encode=True,
+ payload_compression_method="gzip"
+)
+def print_id(filename):
+ with open(f"{filename}.jpg", "rb") as f:
+ return ('OK', 'image/jpeg', f.read())
+```
+
+## Simple Auth token
+
+Lambda-proxy provide a simple token validation system.
+
+- a "TOKEN" variable must be set in the environment
+- each request must provide a "access_token" params (e.g curl
+ http://myurl/test/tests/myid?access_token=blabla)
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/test/tests/<id>', cors=True, token=True)
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+## URL schema and request parameters
+
+QueryString parameters are passed as function's options.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/<id>', cors=True)
+def print_id(id, name=None):
+ return ('OK', 'plain/text', f"{id}{name}")
+```
+
+requests:
+
+```bash
+$ curl /000001
+ 0001
+
+$ curl /000001?name=vincent
+ 0001vincent
+```
+
+## Multiple Routes
+
+```python
+from lambda_proxy.proxy import API
+APP = API(name="app")
+
+@APP.get('/<id>', cors=True)
+@APP.get('/<id>/<int:number>', cors=True)
+def print_id(id, number=None, name=None):
+ return ('OK', 'plain/text', f"{id}-{name}-{number}")
+```
+requests:
+
+```bash
+
+$ curl /000001
+ 0001--
+
+$ curl /000001?name=vincent
+ 0001-vincent-
+
+$ curl /000001/1?name=vincent
+ 0001-vincent-1
+```
+
+# Advanced features
+
+## Context and Event passing
+
+Pass event and context to the handler function.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get("/<id>", cors=True)
+@APP.pass_event
+@APP.pass_context
+def print_id(ctx, evt, id):
+ print(ctx)
+ print(evt)
+ return ('OK', 'plain/text', f"{id}")
+```
+
+# Automatic OpenAPI documentation
+
+By default the APP (`lambda_proxy.proxy.API`) is provided with three (3) routes:
+- `/openapi.json`: print OpenAPI JSON definition
+
+- `/docs`: swagger html UI
+![swagger](https://user-images.githubusercontent.com/10407788/58707335-9cbb0480-8382-11e9-927f-8d992cf2531a.jpg)
+
+- `/redoc`: Redoc html UI
+![redoc](https://user-images.githubusercontent.com/10407788/58707338-9dec3180-8382-11e9-8dec-18173e39258f.jpg)
+
+**Function annotations**
+
+To be able to render full and precise API documentation, lambda_proxy uses python type hint and annotations [link](https://www.python.org/dev/peps/pep-3107/).
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/<int:id>', methods=['GET'], cors=True)
+def print_id(id: int, num: float = 0.2) -> Tuple(str, str, str):
+ return ('OK', 'plain/text', id)
+```
+
+In the example above, our route `/test/<int:id>` define an input `id` to be a `INT`, while we also add this hint to the function `print_id` we also specify the type (and default) of the `num` option.
+
+# Custom Domain and path mapping
+
+Since version 4.1.1, lambda-proxy support custom domain and path mapping (see https://github.com/vincentsarago/lambda-proxy/issues/16).
+
+Note: When using path mapping other than `root` (`/`), `/` route won't be available.
+
+```python
+from lambda_proxy.proxy import API
+
+api = API(name="api", debug=True)
+
+
+# This route won't work when using path mapping
+@api.get("/", cors=True)
+# This route will work only if the path mapping is set to /api
+@api.get("/api", cors=True)
+def index():
+ html = """<!DOCTYPE html>
+ <html>
+ <header><title>This is title</title></header>
+ <body>
+ Hello world
+ </body>
+ </html>"""
+ return ("OK", "text/html", html)
+
+
+@api.get("/yo", cors=True)
+def yo():
+ return ("OK", "text/plain", "YOOOOO")
+```
+
+# Plugin
+
+- Add cache layer: https://github.com/vincentsarago/lambda-proxy-cache
+
+
+# Examples
+
+- https://github.com/vincentsarago/lambda-proxy/tree/master/example
+- https://github.com/RemotePixel/remotepixel-tiler
+
+
+# Contribution & Devellopement
+
+Issues and pull requests are more than welcome.
+
+**Dev install & Pull-Request**
+
+```bash
+$ git clone https://github.com/vincentsarago/lambda-proxy.git
+$ cd lambda-proxy
+$ pip install -e .[dev]
+```
+
+**Python3.7 only**
+
+This repo is set to use pre-commit to run *mypy*, *flake8*, *pydocstring* and *black* ("uncompromising Python code formatter") when committing new code.
+
+```bash
+$ pre-commit install
+$ git add .
+$ git commit -m'my change'
+ black.........................Passed
+ Flake8........................Passed
+ Verifying PEP257 Compliance...Passed
+ mypy..........................Passed
+$ git push origin
+```
+
+### License
+
+See [LICENSE.txt](/LICENSE.txt>).
+
+### Authors
+
+See [AUTHORS.txt](/AUTHORS.txt>).
+
+### Changes
+
+See [CHANGES.txt](/CHANGES.txt>).
+
+%package -n python3-lambda-proxy
+Summary: Simple AWS Lambda proxy to handle API Gateway request
+Provides: python-lambda-proxy
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-lambda-proxy
+# lambda-proxy
+
+[![Packaging status](https://badge.fury.io/py/lambda-proxy.svg)](https://badge.fury.io/py/lambda-proxy)
+[![CircleCI](https://circleci.com/gh/vincentsarago/lambda-proxy.svg?style=svg)](https://circleci.com/gh/vincentsarago/lambda-proxy)
+[![codecov](https://codecov.io/gh/vincentsarago/lambda-proxy/branch/master/graph/badge.svg)](https://codecov.io/gh/vincentsarago/lambda-proxy)
+
+A zero-requirement proxy linking AWS API Gateway `{proxy+}` requests and AWS Lambda.
+
+<img width="600" alt="" src="https://user-images.githubusercontent.com/10407788/58742966-6ff50480-83f7-11e9-81f7-3ba7aa2310bb.png">
+
+## Install
+
+```bash
+$ pip install -U pip
+$ pip install lambda-proxy
+```
+
+Or install from source:
+
+```bash
+$ git clone https://github.com/vincentsarag/lambda-proxy.git
+$ cd lambda-proxy
+$ pip install -U pip
+$ pip install -e .
+```
+
+# Usage
+
+Lambda proxy is designed to work well with both API Gateway's REST API and the
+newer and cheaper HTTP API. If you have issues using with the HTTP API, please
+open an issue.
+
+With GET request
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/tests/<id>', methods=['GET'], cors=True)
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+With POST request
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/tests/<id>', methods=['POST'], cors=True)
+def print_id(id, body):
+ return ('OK', 'plain/text', id)
+```
+
+**Note**
+
+Starting in version 5.2.0, users can now add route using `@APP.get` and `@APP.post` removing the need to add `methods=[**]`
+
+## Binary body
+
+Starting from version 5.0.0, lambda-proxy will decode base64 encoded body on POST message.
+
+Pre 5.0.0
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test', methods=['POST']e)
+def print_id(body):
+ body = json.loads(base64.b64decode(body).decode())
+```
+
+Post 5.0.0
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test', methods=['POST']e)
+def print_id(body):
+ body = json.loads(body)
+```
+
+# Routes
+
+Route schema is simmilar to the one used in [Flask](http://flask.pocoo.org/docs/1.0/api/#url-route-registrations)
+
+> Variable parts in the route can be specified with angular brackets `/user/<username>`. By default a variable part in the URL accepts any string without a slash however a different converter can be specified as well by using `<converter:name>`.
+
+Converters:
+- `int`: integer
+- `string`: string
+- `float`: float number
+- `uuid`: UUID
+
+example:
+- `/app/<user>/<id>` (`user` and `id` are variables)
+- `/app/<string:value>/<float:num>` (`value` will be a string, while `num` will be a float)
+
+## Regex
+You can also add regex parameters descriptions using special converter `regex()`
+
+example:
+```python
+@APP.get("/app/<regex([a-z]+):regularuser>")
+def print_user(regularuser):
+ return ('OK', 'plain/text', f"regular {regularuser}")
+
+@APP.get("/app/<regex([A-Z]+):capitaluser>")
+def print_user(capitaluser):
+ return ('OK', 'plain/text', f"CAPITAL {capitaluser}")
+```
+
+#### Warning
+
+when using **regex()** you must use different variable names or the route might not show up in the documentation.
+
+```python
+@APP.get("/app/<regex([a-z]+):user>")
+def print_user(user):
+ return ('OK', 'plain/text', f"regular {user}")
+
+@APP.get("/app/<regex([A-Z]+):user>")
+def print_user(user):
+ return ('OK', 'plain/text', f"CAPITAL {user}")
+```
+This app will work but the documentation will only show the second route because in `openapi.json`, route names will be `/app/{user}` for both routes.
+
+# Route Options
+
+- **path**: the URL rule as string
+- **methods**: list of HTTP methods allowed, default: ["GET"]
+- **cors**: allow CORS, default: `False`
+- **token**: set `access_token` validation
+- **payload_compression_method**: Enable and select an output body compression
+- **binary_b64encode**: base64 encode the output body (API Gateway)
+- **ttl**: Cache Control setting (Time to Live) **(Deprecated in 6.0.0)**
+- **cache_control**: Cache Control setting
+- **description**: route description (for documentation)
+- **tag**: list of tags (for documentation)
+
+## Cache Control
+
+Add a Cache Control header with a Time to Live (TTL) in seconds.
+
+```python
+from lambda_proxy.proxy import API
+APP = API(app_name="app")
+
+@APP.get('/test/tests/<id>', cors=True, cache_control="public,max-age=3600")
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+Note: If function returns other then "OK", Cache-Control will be set to `no-cache`
+
+## Binary responses
+
+When working with binary on API-Gateway we must return a base64 encoded string
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/test/tests/<filename>.jpg', cors=True, binary_b64encode=True)
+def print_id(filename):
+ with open(f"{filename}.jpg", "rb") as f:
+ return ('OK', 'image/jpeg', f.read())
+```
+
+## Compression
+
+Enable compression if "Accept-Encoding" if found in headers.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get(
+ '/test/tests/<filename>.jpg',
+ cors=True,
+ binary_b64encode=True,
+ payload_compression_method="gzip"
+)
+def print_id(filename):
+ with open(f"{filename}.jpg", "rb") as f:
+ return ('OK', 'image/jpeg', f.read())
+```
+
+## Simple Auth token
+
+Lambda-proxy provide a simple token validation system.
+
+- a "TOKEN" variable must be set in the environment
+- each request must provide a "access_token" params (e.g curl
+ http://myurl/test/tests/myid?access_token=blabla)
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/test/tests/<id>', cors=True, token=True)
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+## URL schema and request parameters
+
+QueryString parameters are passed as function's options.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/<id>', cors=True)
+def print_id(id, name=None):
+ return ('OK', 'plain/text', f"{id}{name}")
+```
+
+requests:
+
+```bash
+$ curl /000001
+ 0001
+
+$ curl /000001?name=vincent
+ 0001vincent
+```
+
+## Multiple Routes
+
+```python
+from lambda_proxy.proxy import API
+APP = API(name="app")
+
+@APP.get('/<id>', cors=True)
+@APP.get('/<id>/<int:number>', cors=True)
+def print_id(id, number=None, name=None):
+ return ('OK', 'plain/text', f"{id}-{name}-{number}")
+```
+requests:
+
+```bash
+
+$ curl /000001
+ 0001--
+
+$ curl /000001?name=vincent
+ 0001-vincent-
+
+$ curl /000001/1?name=vincent
+ 0001-vincent-1
+```
+
+# Advanced features
+
+## Context and Event passing
+
+Pass event and context to the handler function.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get("/<id>", cors=True)
+@APP.pass_event
+@APP.pass_context
+def print_id(ctx, evt, id):
+ print(ctx)
+ print(evt)
+ return ('OK', 'plain/text', f"{id}")
+```
+
+# Automatic OpenAPI documentation
+
+By default the APP (`lambda_proxy.proxy.API`) is provided with three (3) routes:
+- `/openapi.json`: print OpenAPI JSON definition
+
+- `/docs`: swagger html UI
+![swagger](https://user-images.githubusercontent.com/10407788/58707335-9cbb0480-8382-11e9-927f-8d992cf2531a.jpg)
+
+- `/redoc`: Redoc html UI
+![redoc](https://user-images.githubusercontent.com/10407788/58707338-9dec3180-8382-11e9-8dec-18173e39258f.jpg)
+
+**Function annotations**
+
+To be able to render full and precise API documentation, lambda_proxy uses python type hint and annotations [link](https://www.python.org/dev/peps/pep-3107/).
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/<int:id>', methods=['GET'], cors=True)
+def print_id(id: int, num: float = 0.2) -> Tuple(str, str, str):
+ return ('OK', 'plain/text', id)
+```
+
+In the example above, our route `/test/<int:id>` define an input `id` to be a `INT`, while we also add this hint to the function `print_id` we also specify the type (and default) of the `num` option.
+
+# Custom Domain and path mapping
+
+Since version 4.1.1, lambda-proxy support custom domain and path mapping (see https://github.com/vincentsarago/lambda-proxy/issues/16).
+
+Note: When using path mapping other than `root` (`/`), `/` route won't be available.
+
+```python
+from lambda_proxy.proxy import API
+
+api = API(name="api", debug=True)
+
+
+# This route won't work when using path mapping
+@api.get("/", cors=True)
+# This route will work only if the path mapping is set to /api
+@api.get("/api", cors=True)
+def index():
+ html = """<!DOCTYPE html>
+ <html>
+ <header><title>This is title</title></header>
+ <body>
+ Hello world
+ </body>
+ </html>"""
+ return ("OK", "text/html", html)
+
+
+@api.get("/yo", cors=True)
+def yo():
+ return ("OK", "text/plain", "YOOOOO")
+```
+
+# Plugin
+
+- Add cache layer: https://github.com/vincentsarago/lambda-proxy-cache
+
+
+# Examples
+
+- https://github.com/vincentsarago/lambda-proxy/tree/master/example
+- https://github.com/RemotePixel/remotepixel-tiler
+
+
+# Contribution & Devellopement
+
+Issues and pull requests are more than welcome.
+
+**Dev install & Pull-Request**
+
+```bash
+$ git clone https://github.com/vincentsarago/lambda-proxy.git
+$ cd lambda-proxy
+$ pip install -e .[dev]
+```
+
+**Python3.7 only**
+
+This repo is set to use pre-commit to run *mypy*, *flake8*, *pydocstring* and *black* ("uncompromising Python code formatter") when committing new code.
+
+```bash
+$ pre-commit install
+$ git add .
+$ git commit -m'my change'
+ black.........................Passed
+ Flake8........................Passed
+ Verifying PEP257 Compliance...Passed
+ mypy..........................Passed
+$ git push origin
+```
+
+### License
+
+See [LICENSE.txt](/LICENSE.txt>).
+
+### Authors
+
+See [AUTHORS.txt](/AUTHORS.txt>).
+
+### Changes
+
+See [CHANGES.txt](/CHANGES.txt>).
+
+%package help
+Summary: Development documents and examples for lambda-proxy
+Provides: python3-lambda-proxy-doc
+%description help
+# lambda-proxy
+
+[![Packaging status](https://badge.fury.io/py/lambda-proxy.svg)](https://badge.fury.io/py/lambda-proxy)
+[![CircleCI](https://circleci.com/gh/vincentsarago/lambda-proxy.svg?style=svg)](https://circleci.com/gh/vincentsarago/lambda-proxy)
+[![codecov](https://codecov.io/gh/vincentsarago/lambda-proxy/branch/master/graph/badge.svg)](https://codecov.io/gh/vincentsarago/lambda-proxy)
+
+A zero-requirement proxy linking AWS API Gateway `{proxy+}` requests and AWS Lambda.
+
+<img width="600" alt="" src="https://user-images.githubusercontent.com/10407788/58742966-6ff50480-83f7-11e9-81f7-3ba7aa2310bb.png">
+
+## Install
+
+```bash
+$ pip install -U pip
+$ pip install lambda-proxy
+```
+
+Or install from source:
+
+```bash
+$ git clone https://github.com/vincentsarag/lambda-proxy.git
+$ cd lambda-proxy
+$ pip install -U pip
+$ pip install -e .
+```
+
+# Usage
+
+Lambda proxy is designed to work well with both API Gateway's REST API and the
+newer and cheaper HTTP API. If you have issues using with the HTTP API, please
+open an issue.
+
+With GET request
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/tests/<id>', methods=['GET'], cors=True)
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+With POST request
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/tests/<id>', methods=['POST'], cors=True)
+def print_id(id, body):
+ return ('OK', 'plain/text', id)
+```
+
+**Note**
+
+Starting in version 5.2.0, users can now add route using `@APP.get` and `@APP.post` removing the need to add `methods=[**]`
+
+## Binary body
+
+Starting from version 5.0.0, lambda-proxy will decode base64 encoded body on POST message.
+
+Pre 5.0.0
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test', methods=['POST']e)
+def print_id(body):
+ body = json.loads(base64.b64decode(body).decode())
+```
+
+Post 5.0.0
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test', methods=['POST']e)
+def print_id(body):
+ body = json.loads(body)
+```
+
+# Routes
+
+Route schema is simmilar to the one used in [Flask](http://flask.pocoo.org/docs/1.0/api/#url-route-registrations)
+
+> Variable parts in the route can be specified with angular brackets `/user/<username>`. By default a variable part in the URL accepts any string without a slash however a different converter can be specified as well by using `<converter:name>`.
+
+Converters:
+- `int`: integer
+- `string`: string
+- `float`: float number
+- `uuid`: UUID
+
+example:
+- `/app/<user>/<id>` (`user` and `id` are variables)
+- `/app/<string:value>/<float:num>` (`value` will be a string, while `num` will be a float)
+
+## Regex
+You can also add regex parameters descriptions using special converter `regex()`
+
+example:
+```python
+@APP.get("/app/<regex([a-z]+):regularuser>")
+def print_user(regularuser):
+ return ('OK', 'plain/text', f"regular {regularuser}")
+
+@APP.get("/app/<regex([A-Z]+):capitaluser>")
+def print_user(capitaluser):
+ return ('OK', 'plain/text', f"CAPITAL {capitaluser}")
+```
+
+#### Warning
+
+when using **regex()** you must use different variable names or the route might not show up in the documentation.
+
+```python
+@APP.get("/app/<regex([a-z]+):user>")
+def print_user(user):
+ return ('OK', 'plain/text', f"regular {user}")
+
+@APP.get("/app/<regex([A-Z]+):user>")
+def print_user(user):
+ return ('OK', 'plain/text', f"CAPITAL {user}")
+```
+This app will work but the documentation will only show the second route because in `openapi.json`, route names will be `/app/{user}` for both routes.
+
+# Route Options
+
+- **path**: the URL rule as string
+- **methods**: list of HTTP methods allowed, default: ["GET"]
+- **cors**: allow CORS, default: `False`
+- **token**: set `access_token` validation
+- **payload_compression_method**: Enable and select an output body compression
+- **binary_b64encode**: base64 encode the output body (API Gateway)
+- **ttl**: Cache Control setting (Time to Live) **(Deprecated in 6.0.0)**
+- **cache_control**: Cache Control setting
+- **description**: route description (for documentation)
+- **tag**: list of tags (for documentation)
+
+## Cache Control
+
+Add a Cache Control header with a Time to Live (TTL) in seconds.
+
+```python
+from lambda_proxy.proxy import API
+APP = API(app_name="app")
+
+@APP.get('/test/tests/<id>', cors=True, cache_control="public,max-age=3600")
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+Note: If function returns other then "OK", Cache-Control will be set to `no-cache`
+
+## Binary responses
+
+When working with binary on API-Gateway we must return a base64 encoded string
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/test/tests/<filename>.jpg', cors=True, binary_b64encode=True)
+def print_id(filename):
+ with open(f"{filename}.jpg", "rb") as f:
+ return ('OK', 'image/jpeg', f.read())
+```
+
+## Compression
+
+Enable compression if "Accept-Encoding" if found in headers.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get(
+ '/test/tests/<filename>.jpg',
+ cors=True,
+ binary_b64encode=True,
+ payload_compression_method="gzip"
+)
+def print_id(filename):
+ with open(f"{filename}.jpg", "rb") as f:
+ return ('OK', 'image/jpeg', f.read())
+```
+
+## Simple Auth token
+
+Lambda-proxy provide a simple token validation system.
+
+- a "TOKEN" variable must be set in the environment
+- each request must provide a "access_token" params (e.g curl
+ http://myurl/test/tests/myid?access_token=blabla)
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/test/tests/<id>', cors=True, token=True)
+def print_id(id):
+ return ('OK', 'plain/text', id)
+```
+
+## URL schema and request parameters
+
+QueryString parameters are passed as function's options.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get('/<id>', cors=True)
+def print_id(id, name=None):
+ return ('OK', 'plain/text', f"{id}{name}")
+```
+
+requests:
+
+```bash
+$ curl /000001
+ 0001
+
+$ curl /000001?name=vincent
+ 0001vincent
+```
+
+## Multiple Routes
+
+```python
+from lambda_proxy.proxy import API
+APP = API(name="app")
+
+@APP.get('/<id>', cors=True)
+@APP.get('/<id>/<int:number>', cors=True)
+def print_id(id, number=None, name=None):
+ return ('OK', 'plain/text', f"{id}-{name}-{number}")
+```
+requests:
+
+```bash
+
+$ curl /000001
+ 0001--
+
+$ curl /000001?name=vincent
+ 0001-vincent-
+
+$ curl /000001/1?name=vincent
+ 0001-vincent-1
+```
+
+# Advanced features
+
+## Context and Event passing
+
+Pass event and context to the handler function.
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.get("/<id>", cors=True)
+@APP.pass_event
+@APP.pass_context
+def print_id(ctx, evt, id):
+ print(ctx)
+ print(evt)
+ return ('OK', 'plain/text', f"{id}")
+```
+
+# Automatic OpenAPI documentation
+
+By default the APP (`lambda_proxy.proxy.API`) is provided with three (3) routes:
+- `/openapi.json`: print OpenAPI JSON definition
+
+- `/docs`: swagger html UI
+![swagger](https://user-images.githubusercontent.com/10407788/58707335-9cbb0480-8382-11e9-927f-8d992cf2531a.jpg)
+
+- `/redoc`: Redoc html UI
+![redoc](https://user-images.githubusercontent.com/10407788/58707338-9dec3180-8382-11e9-8dec-18173e39258f.jpg)
+
+**Function annotations**
+
+To be able to render full and precise API documentation, lambda_proxy uses python type hint and annotations [link](https://www.python.org/dev/peps/pep-3107/).
+
+```python
+from lambda_proxy.proxy import API
+
+APP = API(name="app")
+
+@APP.route('/test/<int:id>', methods=['GET'], cors=True)
+def print_id(id: int, num: float = 0.2) -> Tuple(str, str, str):
+ return ('OK', 'plain/text', id)
+```
+
+In the example above, our route `/test/<int:id>` define an input `id` to be a `INT`, while we also add this hint to the function `print_id` we also specify the type (and default) of the `num` option.
+
+# Custom Domain and path mapping
+
+Since version 4.1.1, lambda-proxy support custom domain and path mapping (see https://github.com/vincentsarago/lambda-proxy/issues/16).
+
+Note: When using path mapping other than `root` (`/`), `/` route won't be available.
+
+```python
+from lambda_proxy.proxy import API
+
+api = API(name="api", debug=True)
+
+
+# This route won't work when using path mapping
+@api.get("/", cors=True)
+# This route will work only if the path mapping is set to /api
+@api.get("/api", cors=True)
+def index():
+ html = """<!DOCTYPE html>
+ <html>
+ <header><title>This is title</title></header>
+ <body>
+ Hello world
+ </body>
+ </html>"""
+ return ("OK", "text/html", html)
+
+
+@api.get("/yo", cors=True)
+def yo():
+ return ("OK", "text/plain", "YOOOOO")
+```
+
+# Plugin
+
+- Add cache layer: https://github.com/vincentsarago/lambda-proxy-cache
+
+
+# Examples
+
+- https://github.com/vincentsarago/lambda-proxy/tree/master/example
+- https://github.com/RemotePixel/remotepixel-tiler
+
+
+# Contribution & Devellopement
+
+Issues and pull requests are more than welcome.
+
+**Dev install & Pull-Request**
+
+```bash
+$ git clone https://github.com/vincentsarago/lambda-proxy.git
+$ cd lambda-proxy
+$ pip install -e .[dev]
+```
+
+**Python3.7 only**
+
+This repo is set to use pre-commit to run *mypy*, *flake8*, *pydocstring* and *black* ("uncompromising Python code formatter") when committing new code.
+
+```bash
+$ pre-commit install
+$ git add .
+$ git commit -m'my change'
+ black.........................Passed
+ Flake8........................Passed
+ Verifying PEP257 Compliance...Passed
+ mypy..........................Passed
+$ git push origin
+```
+
+### License
+
+See [LICENSE.txt](/LICENSE.txt>).
+
+### Authors
+
+See [AUTHORS.txt](/AUTHORS.txt>).
+
+### Changes
+
+See [CHANGES.txt](/CHANGES.txt>).
+
+%prep
+%autosetup -n lambda-proxy-5.2.1
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-lambda-proxy -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 5.2.1-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..220a7e6
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+ad05428e3cce7620ddeb24f4b1f57099 lambda-proxy-5.2.1.tar.gz