From 20ea9f335f39dbe165a21b79d1bd1253b7210ff1 Mon Sep 17 00:00:00 2001 From: George Smirnov Date: Fri, 27 Dec 2024 01:25:45 +0300 Subject: [PATCH] [IMP] cetmix_tower_server: expand python libraries accessible in evaluation context - HMAC: module implements the HMAC algorithm - HASHLIB: hashlib module enables hashing operations to verify data integrity during communication. --- .../models/cx_tower_command.py | 33 ++++++++++++++++++- .../views/cx_tower_command_view.xml | 10 ++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/cetmix_tower_server/models/cx_tower_command.py b/cetmix_tower_server/models/cx_tower_command.py index b7dbb308..b4b62cd4 100644 --- a/cetmix_tower_server/models/cx_tower_command.py +++ b/cetmix_tower_server/models/cx_tower_command.py @@ -9,7 +9,30 @@ requests = wrap_module(__import__("requests"), ["post", "get", "request"]) json = wrap_module(__import__("json"), ["dumps"]) - +hashlib = wrap_module( + __import__("hashlib"), + [ + "sha1", + "sha224", + "sha256", + "sha384", + "sha512", + "sha3_224", + "sha3_256", + "sha3_384", + "sha3_512", + "shake_128", + "shake_256", + "blake2b", + "blake2s", + "md5", + "new", + ], +) +hmac = wrap_module( + __import__("hmac"), + ["new", "compare_digest"], +) DEFAULT_PYTHON_CODE = """# Available variables: # - user: Current Odoo User @@ -19,6 +42,12 @@ # - time, datetime, dateutil, timezone: useful Python libraries # - requests: Python 'requests' library. Available methods: 'post', 'get', 'request' # - json: Python 'json' library. Available methods: 'dumps' +# - hashlib: Python 'hashlib' library. Available methods: 'sha1', 'sha224', 'sha256', +# 'sha384', 'sha512', 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', 'shake_128', +# 'shake_256', 'blake2b', 'blake2s', 'md5', 'new' +# - hmac: Python 'hmac' library. Use 'new' to create HMAC objects. +# Available methods on the HMAC *object*: 'update', 'copy', 'digest', 'hexdigest'. +# Module-level function: 'compare_digest'. # - float_compare: Odoo function to compare floats based on specific precisions # - UserError: Warning Exception to use with raise # @@ -188,6 +217,8 @@ def _get_eval_context(self, server=None): "UserError": UserError, "server": server or self._context.get("active_server"), "tower": self.env["cetmix.tower"], + "hashlib": hashlib, + "hmac": hmac, } def name_get(self): diff --git a/cetmix_tower_server/views/cx_tower_command_view.xml b/cetmix_tower_server/views/cx_tower_command_view.xml index 7808cf14..1c6448dc 100644 --- a/cetmix_tower_server/views/cx_tower_command_view.xml +++ b/cetmix_tower_server/views/cx_tower_command_view.xml @@ -137,6 +137,16 @@ >requests: Python 'requests' library. Available methods: 'post', 'get', 'request'
  • json: Python 'json' library. Available methods: 'dumps'
  • +
  • hashlib: Python 'hashlib' library. + Available methods: 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'sha3_224', 'sha3_256',
    + 'sha3_384', 'sha3_512', 'shake_128', 'shake_256', 'blake2b', 'blake2s', 'md5', 'new'
  • +
  • hmac: Python 'hmac' library. Use 'new' to create HMAC objects.
    + Available methods on the HMAC *object*: 'update', 'copy', 'digest', 'hexdigest'.
    + Module-level function: 'compare_digest'.
  • UserError: Warning Exception to use with