Browse Source

[MIG] letsencrypt: migration to 11.0

pull/1244/head
Ignacio Ibeas - Acysos S.L 7 years ago
parent
commit
af36a49add
  1. 1
      letsencrypt/README.rst
  2. 1
      letsencrypt/__init__.py
  3. 4
      letsencrypt/__manifest__.py
  4. 1
      letsencrypt/controllers/__init__.py
  5. 4
      letsencrypt/controllers/main.py
  6. 1
      letsencrypt/data/ir_config_parameter.xml
  7. 8
      letsencrypt/data/ir_cron.xml
  8. 1
      letsencrypt/hooks.py
  9. 1
      letsencrypt/models/__init__.py
  10. 20
      letsencrypt/models/letsencrypt.py
  11. 1
      letsencrypt/tests/__init__.py
  12. 1
      letsencrypt/tests/test_letsencrypt.py
  13. 2
      requirements.txt

1
letsencrypt/README.rst

@ -140,6 +140,7 @@ Contributors
* Antonio Espinosa <antonio.espinosa@tecnativa.com>
* Dave Lasley <dave@laslabs.com>
* Ronald Portier <ronald@therp.nl>
* Ignacio Ibeas <ignacio@acysos.com>
ACME implementation
-------------------

1
letsencrypt/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

4
letsencrypt/__manifest__.py

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Let's encrypt",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"author": "Therp BV,"
"Tecnativa,"
"Acysos S.L,"
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Hidden/Dependency",

1
letsencrypt/controllers/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import main

4
letsencrypt/controllers/main.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# © 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# © 2018 Ignacio Ibeas <ignacio@acysos.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os
from odoo import http
@ -12,7 +12,7 @@ class Letsencrypt(http.Controller):
@http.route('/.well-known/acme-challenge/<filename>', auth='none')
def acme_challenge(self, filename):
try:
with file(os.path.join(get_challenge_dir(), filename)) as key:
with open(os.path.join(get_challenge_dir(), filename)) as key:
return key.read()
except IOError:
pass

1
letsencrypt/data/ir_config_parameter.xml

@ -4,7 +4,6 @@
<record id="config_parameter_reload" model="ir.config_parameter" forcecreate="True">
<field name="key">letsencrypt.reload_command</field>
<field name="value">sudo /usr/sbin/service nginx reload</field>
<field name="group_ids" eval="[(6, False, [ref('base.group_system')])]" />
</record>
</data>
</openerp>

8
letsencrypt/data/ir_cron.xml

@ -3,12 +3,12 @@
<data noupdate="1">
<record id="cronjob" model="ir.cron">
<field name="name">Update letsencrypt certificates</field>
<field name="interval_type">weeks</field>
<field name="model_id" ref="model_letsencrypt"/>
<field name="state">code</field>
<field name="code">model.cron()</field>
<field name="interval_number">11</field>
<field name="interval_type">weeks</field>
<field name="numbercall">-1</field>
<field name="model">letsencrypt</field>
<field name="function">cron</field>
<field name="nextcall">2016-01-01</field>
</record>
</data>
</openerp>

1
letsencrypt/hooks.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID, api

1
letsencrypt/models/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import letsencrypt

20
letsencrypt/models/letsencrypt.py

@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# © 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# © 2018 Ignacio Ibeas <ignacio@acysos.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import os
import logging
import urllib2
import urlparse
import urllib.request
import urllib.parse
import subprocess
import tempfile
from odoo import _, api, models, exceptions
@ -81,7 +81,7 @@ class Letsencrypt(models.AbstractModel):
import IPy
try:
ip = IPy.IP(address)
except:
except Exception:
return False
return ip.iptype() == 'PRIVATE'
@ -107,12 +107,12 @@ class Letsencrypt(models.AbstractModel):
'letsencrypt.openssl.cnf', '/etc/ssl/openssl.cnf'
)
csr = os.path.join(get_data_dir(), '%s.csr' % domain)
with tempfile.NamedTemporaryFile() as cfg:
with tempfile.NamedTemporaryFile(mode='wt') as cfg:
cfg.write(open(config).read())
if len(domains) > 1:
cfg.write(
'\n[SAN]\nsubjectAltName=' +
','.join(map(lambda x: 'DNS:%s' % x, domains)) + '\n')
','.join(['DNS:%s' % x for x in domains]) + '\n')
cfg.file.flush()
cmdline = [
'openssl', 'req', '-new',
@ -131,7 +131,7 @@ class Letsencrypt(models.AbstractModel):
@api.model
def cron(self):
domain = urlparse.urlparse(
domain = urllib.parse.urlparse(
self.env['ir.config_parameter'].get_param(
'web.base.url', 'localhost')).netloc
self.validate_domain(domain)
@ -149,16 +149,16 @@ class Letsencrypt(models.AbstractModel):
with open(os.path.join(get_data_dir(), '%s.crt' % domain), 'w')\
as crt:
crt.write(crt_text)
chain_cert = urllib2.urlopen(
chain_cert = urllib.request.urlopen(
self.env['ir.config_parameter'].get_param(
'letsencrypt.chain_certificate_address',
'https://letsencrypt.org/certs/'
'lets-encrypt-x3-cross-signed.pem')
)
crt.write(chain_cert.read())
crt.write(str(chain_cert.read()))
chain_cert.close()
_logger.info('wrote %s', crt.name)
reload_cmd = self.env['ir.config_parameter'].get_param(
reload_cmd = self.env['ir.config_parameter'].sudo().get_param(
'letsencrypt.reload_command', False)
if reload_cmd:
_logger.info('reloading webserver...')

1
letsencrypt/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_letsencrypt

1
letsencrypt/tests/test_letsencrypt.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2016 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase

2
requirements.txt

@ -1,3 +1,5 @@
checksumdir
raven
pysftp
acme_tiny
IPy
Loading…
Cancel
Save