This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
little improvements on slack/taiga/trello/dockerfile
- Loading branch information
FoxMaSk
committed
Dec 10, 2016
1 parent
af61f14
commit 0a6e761
Showing
13 changed files
with
210 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
FROM python:3.5 | ||
MAINTAINER FoxMaSk <foxmask@trigger-happy.eu> | ||
ENV PYTHONUNBUFFERED 1 | ||
RUN mkdir /app | ||
WORKDIR /app | ||
ADD requirements.txt /app/ | ||
COPY requirements-docker.txt /app/ | ||
RUN pip install -r requirements-docker.txt && groupadd -r django && useradd -r -g django django | ||
COPY . /app/ | ||
RUN chown -R django /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
psycopg2 | ||
awesome-slugify==1.6.5 | ||
arrow==0.8.0 | ||
arrow==0.10.0 | ||
djangorestframework==3.5.3 | ||
Django==1.8.17 | ||
django-formtools==1.0 | ||
django-js-reverse==0.7.2 | ||
django-redis==4.6.0 | ||
evernote3 | ||
feedparser==5.2.1 | ||
github3.py==1.0.0a4 | ||
pocket==0.3.6 | ||
py-trello==0.6.1 | ||
pytidylib==0.3.1 | ||
py-trello==0.7.0 | ||
pytz==2016.7 | ||
pytidylib==0.3.2 | ||
pypandoc==1.3.3 | ||
requests-oauthlib==0.7.0 | ||
twython==3.4.0 | ||
wallabag_api==1.1.0 | ||
flake8==3.0.4 | ||
flake8==3.2.1 | ||
todoist-python==7.0.13 | ||
pushbullet.py==0.10.0 | ||
instapush==0.1.2 | ||
djangorestframework | ||
Django==1.8.16 | ||
python-taiga==0.8.6 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
import hmac | ||
import hashlib | ||
|
||
from rest_framework.response import Response | ||
from rest_framework.decorators import api_view | ||
|
||
from django_th.models import TriggerService | ||
from django_th.services import default_provider | ||
|
||
from th_taiga.models import Taiga | ||
|
||
|
||
def epic(taiga_obj, action, data): | ||
""" | ||
:param taiga_obj: taiga object | ||
:param action: craete/change/delete | ||
:param data: data to return | ||
:return: data | ||
""" | ||
if action == 'create' and taiga_obj.notify_epic_create: | ||
data['type_action'] = 'New Epic created' | ||
elif action == 'change' and taiga_obj.notify_epic_change: | ||
data['type_action'] = 'Changed Epic' | ||
elif action == 'delete' and taiga_obj.notify_epic_delete: | ||
data['type_action'] = 'Deleted Epic' | ||
return data | ||
|
||
|
||
def issue(taiga_obj, action, data): | ||
""" | ||
:param taiga_obj: taiga object | ||
:param action: craete/change/delete | ||
:param data: data to return | ||
:return: data | ||
""" | ||
if action == 'create' and taiga_obj.notify_issue_create: | ||
data['type_action'] = 'New Issue created' | ||
elif action == 'change' and taiga_obj.notify_issue_change: | ||
data['type_action'] = 'Changed Issue' | ||
elif action == 'delete' and taiga_obj.notify_issue_delete: | ||
data['type_action'] = 'Deleted Issue' | ||
return data | ||
|
||
|
||
def userstory(taiga_obj, action, data): | ||
""" | ||
:param taiga_obj: taiga object | ||
:param action: craete/change/delete | ||
:param data: data to return | ||
:return: data | ||
""" | ||
if action == 'create' and taiga_obj.notify_userstory_create: | ||
data['type_action'] = 'New Userstory created' | ||
elif action == 'change' and taiga_obj.notify_userstory_change: | ||
data['type_action'] = 'Changed Userstory' | ||
elif action == 'delete' and taiga_obj.notify_userstory_delete: | ||
data['type_action'] = 'Deleted Userstory' | ||
return data | ||
|
||
|
||
def task(taiga_obj, action, data): | ||
""" | ||
:param taiga_obj: taiga object | ||
:param action: craete/change/delete | ||
:param data: data to return | ||
:return: data | ||
""" | ||
if action == 'create' and taiga_obj.notify_task_create: | ||
data['type_action'] = 'New Task created' | ||
elif action == 'change' and taiga_obj.notify_task_change: | ||
data['type_action'] = 'Changed Task' | ||
elif action == 'delete' and taiga_obj.notify_task_delete: | ||
data['type_action'] = 'Deleted Task' | ||
return data | ||
|
||
|
||
def wikipage(taiga_obj, action, data): | ||
""" | ||
:param taiga_obj: taiga object | ||
:param action: craete/change/delete | ||
:param data: data to return | ||
:return: data | ||
""" | ||
if action == 'create' and taiga_obj.notify_wikipage_create: | ||
data['type_action'] = 'New Wikipage created' | ||
elif action == 'change' and taiga_obj.notify_wikipage_change: | ||
data['type_action'] = 'Changed Wikipage' | ||
elif action == 'delete' and taiga_obj.notify_wikipage_delete: | ||
data['type_action'] = 'Deleted Wikipage' | ||
return data | ||
|
||
|
||
def relateduserstory(taiga_obj, action, data): | ||
""" | ||
:param taiga_obj: taiga object | ||
:param action: craete/change/delete | ||
:param data: data to return | ||
:return: data | ||
""" | ||
if action == 'create' and taiga_obj.notify_relateduserstory_create: | ||
data['type_action'] = 'New Related Userstory created' | ||
elif action == 'delete' and taiga_obj.notify_relateduserstory_delete: | ||
data['type_action'] = 'Deleted Related Userstory' | ||
return data | ||
|
||
|
||
def data_filter(trigger_id, **data): | ||
""" | ||
check if we want to track event for a given action | ||
:param trigger_id: | ||
:param data: | ||
:return: | ||
""" | ||
taiga_obj = Taiga.objects.get(trigger_id=trigger_id) | ||
|
||
action = data.get('action') | ||
domain = data.get('type') | ||
data = data.get('data') | ||
|
||
if domain == 'epic': | ||
data = epic(taiga_obj, action, data) | ||
elif domain == 'issue': | ||
data = issue(taiga_obj, action, data) | ||
elif domain == 'userstory': | ||
data = userstory(taiga_obj, action, data) | ||
elif domain == 'task': | ||
data = task(taiga_obj, action, data) | ||
elif domain == 'wikipage': | ||
data = wikipage(taiga_obj, action, data) | ||
elif domain == 'relateduserstory': | ||
data = relateduserstory(taiga_obj, action, data) | ||
else: | ||
data = [] | ||
|
||
return data | ||
|
||
|
||
def consumer(trigger_id, data): | ||
""" | ||
call the consumer and handle the data | ||
:param trigger_id: | ||
:param data: | ||
:return: | ||
""" | ||
status = True | ||
# consumer - the service which uses the data | ||
default_provider.load_services() | ||
service = TriggerService.objects.get(id=trigger_id) | ||
|
||
service_consumer = default_provider.get_service( | ||
str(service.consumer.name.name)) | ||
kwargs = {'user': service.user} | ||
|
||
data = data_filter(trigger_id, **data) | ||
if len(data) > 0: | ||
|
||
getattr(service_consumer, '__init__')(service.consumer.token, | ||
**kwargs) | ||
status = getattr(service_consumer, 'save_data')(service.id, **data) | ||
|
||
return status | ||
|
||
|
||
def verify_signature(data, key, signature): | ||
mac = hmac.new(key.encode("utf-8"), msg=data, digestmod=hashlib.sha1) | ||
return mac.hexdigest() == signature | ||
|
||
|
||
@api_view(['POST']) | ||
def taiga(request, trigger_id, key): | ||
signature = request.META.get('HTTP_X_TAIGA_WEBHOOK_SIGNATURE') | ||
# check that the data are ok with the provided signature | ||
if verify_signature(request._request.body, key, signature): | ||
status = consumer(trigger_id, request.data) | ||
if status: | ||
return Response({"message": "Success"}) | ||
else: | ||
return Response({"message": "Failed!"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.