Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamstooks committed Apr 19, 2016
0 parents commit 501c17d
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) Benjamin W Stookey and individual contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of Benjamin W Stookey nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include LICENSE
include README.md
recursive-include acme_challenge/templates *
recursive-include acme_challenge/tests *
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# django-acme-challenge

A quick tool to serve the acme-challenge verification page. When creating an SSL certificate with Let's Encrypt, you need to serve a page that they request to confirm you own the site:

Make sure your web server displays the following content at
http://your-domain-name/.well-known/acme-challenge/l9msb_LONG_STRING before continuing:

l9msb_LONG_STRING.LONG_STRING

This app provides a quick way to serve that page.

## Installation

Add `'acme_challenge',` to your installed apps and update your urls.py:

url(r'^.well-known/acme-challenge/', include('acme_challenge.urls')),

### Settings

Just set two variables:

- `ACME_CHALLENGE_URL_SLUG`
- `ACME_CHALLENGE_TEMPLATE_CONTENT`

`http://your-domain-name/.well-known/acme-challenge/ACME_CHALLENGE_URL_SLUG` will then serve the value of `ACME_CHALLENGE_TEMPLATE_CONTENT` for validation.
Empty file added acme_challenge/__init__.py
Empty file.
Empty file added acme_challenge/models.py
Empty file.
1 change: 1 addition & 0 deletions acme_challenge/templates/acme_challenge/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ ACME_CHALLENGE_TEMPLATE_CONTENT }}
Empty file.
26 changes: 26 additions & 0 deletions acme_challenge/tests/test_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Simple test to confirm that the view shows what it should when it should
"""

from django.test import TestCase, Client
from django.conf import settings

__all__ = (
'ViewTest',
)

class ViewTest(TestCase):

def setUp(self):
"""
Set the settings variables
"""
settings.ACME_CHALLENGE_URL_SLUG = "test"
settings.ACME_CHALLENGE_TEMPLATE_CONTENT = "test content"

def testView(self):
c = Client()
response = c.get("/test")
self.assertEqual(response.content, "test content")
response = c.get("/test2")
self.assertEqual(response.status_code, 404)
10 changes: 10 additions & 0 deletions acme_challenge/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.conf.urls import url
from views import ACMEChallengeView

urlpatterns = [
url(
r'^(?P<challenge_slug>[\w\-]+)$',
ACMEChallengeView.as_view(),
name='acme-challenge'
),
]
19 changes: 19 additions & 0 deletions acme_challenge/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.views.generic import TemplateView
from django.conf import settings
from django.http import Http404


class ACMEChallengeView(TemplateView):
"""
If the appropriate settings vars are set and the slug matches the url,
then serve the ACME Challenge value
"""
template_name = "acme_challenge/default.txt"

def get_context_data(self, **kwargs):
if settings.ACME_CHALLENGE_URL_SLUG and settings.ACME_CHALLENGE_TEMPLATE_CONTENT:
if self.kwargs['challenge_slug'] == settings.ACME_CHALLENGE_URL_SLUG:
context = super(ACMEChallengeView, self).get_context_data(**kwargs)
context['ACME_CHALLENGE_TEMPLATE_CONTENT'] = settings.ACME_CHALLENGE_TEMPLATE_CONTENT
return context
raise Http404
Empty file added requirements.txt
Empty file.
34 changes: 34 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
import os


# Utility function to read README file
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
name='django-acme-challenge',
version='0.1',
description="A quick tool to serve the acme-challenge verification page.",
author='Benjamin W Stookey',
author_email='ben.stookey@gmail.com',
url='https://github.com/jamstooks/django-acme-challenge',
long_description=read("README.md"),
packages=[
'acme_challenge',
'acme_challenge.tests'
],
include_package_data=True,
classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Framework :: Django',
],
test_suite='tests.main',
install_requires=['Django',],
)
36 changes: 36 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import django
from django.conf import settings


def main():
settings.configure(
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
},
ROOT_URLCONF='acme_challenge.urls',
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'acme_challenge',)
)

django.setup()
try:
# Django <= 1.8
from django.test.simple import DjangoTestSuiteRunner
test_runner = DjangoTestSuiteRunner(verbosity=1)
except ImportError:
# Django >= 1.8
from django.test.runner import DiscoverRunner
test_runner = DiscoverRunner(verbosity=1)

failures = test_runner.run_tests(['acme_challenge'])
if failures:
sys.exit(failures)

if __name__ == '__main__':
main()

0 comments on commit 501c17d

Please sign in to comment.