Skip to content

Commit

Permalink
Merge 4f281be into 7c3032f
Browse files Browse the repository at this point in the history
  • Loading branch information
atb00ker committed Jun 1, 2020
2 parents 7c3032f + 4f281be commit 71a1278
Show file tree
Hide file tree
Showing 27 changed files with 1,466 additions and 600 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ target/

# editors
*.komodoproject
.vscode

# other
*.DS_Store*
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ before_install:
install:
- pip install $DJANGO
- python setup.py -q develop
- pip install --upgrade https://github.com/openwisp/openwisp-utils/tarball/master#egg=openwisp_utils[qa]

before_script:
- ./run-qa-checks
Expand Down
40 changes: 19 additions & 21 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@ django-x509

.. image:: https://travis-ci.org/openwisp/django-x509.svg
:target: https://travis-ci.org/openwisp/django-x509
:alt: Automated Test Build
:alt: CI build status

.. image:: https://coveralls.io/repos/openwisp/django-x509/badge.svg
:target: https://coveralls.io/r/openwisp/django-x509
:alt: Coverage
:alt: Test Coverage

.. image:: https://requires.io/github/openwisp/django-x509/requirements.svg?branch=master
:target: https://requires.io/github/openwisp/django-x509/requirements/?branch=master
:alt: Requirements Status

.. image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg?style=flat-square
:target: https://gitter.im/openwisp/general
:alt: chat

.. image:: https://badge.fury.io/py/django-x509.svg
:target: http://badge.fury.io/py/django-x509
:alt: Pypi Version

.. image:: https://github.com/openwisp/django-x509/tree/master/docs/demo_x509.gif
.. image:: https://pepy.tech/badge/django-x509
:target: https://pepy.tech/project/django-x509
:alt: downloads

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://pypi.org/project/black/
:alt: code style: black

.. image:: https://github.com/openwisp/django-x509/raw/master/docs/demo_x509.gif
:alt: demo
------------

Simple reusable django app implementing x509 PKI certificates management.
Expand Down Expand Up @@ -612,21 +624,12 @@ For more information about automated tests in django, please refer to
Contributing
------------

Please read the `OpenWISP contributing guidelines
<http://openwisp.io/docs/developer/contributing.html>`_
and also keep in mind the following:
Please refer to the `OpenWISP contributing guidelines <http://openwisp.io/docs/developer/contributing.html>`_.

1. Announce your intentions in the `OpenWISP Mailing List <https://groups.google.com/d/forum/openwisp>`_
2. Fork this repo and install it
3. Follow `PEP8, Style Guide for Python Code`_
4. Write code
5. Write tests for your code
6. Ensure all tests pass
7. Ensure test coverage does not decrease
8. Document your changes
9. Send pull request
Support
-------

.. _PEP8, Style Guide for Python Code: http://www.python.org/dev/peps/pep-0008/
See `OpenWISP Support Channels <http://openwisp.org/support.html>`_.

Changelog
---------
Expand All @@ -637,8 +640,3 @@ License
-------

See `LICENSE <https://github.com/openwisp/django-x509/blob/master/LICENSE>`_.

Support
-------

See `OpenWISP Support Channels <http://openwisp.org/support.html>`_.
221 changes: 114 additions & 107 deletions django_x509/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class X509Form(forms.ModelForm):
OPERATION_CHOICES = (
('-', '----- {0} -----'.format(_('Please select an option'))),
('new', _('Create new')),
('import', _('Import Existing'))
('import', _('Import Existing')),
)
operation_type = forms.ChoiceField(choices=OPERATION_CHOICES)

Expand All @@ -25,30 +25,29 @@ class BaseAdmin(ModelAdmin):
"""
ModelAdmin for TimeStampedEditableModel
"""
list_display = ['name',
'key_length',
'digest',
'created',
'modified']

list_display = ['name', 'key_length', 'digest', 'created', 'modified']
search_fields = ['name', 'serial_number', 'common_name']
actions_on_bottom = True
save_on_top = True
form = X509Form
# custom attribute
readonly_edit = ['key_length',
'digest',
'validity_start',
'validity_end',
'country_code',
'state',
'city',
'organization_name',
'organizational_unit_name',
'email',
'common_name',
'serial_number',
'certificate',
'private_key']
readonly_edit = [
'key_length',
'digest',
'validity_start',
'validity_end',
'country_code',
'state',
'city',
'organization_name',
'organizational_unit_name',
'email',
'common_name',
'serial_number',
'certificate',
'private_key',
]

class Media:
css = {'all': (static('django-x509/css/admin.css'),)}
Expand Down Expand Up @@ -77,55 +76,57 @@ def get_fields(self, request, obj=None):
def get_context(self, data, ca_count=0, cert_count=0):
context = dict()
if ca_count:
context.update({
'title': _('Renew selected CAs'),
'ca_count': ca_count,
'cert_count': cert_count,
'cancel_url': f'{self.opts.app_label}_ca_changelist',
'action': 'renew_ca'
})
context.update(
{
'title': _('Renew selected CAs'),
'ca_count': ca_count,
'cert_count': cert_count,
'cancel_url': f'{self.opts.app_label}_ca_changelist',
'action': 'renew_ca',
}
)
else:
context.update({
'title': _('Renew selected certs'),
'cert_count': cert_count,
'cancel_url': f'{self.opts.app_label}_cert_changelist',
'action': 'renew_cert'
})
context.update({
'opts': self.model._meta,
'data': data
})
context.update(
{
'title': _('Renew selected certs'),
'cert_count': cert_count,
'cancel_url': f'{self.opts.app_label}_cert_changelist',
'action': 'renew_cert',
}
)
context.update({'opts': self.model._meta, 'data': data})
return context


