Exemplo n.º 1
0
def key_delete(request, key_fingerprint):
    key = gpgutils.get_gpg_key(key_fingerprint)
    if not key:
        raise Http404(
            _(
                "GPG key with fingerprint %(fingerprint)s does not exist."
                % {"fingerprint": key_fingerprint}
            )
        )
    result = gpgutils.delete_gpg_key(key_fingerprint)
    if result is True:
        messages.success(
            request,
            _(
                "GPG key %(fingerprint)s successfully deleted."
                % {"fingerprint": key_fingerprint}
            ),
        )
    else:
        messages.warning(
            request,
            _(
                "Failed to delete GPG key %(fingerprint)s."
                % {"fingerprint": key_fingerprint}
            ),
        )
    next_url = request.GET.get("next", reverse("key_list"))
    return redirect(next_url)
Exemplo n.º 2
0
def get_child_space_value(value, field, child):
    """If the child space ``child`` is a GPG instance, and the field is key, we
    return a human-readable representation of the GPG key instead of its
    fingerprint: the name of the first user in its uids list.
    """
    if field == 'key' and isinstance(child, GPG):
        key = gpgutils.get_gpg_key(value)
        return ' '.join(key['uids'][0].split()[:-1])
    return value
Exemplo n.º 3
0
def key_delete_context(request, key_fingerprint):
    key = gpgutils.get_gpg_key(key_fingerprint)
    if not key:
        raise Http404(
            _(
                "GPG key with fingerprint %(fingerprint)s does not exist."
                % {"fingerprint": key_fingerprint}
            )
        )
    header = _(
        "Confirm deleting GPG key %(uids)s (%(fingerprint)s)"
        % {"uids": ", ".join(key["uids"]), "fingerprint": key_fingerprint}
    )
    prompt = ""
    dependent_objects = GPG.objects.filter(key=key_fingerprint)
    if dependent_objects:
        messages.error(
            request,
            _(
                "GPG key %(fingerprint)s cannot be deleted because at least"
                " one GPG Space is using it for encryption."
                % {"fingerprint": key_fingerprint}
            ),
        )
    else:
        LOGGER.debug("No dependent GPG spaces")
        dependent_objects = Package.objects.filter(
            encryption_key_fingerprint=key_fingerprint
        ).exclude(status=Package.DELETED)
        if dependent_objects:
            LOGGER.debug("HAVE dependent packages")
            messages.error(
                request,
                _(
                    "GPG key %(fingerprint)s cannot be deleted because at least"
                    " one package (AIP, transfer) needs it in order to be"
                    " decrypted." % {"fingerprint": key_fingerprint}
                ),
            )
        else:
            LOGGER.debug("No dependent packages")
            prompt = _(
                "Are you sure you want to delete GPG key"
                " %(fingerprint)s?" % {"fingerprint": key_fingerprint}
            )
    default_cancel = reverse("key_list")
    cancel_url = request.GET.get("next", default_cancel)
    context_dict = {
        "header": header,
        "dependent_objects": dependent_objects,
        "prompt": prompt,
        "cancel_url": cancel_url,
    }
    return RequestContext(request, context_dict)
Exemplo n.º 4
0
def key_detail(request, key_fingerprint):
    """View details (including ASCII armor) of GPG key with fingerprint
    ``key_fingerprint``.
    """
    key = gpgutils.get_gpg_key(key_fingerprint)
    if not key:
        raise Http404(
            _('GPG key with fingerprint %(fingerprint)s does not exist.' %
              {'fingerprint': key_fingerprint}))
    public_armor, private_armor = gpgutils.export_gpg_key(key['fingerprint'])
    return render(request, 'administration/key_detail.html', locals())
Exemplo n.º 5
0
def key_delete(request, key_fingerprint):
    key = gpgutils.get_gpg_key(key_fingerprint)
    if not key:
        raise Http404(
            _('GPG key with fingerprint %(fingerprint)s does not exist.' %
              {'fingerprint': key_fingerprint}))
    result = gpgutils.delete_gpg_key(key_fingerprint)
    if result is True:
        messages.success(
            request,
            _('GPG key %(fingerprint)s successfully deleted.' %
              {'fingerprint': key_fingerprint}))
    else:
        messages.warning(
            request,
            _('Failed to delete GPG key %(fingerprint)s.' %
              {'fingerprint': key_fingerprint}))
    next_url = request.GET.get('next', reverse('key_list'))
    return redirect(next_url)
Exemplo n.º 6
0
def key_delete_context(request, key_fingerprint):
    key = gpgutils.get_gpg_key(key_fingerprint)
    if not key:
        raise Http404(
            _('GPG key with fingerprint %(fingerprint)s does not exist.' %
              {'fingerprint': key_fingerprint}))
    header = _('Confirm deleting GPG key %(uids)s (%(fingerprint)s)' % {
        'uids': ', '.join(key['uids']),
        'fingerprint': key_fingerprint
    })
    prompt = ''
    dependent_objects = GPG.objects.filter(key=key_fingerprint)
    if dependent_objects:
        messages.error(
            request,
            _('GPG key %(fingerprint)s cannot be deleted because at least'
              ' one GPG Space is using it for encryption.' %
              {'fingerprint': key_fingerprint}))
    else:
        LOGGER.debug('No dependent GPG spaces')
        dependent_objects = Package.objects.filter(
            encryption_key_fingerprint=key_fingerprint).exclude(
                status=Package.DELETED)
        if dependent_objects:
            LOGGER.debug('HAVE dependent packages')
            messages.error(
                request,
                _('GPG key %(fingerprint)s cannot be deleted because at least'
                  ' one package (AIP, transfer) needs it in order to be'
                  ' decrypted.' % {'fingerprint': key_fingerprint}))
        else:
            LOGGER.debug('No dependent packages')
            prompt = _('Are you sure you want to delete GPG key'
                       ' %(fingerprint)s?' % {'fingerprint': key_fingerprint})
    default_cancel = reverse('key_list')
    cancel_url = request.GET.get('next', default_cancel)
    context_dict = {
        'header': header,
        'dependent_objects': dependent_objects,
        'prompt': prompt,
        'cancel_url': cancel_url,
    }
    return RequestContext(request, context_dict)