Commit bb81cd79 authored by Guilhem Saurel's avatar Guilhem Saurel

show gitlab hooks

parent 92013758
Pipeline #8492 failed with stage
in 40 seconds
......@@ -162,6 +162,7 @@ PRIVATE_REGISTRY = 'gepgitlab.laas.fr:4567'
PUBLIC_REGISTRY = 'memmos.laas.fr:5000'
GITHUB_USER = 'hrp2-14'
GITHUB_WEBHOOK_KEY = os.environ['GITHUB_WEBHOOK_KEY']
GITLAB_WEBHOOK_KEY = os.environ['GITLAB_WEBHOOK_KEY']
AUTHENTICATION_BACKENDS = ["django_auth_ldap.backend.LDAPBackend"]
......
......@@ -6,4 +6,5 @@ from . import views
urlpatterns = [
path('webhook', views.webhook),
path('gl-webhook', views.gl_webhook),
]
......@@ -5,8 +5,6 @@ from ipaddress import ip_address, ip_network
from json import loads
from pprint import pprint
import requests
from autoslug.utils import slugify
from django.conf import settings
from django.http import HttpRequest
from django.http.response import (HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseRedirect,
......@@ -15,6 +13,10 @@ from django.shortcuts import get_object_or_404, reverse
from django.utils.encoding import force_bytes
from django.views.decorators.csrf import csrf_exempt
import requests
from autoslug.utils import slugify
from dashboard.middleware import ip_laas
from rainboard.models import Forge, Namespace, Project
from . import models
......@@ -105,6 +107,13 @@ def push(request: HttpRequest, rep: str) -> HttpResponse:
return HttpResponse(rep)
def pipeline(request: HttpRequest, rep: str) -> HttpResponse:
"""Something happened on a Gitlab pipeline. Tell Github if necessary."""
print('pipeline')
pprint(loads(request.body.decode()))
return HttpResponse(rep)
@csrf_exempt
def webhook(request: HttpRequest) -> HttpResponse:
"""
......@@ -147,3 +156,29 @@ def webhook(request: HttpRequest) -> HttpResponse:
return pull_request(request, 'check_suite event detected')
return HttpResponseForbidden('event not found')
@csrf_exempt
def gl_webhook(request: HttpRequest) -> HttpResponse:
# validate ip source
if not ip_laas(request):
print('not from LAAS IP')
return HttpResponseRedirect(reverse('login'))
# validate token
token = request.META.get('HTTP_X_GITLAB_TOKEN')
if token is None:
print('no token')
return HttpResponseRedirect(reverse('login'))
if token != settings.GITHUB_WEBHOOK_KEY:
print('wrong token')
return HttpResponseForbidden('wrong token.')
event = request.META.get('HTTP_X_GITLAB_EVENT', 'ping')
if event == 'ping':
pprint(loads(request.body.decode()))
return HttpResponse('pong')
if event == 'Pipeline Hook':
return pipeline(request, 'pipeline event detected')
return HttpResponseForbidden('event not found')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment