|
14 | 14 |
|
15 | 15 | from celery.canvas import group |
16 | 16 | from django.conf import settings |
| 17 | +from django.contrib.auth.models import User |
17 | 18 | from django.db import models |
18 | 19 | from django.db.models.signals import post_save |
19 | 20 | from django.dispatch import receiver |
@@ -682,6 +683,41 @@ class Meta: |
682 | 683 | def __str__(self): |
683 | 684 | return '{0}-v{1}'.format(self.formation.id, self.version) |
684 | 685 |
|
| 686 | + @classmethod |
| 687 | + def push(cls, push): |
| 688 | + """ |
| 689 | + Process a push from a local Git server |
| 690 | +
|
| 691 | + Creates a new Build and returns the formation's |
| 692 | + databag for processing by the git-receive hook |
| 693 | + """ |
| 694 | + # SECURITY: |
| 695 | + # we assume the first part of the ssh key name |
| 696 | + # is the authenticated user because we trust gitosis |
| 697 | + username = push.pop('ssh_key').split('_')[0] |
| 698 | + # retrieve the user and formation instances |
| 699 | + user = User.objects.get(username=username) |
| 700 | + formation = Formation.objects.get(owner=push['owner'], |
| 701 | + id=push.pop('formation')) |
| 702 | + # merge the push with the required model instances |
| 703 | + push['owner'] = user |
| 704 | + push['formation'] = formation |
| 705 | + # create the build |
| 706 | + new_build = cls.objects.create(**push) |
| 707 | + # send a release signal |
| 708 | + release_signal.send(sender=push, build=new_build, |
| 709 | + formation=formation, |
| 710 | + user=user) |
| 711 | + # recalculate the formation databag including the new |
| 712 | + # build and release |
| 713 | + databag = formation.calculate() |
| 714 | + # if enabled, force-converge all of the chef nodes |
| 715 | + if settings.CONVERGE_ON_PUSH is True: |
| 716 | + formation.converge(databag) |
| 717 | + # return the databag object so the git-receive hook |
| 718 | + # can tell the user about proxy URLs, etc. |
| 719 | + return databag |
| 720 | + |
685 | 721 |
|
686 | 722 | @python_2_unicode_compatible |
687 | 723 | class Release(UuidAuditedModel): |
|
0 commit comments