class AbstractCaAdmin(BaseAdmin):
list_filter = ['key_length', 'digest', 'created']
fields = ['operation_type',
'name',
'notes',
'key_length',
'digest',
'validity_start',
'validity_end',
'country_code',
'state',
'city',
'organization_name',
'organizational_unit_name',
'email',
'common_name',
'extensions',
'serial_number',
'certificate',
'private_key',
'passphrase',
'created',
'modified']
fields = [
'operation_type',
'name',
'notes',
'key_length',
'digest',
'validity_start',
'validity_end',
'country_code',
'state',
'city',
'organization_name',
'organizational_unit_name',
'email',
'common_name',
'extensions',
'serial_number',
'certificate',
'private_key',
'passphrase',
'created',
'modified',
]
actions = ['renew_ca']

class Media:
js = ('admin/js/jquery.init.js',
'django-x509/js/x509-admin.js',)
js = ('admin/js/jquery.init.js', 'django-x509/js/x509-admin.js')

def get_urls(self):
return [
Expand All @@ -136,13 +137,11 @@ def crl_view(self, request, pk):
authenticated = request.user.is_authenticated
authenticated = authenticated() if callable(authenticated) else authenticated
if app_settings.CRL_PROTECTED and not authenticated:
return HttpResponse(_('Forbidden'),
status=403,
content_type='text/plain')
return HttpResponse(_('Forbidden'), status=403, content_type='text/plain')
instance = get_object_or_404(self.model, pk=pk)
return HttpResponse(instance.crl,
status=200,
content_type='application/x-pem-file')
return HttpResponse(
instance.crl, status=200, content_type='application/x-pem-file'
)

def renew_ca(self, request, queryset):
if request.POST.get('post'):
Expand All @@ -151,11 +150,16 @@ def renew_ca(self, request, queryset):
ca.renew()
renewed_rows += 1
message = ngettext(
'%(renewed_rows)d CA and its related certificates have been successfully renewed',
'%(renewed_rows)d CAs and their related certificates have been successfully renewed',
renewed_rows) % {
'renewed_rows': renewed_rows
}
(
'%(renewed_rows)d CA and its related certificates have '
'been successfully renewed'
),
(
'%(renewed_rows)d CAs and their related '
'certificates have been successfully renewed'
),
renewed_rows,
) % {'renewed_rows': renewed_rows}
self.message_user(request, message)
else:
data = dict()
Expand All @@ -169,7 +173,9 @@ def renew_ca(self, request, queryset):
return render(
request,
'admin/django_x509/renew_confirmation.html',
context=self.get_context(data, ca_count=ca_count, cert_count=cert_count)
context=self.get_context(
data, ca_count=ca_count, cert_count=cert_count
),
)

renew_ca.short_description = _('Renew selected CAs')
Expand All @@ -179,41 +185,43 @@ class AbstractCertAdmin(BaseAdmin):
list_filter = ['ca', 'revoked', 'key_length', 'digest', 'created']
list_select_related = ['ca']
readonly_fields = ['revoked', 'revoked_at']
fields = ['operation_type',
'name',
'ca',
'notes',
'revoked',
'revoked_at',
'key_length',
'digest',
'validity_start',
'validity_end',
'country_code',
'state',
'city',
'organization_name',
'organizational_unit_name',
'email',
'common_name',
'extensions',
'serial_number',
'certificate',
'private_key',
'passphrase',
'created',
'modified']
fields = [
'operation_type',
'name',
'ca',
'notes',
'revoked',
'revoked_at',
'key_length',
'digest',
'validity_start',
'validity_end',
'country_code',
'state',
'city',
'organization_name',
'organizational_unit_name',
'email',
'common_name',
'extensions',
'serial_number',
'certificate',
'private_key',
'passphrase',
'created',
'modified',
]
actions = ['revoke_action', 'renew_cert']

class Media:
js = ('admin/js/jquery.init.js',
'django-x509/js/x509-admin.js',)
js = ('admin/js/jquery.init.js', 'django-x509/js/x509-admin.js')

def ca_url(self, obj):
url = reverse('admin:{0}_ca_change'.format(self.opts.app_label), args=[obj.ca.pk])
return format_html('<a href="{url}">{text}</a>',
url=url,
text=obj.ca.name)
url = reverse(
'admin:{0}_ca_change'.format(self.opts.app_label), args=[obj.ca.pk]
)
return format_html('<a href="{url}">{text}</a>', url=url, text=obj.ca.name)

ca_url.short_description = 'CA'

def revoke_action(self, request, queryset):
Expand All @@ -239,18 +247,17 @@ def renew_cert(self, request, queryset):
message = ngettext(
'%(renewed_rows)d Certificate has been successfully renewed',
'%(renewed_rows)d Certificates have been successfully renewed',
renewed_rows) % {
'renewed_rows': renewed_rows
}
renewed_rows,
) % {'renewed_rows': renewed_rows}
self.message_user(request, message)
else:
return render(
request,
'admin/django_x509/renew_confirmation.html',
context=self.get_context(queryset, cert_count=len(queryset))
context=self.get_context(queryset, cert_count=len(queryset)),
)

renew_cert.short_description = _("Renew selected certificates")
renew_cert.short_description = _('Renew selected certificates')


# For backward compatibility
Expand Down
Loading

0 comments on commit 71a1278

Please sign in to comment.