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

added support for authenticating updates from github #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions cinch/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import logging
from flask import request
from flask import abort, request
from github import Github, UnknownObjectException

from cinch import app, models
Expand Down Expand Up @@ -55,8 +55,6 @@ def _handle_pull_request(self, pull_request_data):

pull.head_commit = commit.sha



models.db.session.commit()

def _handle_master_update(self):
Expand Down Expand Up @@ -163,7 +161,9 @@ def update_pull_data(self, pull, data):
def accept_github_update():
""" View for github web hooks to handle updates
"""
# TODO: verify request is from github
update_secret = app.config.get('GITHUB_UPDATE_SECRET')
if update_secret and request.args.get('secret') != update_secret:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to be paranoid we could use werkzeug.security.safe_str_cmp: ("This function compares strings in somewhat constant time.")

abort(401)

github_token = app.config.get('GITHUB_TOKEN')
gh = Github(github_token)
Expand Down
4 changes: 4 additions & 0 deletions setup_env.sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ export CINCH_SENTRY_DSN=

# A sqlalchemy parseable database identifier
export CINCH_DB_URI=

# For authenticating updates sent from github.
# This must be included in the callback url under the param `secret`
export CINCH_GITHUB_UPDATE_SECRET=