VirusTotalNet icon indicating copy to clipboard operation
VirusTotalNet copied to clipboard

Add raw body support to python3 templates

Open viveksyngh opened this issue 5 years ago • 4 comments

Signed-off-by: Vivek Singh [email protected]

Description

Motivation and Context

  • [ ] I have raised an issue to propose this change (required)

Which issue(s) this PR fixes

Fixes #

How Has This Been Tested?

This has been tested on my local with kind

faas-cli invoke raw-body-test <<< "Hello"
Handling connection for 8080
Hello

<class 'str'>
➜  templates git:(raw_body) ✗ faas-cli deploy -f raw-body-test.yml --env=RAW_BODY=True
Deploying: raw-body-test.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
Handling connection for 8080

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/raw-body-test

➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-test <<< "Hello"               
Handling connection for 8080
Hello

<class 'str'>
➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-test <<< "Hello"
Handling connection for 8080
b'Hello\n'
<class 'bytes'>
➜  templates git:(raw_body) ✗ faas-cli deploy -f raw-body-debian.yml   
Deploying: raw-body-debian.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
Handling connection for 8080

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/raw-body-debian

➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-debian <<< "Hello"
Handling connection for 8080
Hello

<class 'str'>
➜  templates git:(raw_body) ✗ faas-cli deploy -f raw-body-debian.yml --env=RAW_BODY=True
Deploying: raw-body-debian.
WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.
Handling connection for 8080

Deployed. 202 Accepted.
URL: http://127.0.0.1:8080/function/raw-body-debian

➜  templates git:(raw_body) ✗ faas-cli invoke raw-body-debian <<< "Hello"               
Handling connection for 8080
b'Hello\n'
<class 'bytes'>

Types of changes

  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Version change (see: Impact to existing users)

Impact to existing users

Checklist:

  • [x] My code follows the code style of this project.
  • [ ] My change requires a change to the documentation.
  • [ ] I have updated the documentation accordingly.
  • [x] I've read the CONTRIBUTION guide
  • [x] I have signed-off my commits with git commit -s
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

viveksyngh avatar Jun 10 '20 17:06 viveksyngh

Thanks for the PR. Just bear in mind to fill out the template i.e. How Has This Been Tested?

alexellis avatar Jun 10 '20 18:06 alexellis

Need to cross reference with https://github.com/openfaas-incubator/python-flask-template/pull/38

alexellis avatar Jul 07 '20 19:07 alexellis

Need to cross reference with openfaas-incubator/python-flask-template#38

This has been handled within is_val function.

viveksyngh avatar Jul 08 '20 04:07 viveksyngh

Hi @alexellis, @viveksyngh

Sorry to hijack this PR, but I opened a similar, but more extensive issue (#205) in May. In it, I proposed opening a PR with my tried-and-tested solution, but since I got no response on the issue, I didn't at the time. I've now created it as #217.

Imho, my solution is less hackish, as it parses standard headers and doesn't require environment variable definition. It also is more extensive in functionality.

I'd be happy to propose similar changes to the flask templates (actually have those running privately too).

jpauwels avatar Sep 18 '20 11:09 jpauwels