Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webhooks.verifyAndParse and standalone verifyAndParse method #379

Open
gr2m opened this issue Dec 6, 2020 · 0 comments
Open

webhooks.verifyAndParse and standalone verifyAndParse method #379

gr2m opened this issue Dec 6, 2020 · 0 comments
Labels
Type: Feature New feature or request

Comments

@gr2m
Copy link
Contributor

gr2m commented Dec 6, 2020

What’s missing?

There is currently no simple way to parse and verify an incoming http request object at the same time. It's only possible as part of the event API of a webhooks instance, which might be overkill / not the best fit for a serverless/function environment

This would permit for code such as this:

export async function handler(event) {
  try {    
    const githubEvent = await verifyAndParse(secret, event)
    // handle valid event
    return { body: text, statusCode: 200 };
  } catch (error) {
    // handle errors
    return { body: 'oh noes!', statusCode: 500 }
  }
}

Why?

This is a follow up to #372 (comment), see the discussion for more reasoning.

In a nutshell, @G-Rath's use case is to separate receiving and verifying the event request from running any event handlers to avoid AWS Lambda timeouts.

Alternatives you tried

export async function handler(event) {
  const webhooks = new Webhooks(options)

  webhooks.on(['check_run', 'code_scanning_alert', 'commit_comment'], async (event) => {
    // handle valid events
  })

  try {
    await webhooks.verifyAndReceive(awsEventToOctokitEvent(event))
    return { statusCode: 200 };
  } catch (error) {
    // handle error
    return { body: 'oh noes!', statusCode: 500 }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant