Skip to content

Commit

Permalink
Merge ccd59fe into af6c04b
Browse files Browse the repository at this point in the history
  • Loading branch information
YraganTron authored Jun 17, 2017
2 parents af6c04b + ccd59fe commit c14502d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def generate_root_crt(self, data, recreation=False):
self._create_root_crt(self.generate_subj_recreation_root_crt(), validity_period)
else:
self._create_root_crt(self.generate_subj_root_crt(data), validity_period)
self._create_model_root_crt(data)
obj = self._create_model_root_crt(data)
return obj

def generate_site_crt(self, cn, validity_period, pk=None, alt_name='DNS'):
if not os.path.exists(os.path.join(settings.MEDIA_ROOT, cn)):
Expand All @@ -45,9 +46,10 @@ def generate_site_crt(self, cn, validity_period, pk=None, alt_name='DNS'):
self._create_req_crt(path)
self._create_site_crt(path, self.calculate_validity_period(validity_period))
if pk:
self._recreation_model_site_crt(cn, pk, self.calculate_validity_period(validity_period))
obj = self._recreation_model_site_crt(cn, pk, self.calculate_validity_period(validity_period))
else:
self._create_model_site_crt(cn, self.calculate_validity_period(validity_period))
obj = self._create_model_site_crt(cn, self.calculate_validity_period(validity_period))
return obj

@staticmethod
def get_type_alt_names(cn):
Expand Down
16 changes: 10 additions & 6 deletions core/views/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ def get_queryset(self):

class Create(BreadcrumbsMixin, FormView):
form_class = forms.CertificatesCreate
success_url = reverse_lazy('certificates_search')
template_name = 'core/certificate/create.html'

def get_success_url(self):
return reverse_lazy('certificates_view', kwargs={'pk': self.obj.pk})

def get_breadcrumbs(self):
return (
('Home', reverse('index')),
Expand All @@ -69,9 +71,9 @@ def get_initial(self):
def form_valid(self, form):
ca = Ca()
if ca.get_type_alt_names(form.cleaned_data['cn']):
ca.generate_site_crt(form.cleaned_data['cn'], form.cleaned_data['validity_period'], alt_name='IP')
self.obj=ca.generate_site_crt(form.cleaned_data['cn'], form.cleaned_data['validity_period'], alt_name='IP')
else:
ca.generate_site_crt(form.cleaned_data['cn'], form.cleaned_data['validity_period'])
self.obj=ca.generate_site_crt(form.cleaned_data['cn'], form.cleaned_data['validity_period'])
return super().form_valid(form)


Expand All @@ -80,6 +82,9 @@ class UploadExisting(BreadcrumbsMixin, FormView):
form_class = forms.CertificatesUploadExisting
success_url = reverse_lazy('certificates_search')

def get_success_url(self):
return reverse_lazy('certificates_view', kwargs={'pk': self.obj.pk})

def get_breadcrumbs(self):
return (
('Home', reverse('index')),
Expand All @@ -91,7 +96,7 @@ def form_valid(self, form):
if form.cleaned_data['crt_file']:
crt_file_data = form.cleaned_data['crt_file'].read()
cert = crypto.load_certificate(crypto.FILETYPE_PEM, crt_file_data)
models.SiteCrt.objects.create(
self.obj=models.SiteCrt.objects.create(
key=form.cleaned_data['key_file'],
crt=form.cleaned_data['crt_file'],
cn=cert.get_subject().CN,
Expand All @@ -102,7 +107,7 @@ def form_valid(self, form):
cn = cert.get_subject().CN
pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, form.cleaned_data['key_text'])
Ca.write_cert_site(cert, pkey, cn)
models.SiteCrt.objects.create(
self.obj=models.SiteCrt.objects.create(
key=os.path.join(cn, cn + '.key'),
crt=os.path.join(cn, cn + '.crt'),
cn=cn,
Expand Down Expand Up @@ -193,4 +198,3 @@ def form_valid(self, form):
ca.generate_site_crt(self.object.cn, form.cleaned_data['validity_period'], self.kwargs['pk'])
messages.success(self.request, 'Recreation success')
return super().form_valid(form)

0 comments on commit c14502d

Please sign in to comment.