Skip to content

Commit

Permalink
[FIX] hw_drivers: add cron for HTTPS certificate update
Browse files Browse the repository at this point in the history
Context:
When an HTTPS certificate is delivered, it is valid for ~1 month.
To avoid missing the certificate, a script is automatically ran daily
to check if a new HTTPS certificate is necessary.

On the IoT box, it is added in the native Unix system with this file:
https://github.com/odoo/odoo/blob/16.0/addons/point_of_sale/tools/posbox/overwrite_after_init/etc/cron.daily/odoo

However, prior to this commit, there is nothing equivalent for windows

Note: the HTTPS certificate check is also done automatically when
accessing the homepage.

Before this commit:
After an HTTPS certificate delivery, if we let the IoT server
running non-stop (and without accessing the homepage).
The HTTPS will expire without any automatic renew.

After this commit:
The cron process is handled by the handler Manager

Other note:
- Using native Windows "Scheduled Task" have been proposed at:
odoo#144584
But, was judged too risky from a security point of view
- `sched` library have been discarded as the code is too verbose
- This is unstable for the iot-box. This is the reason for the
initial Windows check on the import. The iot-box does not need
this fix anyway as explained in the context

opw-3617687

closes odoo#145114

X-original-commit: b9bd360
Signed-off-by: Loan Sens (lse) <lse@odoo.com>
  • Loading branch information
lse-odoo committed Dec 6, 2023
1 parent e3ddf17 commit 962d432
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addons/hw_drivers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

_logger = logging.getLogger(__name__)

try:
import schedule
except ImportError:
schedule = None
# For now, it is intended to not be installed on the iot-box as it uses native Unix cron system
if platform.system() == 'Windows':
_logger.warning('Could not import library schedule')

try:
from dbus.mainloop.glib import DBusGMainLoop
except ImportError:
Expand Down Expand Up @@ -104,6 +112,9 @@ def run(self):
except Exception as e:
_logger.error("Error in %s: %s", str(interface), e)

# Set scheduled actions
schedule and schedule.every().day.at("00:00").do(helpers.get_certificate_status)

#Setup the websocket connection
if helpers.get_odoo_server_url():
iot_client.start()
Expand All @@ -116,6 +127,7 @@ def run(self):
self.previous_iot_devices = iot_devices.copy()
self.send_alldevices(iot_client)
time.sleep(3)
schedule and schedule.run_pending()
except Exception:
# No matter what goes wrong, the Manager loop needs to keep running
_logger.error(format_exc())
Expand Down
1 change: 1 addition & 0 deletions setup/win32/requirements-local-proxy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ghostscript==0.7
cryptocode==0.1
pysmb==1.2.9.1
websocket-client==1.6.3
schedule==1.2.1

0 comments on commit 962d432

Please sign in to comment.