-
Notifications
You must be signed in to change notification settings - Fork 3
/
letsencrypt.py
38 lines (26 loc) · 1.16 KB
/
letsencrypt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import webapp2
from google.appengine.ext import db
TESTING = os.environ.get('SERVER_SOFTWARE', '').startswith('Development')
from config import API_KEY
class LetsEncryptEntry(db.Model):
value = db.TextProperty(required=False)
created = db.DateTimeProperty(required=False, auto_now_add=True)
class LetsEncryptHandler(webapp2.RequestHandler):
def get(self, key):
entry = LetsEncryptEntry.get_by_key_name(key)
if entry == None:
self.response.set_status(404, 'Not found')
self.response.write('Not found')
return
self.response.write(entry.value)
def post(self, key):
if not self.request.headers.has_key('api-key') or self.request.headers['api-key'] != API_KEY:
# logging.info('Key was "%s", should be "%s"', self.request.headers['api-key'], API_KEY)
self.response.set_status(403, 'Permission denied')
self.response.write('Permission denied')
return
LetsEncryptEntry(key_name=key, value=self.request.body).put()
app = webapp2.WSGIApplication([
('/.well-known/acme-challenge/([\w-]+)', LetsEncryptHandler)
], debug=TESTING)