Skip to content

Commit

Permalink
[IMP] data_encryption: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Oct 9, 2022
1 parent d9eb1d7 commit 949674d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
15 changes: 9 additions & 6 deletions data_encryption/models/encrypted_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ def _decrypt_data(self, env):
cipher = self._get_cipher(env)
try:
return cipher.decrypt(self.encrypted_data).decode()
except InvalidToken:
except InvalidToken as exc:
raise ValidationError(
_(
"Password has been encrypted with a different "
"key. Unless you can recover the previous key, "
"this password is unreadable."
)
)
) from exc

@api.model
@ormcache("self._uid", "name", "env")
Expand All @@ -77,10 +77,10 @@ def _encrypted_read_json(self, name, env=None):
return {}
try:
return json.loads(data)
except (ValueError, TypeError):
except (ValueError, TypeError) as exc:
raise ValidationError(
_("The data you are trying to read are not in a json format")
)
) from exc

@staticmethod
def _retrieve_env():
Expand All @@ -107,8 +107,11 @@ def _get_cipher(cls, env):
key_str = config.get(key_name)
if not key_str:
raise ValidationError(
_("No '%s' entry found in config file. " "Use a key similar to: %s")
% (key_name, Fernet.generate_key())
_(
"No '%(key_name)s' entry found in config file. "
"Use a key similar to: %(key)s"
)
% {"key_name": key_name, "key": Fernet.generate_key()}
)
# key should be in bytes format
key = key_str.encode()
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# generated from manifests external_dependencies
cryptography
1 change: 1 addition & 0 deletions setup/data_encryption/odoo/addons/data_encryption
6 changes: 6 additions & 0 deletions setup/data_encryption/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 949674d

Please sign in to comment.