diff --git a/letsencrypt/README.rst b/letsencrypt/README.rst index dba2941df..5ba19fa2d 100644 --- a/letsencrypt/README.rst +++ b/letsencrypt/README.rst @@ -14,13 +14,13 @@ Let's Encrypt :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github - :target: https://github.com/OCA/server-tools/tree/10.0/letsencrypt + :target: https://github.com/OCA/server-tools/tree/11.0/letsencrypt :alt: OCA/server-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-10-0/server-tools-10-0-letsencrypt + :target: https://translation.odoo-community.org/projects/server-tools-11-0/server-tools-11-0-letsencrypt :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/149/10.0 + :target: https://runbot.odoo-community.org/runbot/149/11.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -148,7 +148,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -160,6 +160,7 @@ Authors * Therp BV * Tecnativa +* Acysos S.L Contributors ~~~~~~~~~~~~ @@ -198,6 +199,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/server-tools `_ project on GitHub. +This module is part of the `OCA/server-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/letsencrypt/__manifest__.py b/letsencrypt/__manifest__.py index e3f8f9fdc..faaedf590 100644 --- a/letsencrypt/__manifest__.py +++ b/letsencrypt/__manifest__.py @@ -16,7 +16,7 @@ "data": [ "data/ir_config_parameter.xml", "data/ir_cron.xml", - "views/base_config_settings.xml", + "views/res_config_settings.xml", ], "demo": [ "demo/ir_cron.xml", diff --git a/letsencrypt/data/ir_config_parameter.xml b/letsencrypt/data/ir_config_parameter.xml index 9637cbfd8..804b13578 100644 --- a/letsencrypt/data/ir_config_parameter.xml +++ b/letsencrypt/data/ir_config_parameter.xml @@ -16,9 +16,6 @@ forcecreate="True"> letsencrypt.backoff 3 - diff --git a/letsencrypt/migrations/11.0.2.0.0/post-migrate.py b/letsencrypt/migrations/11.0.2.0.0/post-migrate.py index 57a6a9c3a..60a66058c 100644 --- a/letsencrypt/migrations/11.0.2.0.0/post-migrate.py +++ b/letsencrypt/migrations/11.0.2.0.0/post-migrate.py @@ -6,6 +6,10 @@ from odoo import api, SUPERUSER_ID def migrate_altnames(env): config = env["ir.config_parameter"] existing = config.search([("key", "=like", "letsencrypt.altname.%")]) + if not existing: + # We may be migrating from 10.0.2.0.0, in which case + # letsencrypt.altnames already exists and shouldn't be clobbered. + return new_domains = "\n".join(existing.mapped("value")) config.set_param("letsencrypt.altnames", new_domains) existing.unlink() @@ -18,14 +22,18 @@ def migrate_cron(env): jobs = ( env["ir.cron"] .with_context(active_test=False) - .search([("model", "=", "letsencrypt"), ("function", "=", "cron")]) + .search( + [ + ("ir_actions_server_id.model_id.model", "=", "letsencrypt"), + ("ir_actions_server_id.code", "=", "model.cron()"), + ] + ) ) if not jobs: # ir.cron._try_lock doesn't handle empty recordsets well return - jobs.write( - {"function": "_cron", "interval_type": "days", "interval_number": "1"} - ) + jobs.write({"interval_type": "days", "interval_number": "1"}) + jobs.mapped("ir_actions_server_id").write({"code": "model._cron()"}) def migrate(cr, version): diff --git a/letsencrypt/models/__init__.py b/letsencrypt/models/__init__.py index bb6955a8e..54285a070 100644 --- a/letsencrypt/models/__init__.py +++ b/letsencrypt/models/__init__.py @@ -1,4 +1,4 @@ # © 2016 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import letsencrypt -from . import base_config_settings +from . import res_config_settings diff --git a/letsencrypt/models/letsencrypt.py b/letsencrypt/models/letsencrypt.py index 85acdabc3..e973f43f9 100644 --- a/letsencrypt/models/letsencrypt.py +++ b/letsencrypt/models/letsencrypt.py @@ -10,7 +10,7 @@ import os import re import subprocess import time -import urlparse +import urllib.parse from datetime import datetime, timedelta @@ -197,7 +197,7 @@ class Letsencrypt(models.AbstractModel): def _cron(self): ir_config_parameter = self.env['ir.config_parameter'] base_url = ir_config_parameter.get_param('web.base.url', 'localhost') - domain = urlparse.urlparse(base_url).hostname + domain = urllib.parse.urlparse(base_url).hostname cert_file = os.path.join(_get_data_dir(), '%s.crt' % domain) domains = self._cascade_domains([domain] + self._get_altnames()) @@ -403,7 +403,7 @@ class Letsencrypt(models.AbstractModel): Respond to the HTTP challenge by writing the file to serve. """ token = self._base64_encode(challenge.token) - challenge_file = os.path.join(_get_challenge_dir(), token.decode()) + challenge_file = os.path.join(_get_challenge_dir(), token) with open(challenge_file, 'w') as file_: file_.write(challenge.validation(account_key)) diff --git a/letsencrypt/models/base_config_settings.py b/letsencrypt/models/res_config_settings.py similarity index 95% rename from letsencrypt/models/base_config_settings.py rename to letsencrypt/models/res_config_settings.py index 2f8918391..f35a6f8b9 100644 --- a/letsencrypt/models/base_config_settings.py +++ b/letsencrypt/models/res_config_settings.py @@ -10,8 +10,8 @@ DNS_SCRIPT_DEFAULT = """# Write your script here """ -class BaseConfigSettings(models.TransientModel): - _inherit = 'base.config.settings' +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' letsencrypt_altnames = fields.Text( string="Domain names", @@ -69,7 +69,7 @@ class BaseConfigSettings(models.TransientModel): @api.model def default_get(self, fields_list): - res = super(BaseConfigSettings, self).default_get(fields_list) + res = super().default_get(fields_list) get_param = self.env['ir.config_parameter'].get_param res.update( { @@ -97,8 +97,9 @@ class BaseConfigSettings(models.TransientModel): return res @api.multi - def set_dns_provider(self): - self.ensure_one() + def set_values(self): + super().set_values() + self.letsencrypt_check_dns_required() if self.letsencrypt_dns_provider == 'shell': diff --git a/letsencrypt/readme/CONTRIBUTORS.rst b/letsencrypt/readme/CONTRIBUTORS.rst index 5da59e4d3..1aeb78d8d 100644 --- a/letsencrypt/readme/CONTRIBUTORS.rst +++ b/letsencrypt/readme/CONTRIBUTORS.rst @@ -2,5 +2,6 @@ * Antonio Espinosa * Dave Lasley * Ronald Portier +* Ignacio Ibeas * George Daramouskas * Jan Verbeek diff --git a/letsencrypt/static/description/index.html b/letsencrypt/static/description/index.html index 7706bfc69..f24ebd0d6 100644 --- a/letsencrypt/static/description/index.html +++ b/letsencrypt/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

