예제 #1
0
 def test_get(self):
     object_id = str(uuid.uuid4())
     api.get(self.request, object_id)
     self.key_manager.get.assert_called_once()
     args, kwargs = self.key_manager.get.call_args
     actual_ctxt, actual_id = args
     self.assertEqual(actual_ctxt, self.ctxt)
     self.assertEqual(actual_id, object_id)
예제 #2
0
 def _get_data(self):
     try:
         obj = client.get(self.request, self.kwargs['object_id'])
     except Exception:
         redirect = reverse('horizon:project:x509_certificates:index')
         msg = _('Unable to retrieve details for x509_certificate "%s".')\
             % (self.kwargs['object_id'])
         exceptions.handle(self.request, msg, redirect=redirect)
     return obj
예제 #3
0
def download_key(request, object_id):
    try:
        obj = client.get(request, object_id)
        data = obj.get_encoded()
        response = HttpResponse()
        response.write(data)
        response['Content-Disposition'] = ('attachment; '
                                           'filename="%s.key"' % object_id)
        response['Content-Length'] = str(len(response.content))
        return response

    except Exception:
        redirect = reverse('horizon:project:symmetric_keys:index')
        msg = _('Unable to download symmetric_key "%s".')\
            % (object_id)
        exceptions.handle(request, msg, redirect=redirect)
예제 #4
0
def download_cert(request, object_id):
    try:
        obj = client.get(request, object_id)
        der_data = obj.get_encoded()
        cert_obj = load_der_x509_certificate(der_data, default_backend())
        data = cert_obj.public_bytes(Encoding.PEM)
        response = HttpResponse()
        response.write(data)
        response['Content-Disposition'] = ('attachment; '
                                           'filename="%s.pem"' % object_id)
        response['Content-Length'] = str(len(response.content))
        return response

    except Exception:
        redirect = reverse('horizon:project:x509_certificates:index')
        msg = _('Unable to download x509_certificate "%s".')\
            % (object_id)
        exceptions.handle(request, msg, redirect=redirect)
예제 #5
0
def download_key(request, object_id):
    try:
        obj = client.get(request, object_id)
        data = obj.get_encoded()
        key_obj = serialization.load_der_public_key(
            data, backend=backends.default_backend())
        key_pem = key_obj.public_bytes(
            encoding=serialization.Encoding.PEM,
            format=serialization.PublicFormat.SubjectPublicKeyInfo)

        response = HttpResponse()
        response.write(key_pem)
        response['Content-Disposition'] = ('attachment; '
                                           'filename="%s.key"' % object_id)
        response['Content-Length'] = str(len(response.content))
        return response

    except Exception:
        redirect = reverse('horizon:project:public_keys:index')
        msg = _('Unable to download public_key "%s".')\
            % (object_id)
        exceptions.handle(request, msg, redirect=redirect)
예제 #6
0
def download_key(request, object_id):
    try:
        obj = client.get(request, object_id)
        data = obj.get_encoded()
        key_obj = load_der_private_key(data,
                                       password=None,
                                       backend=backends.default_backend())
        key_pem = key_obj.private_bytes(
            encoding=serialization.Encoding.PEM,
            format=serialization.PrivateFormat.PKCS8,
            encryption_algorithm=serialization.NoEncryption())
        response = HttpResponse()
        response.write(key_pem)
        response['Content-Disposition'] = ('attachment; '
                                           'filename="%s.key"' % object_id)
        response['Content-Length'] = str(len(response.content))
        return response

    except Exception:
        redirect = reverse('horizon:project:private_keys:index')
        msg = _('Unable to download private_key "%s".')\
            % (object_id)
        exceptions.handle(request, msg, redirect=redirect)