Giter VIP home page Giter VIP logo

codehook's Introduction

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

codehook

Webhook logic and infrastructure automated
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

There are many ways to extend the capabilities of your favourite SaaS tools, and webhooks are my favourite. Webhooks are the foundation of modern API development. They enable us to react to changes in our systems, an incoming text message, a successful payment, or that latest pull request no matter our stack. 1

During my time in Stripe, I found that some users were confortable in getting a handler up and running in 30 minutes, others had to navigate weeks of company approvals to get the infrastructure to run one, and others simply did not know what to do. [2](user survey)

I think this tool will make webhooks easy for everyone, once and for all. Here's why:

  • Your time should be focused on creating something amazing, and truly unique business logic. The infra to do it isn't unique
  • You shouldn't be doing the same tasks over and over like creating a webhook boilerplate from scratch
  • You should be able to run your code in your environments when you have control over then
  • You shouldn't be blocked from running your code elsewhere if you want because of company buorocracy

Codehook aims to help you all of the above: an open source tool to help you build, test, deploy and host (optionally) webhook handlers 🚀

(back to top)

Built With

Python Typer AWS Ruff

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

Codehook is a Python project that relies heavily on Typer and Boto3, with a few additional dependencies.

Installing Python is generally easy, and nowadays many Linux and UNIX distributions include a recent Python. If you do need to install Python and aren't confident about the task you can find a few notes on the BeginnersGuide/Download wiki page, but installation is unremarkable on most platforms.

Configuration

  1. Get an AWS API Key at https://example.com
  2. Get the API Key for your source system, such as Stripe.
  3. Make sure to set the following environment variables:
  AWS_ACCESS_KEY_ID=
  AWS_SECRET_ACCESS_KEY=
  STRIPE_API_KEY=

(back to top)

Usage

The simplest case

Create a file named handler.py with the following content:

def handler_logic(body):
    return (200, "Hello, codehook!")

Run the codehook CLI

foo@bar:~$ codehook deploy --file handler.py

The end of the response will contain information about the endpoint:

Deployment complete 🚀
Function name: handler
API ID: 123456789
Webhook URL: https:/123456789.execute-api.us-east-1.amazonaws.com/prod/codehook
Webhook ID: we_abcdefghijkl

Make a POST request to the endpoint that was just created

foo@bar:~$ curl -X PUT https://123456789.execute-api.us-east-1.amazonaws.com/prod/codehook | json_pp

The body of your response should a tuple containing:

{
  "body" : "Handler logic skeleton",
  "status_code" : 200
}

Congratulations! You just deployed a live webhook endpoint 🎉

You can clean up by running

foo@bar:~$ codehook delete --all

A slightly more complex example

Your function handler receives a body parameter from the webhook event. For this example, create a file named echo.py with the following content:

def handler_logic(body):
    return (200, body)

Run the codehook CLI. You can specify a function name, and the source for the event. Currently codehook supports Stripe webhook events.

codehook deploy --file echo.py --name echo_function --source stripe --enabled-events '*'

Make a POST request to the endpoint that was just created, and pass a request body this time:

foo@bar:~$ curl -X PUT -H "Content-Type: application/json" -d '{"hello":"codehook"}' \
  https://123456789.execute-api.us-east-1.amazonaws.com/prod/codehook | json_pp

The body of your response this time should echo back what you sent:

{
  "body" : "{\"hello\":\"codehook\"}",
  "status_code" : 200
}

You can also delete your resources one by one by running

foo@bar:~$ codehook delete --lambda-function-name echo_function --api-id 123456789

For more examples, please refer to the Documentation

(back to top)

Roadmap

  • Support for additional event sources
  • Improve code generation capability
  • Support for additional cloud providers

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please clone the repo, start a new branch, and create a pull request. You can also simply open an issue with the tag "enhancement". And don't forget to give the project a star!

  1. Clone the Project
  git clone https://github.com/edujanicas/codehook.git
  1. Create your Feature Branch
  git checkout -b feature/AmazingFeature
  1. Install all the dependencies (Using poetry)
  poetry install
  1. Copy .env.example into a .env file and fill in your API Keys
  cp .env.example .env
  1. Run the CLI locally
  poetry run codehook [COMMAND]
  1. Commit your Changes
  git commit -m 'Add some AmazingFeature'
  1. Push to the Branch
  git push origin feature/AmazingFeature
  1. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Eduardo Janicas - [email protected]

Project Link: https://github.com/edujanicas/codehook

(back to top)

Acknowledgments

(back to top)

codehook's People

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

canerberk

codehook's Issues

Create deployer

CLI tool
Takes lambda function
Deploys behind API Gateway
Return URL

Generate function code based on command

Is your feature request related to a problem? Please describe.
Generic boilerplates are no longer needed when an LLM can get pretty close to the logic you ask it to do. What if we can bootstrap something really close to the whole webhook logic?

Describe the solution you'd like
Make use of OpenAI's ChatCompletions to generate Python code that gets fed into the webhook handler
https://platform.openai.com/docs/quickstart?context=python

Describe alternatives you've considered
Just generate code vs generate and deploy. Ideally the latter

Handle Delete REST API call TooManyRequests Gracefully

Describe the bug
When calling DeleteRestAPI, codehook consistently gets
An error occurred (TooManyRequestsException) when calling the DeleteRestApi operation (reached max retries: 4): Too Many Requests back

To Reproduce
Create 2 codehook functions and try to delete --all

Expected behavior
Gracefully retry the deletion 30 seconds after (AWS throttles to 1 requests every 30 seconds)

Setup CI/CD pipeline

Is your feature request related to a problem? Please describe.
Currently we need to manually lint and test the repo before each commit. Ideally, this will all be done automatically.

Describe the solution you'd like
GitHub actions pipeline to lint and test each commit, test PRs extensively, and publish releases.

Add support for additional sources

Is your feature request related to a problem? Please describe.
Currently codehook only supports Stripe webhook events. Ideally we want to launch with support for 3 popular different sources.

Describe the solution you'd like
Under codehook/skeletons lies the handler for different types of event sources. Under codehook/sources/ lives the deployer for each to create a webhook endpoint in each. Add support for Shopify and Slack, as a starter.

Describe alternatives you've considered
https://webhooks.fyi/docs/webhook-directory

Create deployment packages that include dependencies

Is your feature request related to a problem? Please describe.
Currently, the function being deployed only supports the standard library. Support for extra libraries requires separate Lambda Layers to be deployed.

Describe the solution you'd like
Include all .requirements.txt dependencies in the .zip deployment package generated by the Lambda module.
https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-create-dependencies

Describe alternatives you've considered
Deploying the function as a container image. Although eventually this might be useful to support additional providers, I believe at the moment it is an overkill.

Add a complete list of Stripe events

Is your feature request related to a problem? Please describe.
Currently codehook handlers will subscribe to all Stripe events. To avoid noise, handlers need to be able to only select a subset

Describe the solution you'd like
Use the Events enum to list all different event types

Improve test coverage

Is your feature request related to a problem? Please describe.
We only have one test at the moment. We need much higher test coverage.

Describe the solution you'd like
Improve test coverage to test each command independently, alongside error cases

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.