Giter Site home page Giter Site logo

flask-githubapp's Introduction

Hi there ๐Ÿ‘‹

flask-githubapp's People

Contributors

bradshjg avatar napo2k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flask-githubapp's Issues

Add custom routes?

Is it possible to add custom routes? I want to display a message when a GET request is sent to the root URL /. I also want to add a healthcheck at /health for kubernetes usage. I can't figure out how to do this right now.

Application object must be callable

Trying to use gunicorn with this, i found that it doesn't boot, with the message "Application object must be callable." Is this a known issue after running GitHubApp(app)?

Support AWS Lambda Deployment

While it's not too difficult to wrap the app in https://github.com/slank/awsgi or similar for Lambda deployment, first-class support could be handy...especially docs/tooling (hopefully very thin tooling) to support deployment.

The API should be GitHubApp.lambda_handler(event, context) and should probably return the same (un-jsonify-ed) response.

  • Should not break backwards compatibility
  • Unmodified applications should be deployable, but this is a soft requirements
  • Tooling should be able to package projects for AWS Lambda that employ a requirements.txt file with only pure-Python package. Anything beyond that gets messy very quickly.

Edit: Now I'm not sure if the api should be public...it doesn't really need to be ๐Ÿ˜• ...ohhhh and I'm also completely ignoring secrets management. I don't want to have an opinion on it...but for non-sensitive apps a GUI walkthrough using Lambda env vars should be pretty straightforward. Folks can handle it however they want outside that.

127.0.0.1 - - [12/Dec/2021 00:39:05] "POST / HTTP/1.1" 400 -

https://github.com/bradshjg/flask-githubapp/blob/master/samples/cruel_closer/app.py with smee.io

S:\Projects\Python\github-bot-flask\venv\Scripts\python.exe S:/Projects/Python/github-bot-flask/app.py
 * Serving Flask app 'app' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on http://10.0.1.10:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [12/Dec/2021 00:39:05] "POST / HTTP/1.1" 400 -
127.0.0.1 - - [12/Dec/2021 00:39:05] "POST / HTTP/1.1" 400 -

Errors running locally

Hello!

I am trying to use this to - duh - set up a github app. I have gotten, I believe, all the details related to app id, signature, key, etc.
I have a bunch of prepared payloads from git to test, and I have the app running as flask locally as per your README
However when I send one of the requests:

STOLTM6653 เฅ  ~/Work/gitbot: git@master! [08:46:08] ยฑ curl -H "X-GitHub-Event: push" -H "Content-Type: application/json" -X POST -d @./zzpayloads/master_push.json localhost:5000           โœน โœญ
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

and the output from the flask server process is:

Traceback (most recent call last):
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask_githubapp/core.py", line 172, in _flask_view_func
    self._verify_webhook()
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/flask_githubapp/core.py", line 192, in _verify_webhook
    signature = request.headers['X-Hub-Signature'].split('=')[1]
  File "/Users/nachofernandez/Work/gitbot/.env/lib/python3.9/site-packages/werkzeug/datastructures.py", line 1463, in __getitem__
    return _unicodify_header_value(self.environ["HTTP_" + key])
KeyError: 'HTTP_X_HUB_SIGNATURE'

I have checked the git payloads in the webhook I am trying to put this github app on, and I don't see any X-Hub-Signature headers. I see headers like:

Request URL: 
Request method: POST
content-type: application/json
Expect: 
User-Agent: GitHub-Hookshot/b56da86
X-GitHub-Delivery: <some-guid>
X-GitHub-Enterprise-Host: <host>
X-GitHub-Enterprise-Version: 2.22.5
X-GitHub-Event: pull_request

The payload itself is a full push payload - in any case my code doesn't do anything with it just yet. Is this a problem on my end, is it that I am using a wrong flask-githubapp version (I am on flask 1.1.2 and flask-githubapp 0.2.0)?

Allow Returning Response from Hook Request

Currently no matter what the hook function returns, a 200 response with the body "OK" is returned by the server.

...but what do we return if multiple hook functions are run ๐Ÿ˜ข ?

Maybe

{
  "some_function": "some_function response",
  "some_other_function": "some_other_function response"
}

No X-Hub-Signature header with GitHub Enterprise

Hi,

I wanted to use your cool library, however it fais on _verify_webhook as the X-Hub-Signature header is not present in the payload.

What could we do to remediate this, I would not want to clone / modify the code, ideally

Create Tests

  • test against multiple python versions
  • wire up testing to travis

Add Logging

Need much better logging in order to see where any failures are happening.

Support X-Hub-Signature-256

We should prefer this header and probably fall back to the X-Hub-Signature header in the case that it's missing (in the case of maybe old Enterprise Server installations???)

I'm also a little conflicted about the current practice of requiring a secret to be set. I think there are probably legitimate use cases where a secret isn't needed and it makes some approaches to local dev and testing a bit more complicated. For now let's provide an interface to opt-out and give a more kind error message (right now I'm pretty sure we throw a relatively opaque KeyError ๐Ÿ˜ž) in the case that the user has not opted out and the header is missing.

Exception on / [POST]

I'm getting some some errors and I'm not really sure where they're coming from or how to debug. Is this a lib issue or an issue with my setup?

Traceback (most recent call last):
  File "/app/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/app/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/app/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/app/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/app/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/app/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/site-packages/flask_githubapp/core.py", line 169, in _flask_view_func
    event = request.headers['X-GitHub-Event']
  File "/app/site-packages/werkzeug/datastructures.py", line 1463, in __getitem__
    return _unicodify_header_value(self.environ["HTTP_" + key])
KeyError: 'HTTP_X_GITHUB_EVENT'

How to set environment variables

Hello,
How can i setup the env variables in order to run the code that you present? I'm talking about the tree you mentioned: GITHUBAPP_ID, GITHUBAPP_KEY_PATH, and GITHUBAPP_SECRET.

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.