Skip to content

Commit

Permalink
[IMP] cetmix_tower_server: expand python libraries accessible in eval…
Browse files Browse the repository at this point in the history
…uation context

- HMAC: module implements the HMAC algorithm
- HASHLIB:  hashlib module  enables hashing operations to verify data integrity during communication.
  • Loading branch information
Aldeigja committed Jan 15, 2025
1 parent b1e01f1 commit 20ea9f3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
33 changes: 32 additions & 1 deletion cetmix_tower_server/models/cx_tower_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
#
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions cetmix_tower_server/views/cx_tower_command_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@
>requests</code>: Python 'requests' library. Available methods: 'post', 'get', 'request'</li>
<li><code
>json</code>: Python 'json' library. Available methods: 'dumps'</li>
<li><code>hashlib</code>: Python 'hashlib' library.
Available methods: 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'sha3_224', 'sha3_256',<br
/>
'sha3_384', 'sha3_512', 'shake_128', 'shake_256', 'blake2b', 'blake2s', 'md5', 'new'</li>
<li><code
>hmac</code>: Python 'hmac' library. Use 'new' to create HMAC objects.<br
/>
Available methods on the HMAC *object*: 'update', 'copy', 'digest', 'hexdigest'.<br
/>
Module-level function: 'compare_digest'.</li>
<li><code
>UserError</code>: Warning Exception to use with <code
>
Expand Down

0 comments on commit 20ea9f3

Please sign in to comment.