-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add Webhook Utility #12
base: master
Are you sure you want to change the base?
Changes from all commits
f594e7f
5aaac70
94a7f8f
9818911
c3270dd
f67a822
a15643b
8371388
8f81f5d
7332b70
878008a
b55b75e
40c81d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ services: | |
- MYSQL_DATABASE=pesticide_docker | ||
- MYSQL_USER=test_user | ||
- MYSQL_PASSWORD=test_user_password | ||
- MYSQL_ROOT_PASSWORD=ROOT_PASSWORD | ||
- MYSQL_ROOT_PASSWORD= | ||
volumes: | ||
- /home/pesticide-data:/var/lib/mysql | ||
expose: | ||
|
@@ -27,12 +27,15 @@ services: | |
backend: | ||
restart: always | ||
container_name: pesticide_backend | ||
command: bash -c "cd ./src && python check_db.py --service-name db --ip db --port 3306 && python manage.py collectstatic --noinput && python manage.py makemigrations pesticide_app && python manage.py makemigrations && python manage.py migrate && daphne -b 0.0.0.0 -p 8000 pesticide.asgi:application" | ||
command: bash -c "cd ./src && python check_db.py --service-name db --ip db --port 3306 && python manage.py collectstatic --noinput && daphne -b 0.0.0.0 -p 8000 pesticide.asgi:application" | ||
build: | ||
context: ./pesticide_backend/ | ||
dockerfile: Dockerfile | ||
volumes: | ||
- ./pesticide_backend:/backend | ||
- type: bind | ||
source: ./pesticide_backend | ||
target: /backend | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this necessary? |
||
read_only: false | ||
expose: | ||
- "8000" | ||
depends_on: | ||
|
@@ -43,14 +46,16 @@ services: | |
|
||
frontend: | ||
container_name: pesticide_frontend | ||
command: npm run build | ||
command: npm start | ||
build: | ||
context: ./pesticide_frontend/ | ||
dockerfile: Dockerfile | ||
volumes: | ||
- ./pesticide_frontend:/frontend | ||
expose: | ||
- "3000" | ||
ports: | ||
- 3000:3000 | ||
stdin_open: true | ||
depends_on: | ||
- backend | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ upstream redis-server { | |
server backend:8000 fail_timeout=0; | ||
} | ||
|
||
upstream frontend-server { | ||
ip_hash; | ||
server frontend:3000 fail_timeout=0; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just like the docker-compose file, modifications made to this file were only meant for development setup, and are not meant to be committed. |
||
server { | ||
listen 8080; | ||
|
||
|
@@ -44,9 +49,12 @@ server { | |
proxy_no_cache 1; | ||
} | ||
|
||
# location / { | ||
# root /var/www/frontend; | ||
# try_files $uri $uri/ /index.html; | ||
# } | ||
|
||
location / { | ||
root /var/www/frontend; | ||
try_files $uri $uri/ /index.html; | ||
proxy_pass http://frontend-server; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.core.serializers import serialize | ||
from rest_framework import serializers | ||
from pesticide_app.models import WebhookDetails | ||
|
||
class WebhookSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = WebhookDetails | ||
fields = '__all__' | ||
|
||
class WebhookFlaskSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = WebhookDetails | ||
fields = ['name','repository_name','ssh_url','path','secret','branch','identifier'] | ||
|
||
class WebhookDetailsSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = WebhookDetails | ||
fields = ['id','name','repository_name','ssh_url','path','branch','identifier','project','creator','timestamp'] | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 3.1.1 on 2022-02-18 12:58 | ||
|
||
import datetime | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('pesticide_app', '0011_auto_20210105_2148'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='WebhookDetails', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100, unique=True)), | ||
('repository_name', models.CharField(max_length=500)), | ||
('ssh_url', models.CharField(max_length=1000)), | ||
('path', models.CharField(max_length=1000)), | ||
('secret', models.CharField(max_length=1000)), | ||
('branch', models.CharField(max_length=1000)), | ||
('identifier', models.CharField(max_length=100, unique=True)), | ||
('timestamp', models.DateTimeField(blank=True, default=datetime.datetime.now, null=True)), | ||
('creator', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='webhook_creator', to=settings.AUTH_USER_MODEL)), | ||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='webhooks', to='pesticide_app.project')), | ||
], | ||
options={ | ||
'ordering': ['-timestamp'], | ||
}, | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.db import models | ||
from pesticide_app.models.project import Project | ||
from pesticide_app.models.user import User | ||
from datetime import datetime | ||
|
||
class WebhookDetails(models.Model): | ||
|
||
name = models.CharField(max_length=100, unique=True) | ||
repository_name = models.CharField(max_length=500) | ||
ssh_url = models.CharField(max_length=1000) | ||
path = models.CharField(max_length=1000) #wrt omniport codebase | ||
secret = models.CharField(max_length=1000) | ||
branch = models.CharField(max_length=1000) | ||
identifier = models.CharField(max_length=100, unique=True) #used to identify webhook url | ||
project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='webhooks') | ||
creator = models.ForeignKey(User, null=True, on_delete=models.CASCADE, related_name='webhook_creator') | ||
timestamp = models.DateTimeField(default=datetime.now, blank=True, null=True) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta: | ||
ordering = ['-timestamp'] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from rest_framework import viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
from pesticide_app.permissions import ProjectMemberOrAdmin | ||
from rest_framework.authentication import SessionAuthentication | ||
from pesticide_app.api.serializers import WebhookSerializer | ||
from pesticide_app.models import WebhookDetails | ||
|
||
|
||
class WebhookViewSet(viewsets.ModelViewSet): | ||
serializer_class = WebhookSerializer | ||
queryset = WebhookDetails.objects.all() | ||
permission_classes = [IsAuthenticated & ProjectMemberOrAdmin ] | ||
authentication_classes = [SessionAuthentication, ] | ||
|
||
def perform_create(self,serializer): | ||
serializer.save(creator = self.request.user) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
from rest_framework.permissions import IsAuthenticated | ||
from pesticide_app.permissions import ReadOnlyPermissions | ||
from rest_framework.authentication import SessionAuthentication | ||
from pesticide_app.api.serializers import WebhookDetailsSerializer | ||
from pesticide_app.models import Project | ||
|
||
|
||
class WebhookDetailsView(APIView): | ||
permission_classes = [IsAuthenticated & ReadOnlyPermissions] | ||
authentication_classes = [SessionAuthentication, ] | ||
|
||
def get(self, request, pk, format = None): | ||
project = Project.objects.get(id=pk) | ||
webhook_data = WebhookDetailsSerializer(project.webhooks.all(),many=True) | ||
return Response(webhook_data.data) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.http import HttpResponse | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused imports. |
||
from django.forms.models import model_to_dict | ||
from django.http import JsonResponse | ||
from rest_framework.views import APIView | ||
from pesticide_app.models import WebhookDetails | ||
from pesticide_app.permissions import IsFlaskRequest | ||
|
||
class WebhookFlaskView(APIView): | ||
permission_classes = [IsFlaskRequest] | ||
|
||
def get(self, request, pk, format=None): | ||
try: | ||
webhook = WebhookDetails.objects.get(identifier = pk) | ||
return JsonResponse(model_to_dict(webhook)) | ||
except: | ||
return HttpResponse("No matching query") | ||
|
||
def get_permissions(self): | ||
if self.request.method == 'GET': | ||
self.permission_classes = [IsFlaskRequest] | ||
return super(WebhookFlaskView, self).get_permissions() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ FROM node:10.18-alpine | |
WORKDIR /frontend | ||
COPY package.json package-lock.json ./ | ||
RUN npm install | ||
RUN npm install [email protected] -g | ||
# RUN npm install [email protected] -g | ||
COPY . ./ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not commit this modified docker-compose file. The modifications made were only for easy development, and cannot be used in a production setup.