[IMP] data_encryption: black, isort, prettier
This commit is contained in:
parent
d9eb1d7ff7
commit
949674d06c
|
|
@ -44,14 +44,14 @@ class EncryptedData(models.Model):
|
||||||
cipher = self._get_cipher(env)
|
cipher = self._get_cipher(env)
|
||||||
try:
|
try:
|
||||||
return cipher.decrypt(self.encrypted_data).decode()
|
return cipher.decrypt(self.encrypted_data).decode()
|
||||||
except InvalidToken:
|
except InvalidToken as exc:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_(
|
_(
|
||||||
"Password has been encrypted with a different "
|
"Password has been encrypted with a different "
|
||||||
"key. Unless you can recover the previous key, "
|
"key. Unless you can recover the previous key, "
|
||||||
"this password is unreadable."
|
"this password is unreadable."
|
||||||
)
|
)
|
||||||
)
|
) from exc
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@ormcache("self._uid", "name", "env")
|
@ormcache("self._uid", "name", "env")
|
||||||
|
|
@ -77,10 +77,10 @@ class EncryptedData(models.Model):
|
||||||
return {}
|
return {}
|
||||||
try:
|
try:
|
||||||
return json.loads(data)
|
return json.loads(data)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError) as exc:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("The data you are trying to read are not in a json format")
|
_("The data you are trying to read are not in a json format")
|
||||||
)
|
) from exc
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _retrieve_env():
|
def _retrieve_env():
|
||||||
|
|
@ -107,8 +107,11 @@ class EncryptedData(models.Model):
|
||||||
key_str = config.get(key_name)
|
key_str = config.get(key_name)
|
||||||
if not key_str:
|
if not key_str:
|
||||||
raise ValidationError(
|
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 should be in bytes format
|
||||||
key = key_str.encode()
|
key = key_str.encode()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
# generated from manifests external_dependencies
|
||||||
|
cryptography
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../data_encryption
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue