adding an endpoint for receiving builder posts (bug 657052)

This commit is contained in:
Jeff Balogh 2011-05-16 17:07:57 -07:00
Родитель 173107306d
Коммит b80c6b0938
5 изменённых файлов: 50 добавлений и 2 удалений

Просмотреть файл

@ -37,3 +37,8 @@ def migrate_jetpack_versions(ids, **kw):
task_log.info('Setting jetpack version to %s for File %s.' %
(file_.jetpack_version, file_.id))
file_.save()
@task
def repackage_jetpack(builder_data, **kw):
task_log.info('[1@None] Repackaging jetpack for %s.' % builder_data['id'])

Просмотреть файл

@ -382,3 +382,27 @@ class TestDiffViewer(FilesBase, test_utils.TestCase):
node = doc('#content-wrapper a')
eq_(len(node), 2)
assert node[0].text.startswith('Download ar.dic')
class TestBuilderPingback(test_utils.TestCase):
def post(self, data):
return self.client.post(reverse('files.builder-pingback'), data,
content_type='application/json')
def test_success(self):
r = self.post(json.dumps({'id': 1,
'secret': settings.BUILDER_SECRET_KEY}))
eq_(r.status_code, 200)
def test_no_secret(self):
r = self.post(json.dumps({'id': 1}))
eq_(r.status_code, 400)
def test_bad_json(self):
r = self.post('wut')
eq_(r.status_code, 400)
def test_no_id(self):
r = self.post({'wut': 1})
eq_(r.status_code, 400)

Просмотреть файл

@ -21,4 +21,6 @@ urlpatterns = patterns('',
('^browse/(?P<file_id>\d+)/', include(file_patterns)),
('^compare/(?P<one_id>\d+)\.{3}(?P<two_id>\d+)/',
include(compare_patterns)),
url('^builder-pingback', views.builder_pingback,
name='files.builder-pingback'),
)

Просмотреть файл

@ -1,20 +1,22 @@
import hashlib
import json
from django import http
from django.conf import settings
from django.utils.http import http_date
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
import commonware.log
import jingo
import waffle
from access import acl
from amo.decorators import json_view
from amo.decorators import json_view, post_required
from amo.urlresolvers import reverse
from amo.utils import HttpResponseSendFile, Message, Token
from files.decorators import file_view, compare_file_view, file_view_token
from files.tasks import extract_file
from files.tasks import extract_file, repackage_jetpack
from tower import ugettext as _
@ -157,3 +159,16 @@ def serve(request, viewer, key):
raise http.Http404()
return HttpResponseSendFile(request, obj['full'],
content_type=obj['mimetype'])
@csrf_exempt
@post_required
def builder_pingback(request):
try:
data = json.loads(request.raw_post_data)
data['id'] # Ensure id is available.
assert data.get('secret') == settings.BUILDER_SECRET_KEY
except Exception:
return http.HttpResponseBadRequest()
repackage_jetpack(data)
return http.HttpResponse()

Просмотреть файл

@ -932,3 +932,5 @@ VALID_LOGIN_REDIRECTS = {
'builderstage': 'https://builder-addons-next.allizom.org',
'buildertrunk': 'https://builder-addons.allizom.org',
}
BUILDER_SECRET_KEY = 'love will tear us apart'