This module was written to have your Odoo installation request SSL certificates from https://letsencrypt.org automatically.

Table of contents

@@ -490,7 +490,7 @@ For example, --load=web,letsencry

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -500,6 +500,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Therp BV
  • Tecnativa
  • +
  • Acysos S.L
@@ -509,6 +510,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Antonio Espinosa <antonio.espinosa@tecnativa.com>
  • Dave Lasley <dave@laslabs.com>
  • Ronald Portier <ronald@therp.nl>
  • +
  • Ignacio Ibeas <ignacio@acysos.com>
  • George Daramouskas <gdaramouskas@therp.nl>
  • Jan Verbeek <jverbeek@therp.nl>
  • @@ -535,7 +537,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    -

    This module is part of the OCA/server-tools project on GitHub.

    +

    This module is part of the OCA/server-tools project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/letsencrypt/tests/test_letsencrypt.py b/letsencrypt/tests/test_letsencrypt.py index 29226491b..f7e693a02 100644 --- a/letsencrypt/tests/test_letsencrypt.py +++ b/letsencrypt/tests/test_letsencrypt.py @@ -1,8 +1,6 @@ # Copyright 2018 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from __future__ import unicode_literals # cryptography is picky - import os import shutil @@ -28,21 +26,21 @@ def _poll(order, deadline): class TestLetsencrypt(SingleTransactionCase): def setUp(self): - super(TestLetsencrypt, self).setUp() + super().setUp() self.env['ir.config_parameter'].set_param( 'web.base.url', 'http://www.example.com' ) - self.env['base.config.settings'].create( + self.env['res.config.settings'].create( { 'letsencrypt_dns_provider': 'shell', 'letsencrypt_dns_shell_script': 'touch /tmp/.letsencrypt_test', 'letsencrypt_altnames': '*.example.com', 'letsencrypt_reload_command': 'true', # i.e. /bin/true } - ).set_dns_provider() + ).set_values() def test_config_settings(self): - setting_vals = self.env['base.config.settings'].default_get([]) + setting_vals = self.env['res.config.settings'].default_get([]) self.assertEqual(setting_vals['letsencrypt_dns_provider'], 'shell') self.assertEqual( setting_vals['letsencrypt_dns_shell_script'], @@ -57,9 +55,9 @@ class TestLetsencrypt(SingleTransactionCase): @mock.patch('acme.client.ClientV2.poll_and_finalize', side_effect=_poll) def test_http_challenge(self, poll, answer_challenge): letsencrypt = self.env['letsencrypt'] - self.env['base.config.settings'].create( + self.env['res.config.settings'].create( {'letsencrypt_altnames': 'test.example.com'} - ).set_dns_provider() + ).set_values() letsencrypt._cron() poll.assert_called() self.assertTrue(os.listdir(_get_challenge_dir())) @@ -98,22 +96,22 @@ class TestLetsencrypt(SingleTransactionCase): ) def test_dns_challenge_error_on_missing_provider(self): - self.env['base.config.settings'].create( + self.env['res.config.settings'].create( { 'letsencrypt_altnames': '*.example.com', 'letsencrypt_dns_provider': False, } - ).set_dns_provider() + ).set_values() with self.assertRaises(UserError): self.env['letsencrypt']._cron() def test_prefer_dns_setting(self): - self.env['base.config.settings'].create( + self.env['res.config.settings'].create( { 'letsencrypt_altnames': 'example.com', 'letsencrypt_prefer_dns': True, } - ).set_dns_provider() + ).set_values() self.env['ir.config_parameter'].set_param( 'web.base.url', 'http://example.com' ) @@ -327,7 +325,7 @@ class TestLetsencrypt(SingleTransactionCase): file_.write(cert.public_bytes(serialization.Encoding.PEM)) def tearDown(self): - super(TestLetsencrypt, self).tearDown() + super().tearDown() shutil.rmtree(_get_data_dir(), ignore_errors=True) if path.isfile('/tmp/.letsencrypt_test'): os.remove('/tmp/.letsencrypt_test') diff --git a/letsencrypt/views/base_config_settings.xml b/letsencrypt/views/base_config_settings.xml deleted file mode 100644 index 93402ee1e..000000000 --- a/letsencrypt/views/base_config_settings.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - Letsencrypt base config settings - base.config.settings - - - - - - - - - - - - - - - - - - diff --git a/letsencrypt/views/res_config_settings.xml b/letsencrypt/views/res_config_settings.xml new file mode 100644 index 000000000..5bb56b429 --- /dev/null +++ b/letsencrypt/views/res_config_settings.xml @@ -0,0 +1,75 @@ + + + Letsencrypt settings view + res.config.settings + + + +
    +
    +

    Let's Encrypt

    + +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +