Esempio n. 1
0
def validate_docker_image(*, pk: uuid.UUID, app_label: str, model_name: str):
    model = apps.get_model(app_label=app_label, model_name=model_name)
    instance = model.objects.get(pk=pk)

    if not instance.image:
        if instance.user_upload:
            with transaction.atomic():
                instance.user_upload.copy_object(to_field=instance.image)
                instance.user_upload.delete()
                # Another validation job will be launched to validate this
                return
        else:
            # No image to validate
            return

    try:
        image_sha256 = _validate_docker_image_manifest(instance=instance)
    except ValidationError as e:
        model.objects.filter(pk=instance.pk).update(image_sha256="",
                                                    ready=False,
                                                    status=oxford_comma(e))
        send_invalid_dockerfile_email(container_image=instance)
        return

    push_container_image(instance=instance)
    model.objects.filter(pk=instance.pk).update(image_sha256=image_sha256,
                                                ready=True)
Esempio n. 2
0
 def __init__(self, *args, **kw):
     super().__init__(*args, **kw)
     accept_terms = self.fields["accept_terms"]
     accept_terms.label = accept_terms.label.format(
         oxford_comma([
             f'the <a href="{p.get_absolute_url()}">{p.title}</a>'
             for p in Policy.objects.all()
         ]))
Esempio n. 3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     # mark_safe ok here as we control the policy page titles
     self.fields["accept_terms"].label = mark_safe(
         "I have read and agree to {}.".format(
             oxford_comma([
                 f'the <a href="{p.get_absolute_url()}">{p.title}</a>'
                 for p in Policy.objects.all()
             ])))
Esempio n. 4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper(self)
     self.helper.layout.append(Submit("submit", "Submit"))
     accept_terms = self.fields["accept_terms"]
     accept_terms.label = accept_terms.label.format(
         oxford_comma([
             f'the <a href="{p.get_absolute_url()}">{p.title}</a>'
             for p in Policy.objects.all()
         ]))