05/18 Enhanced codes and functionalities 10
This commit is contained in:
@@ -62,4 +62,29 @@ class EmergencyAccess(db.Model):
|
||||
self.request_initiated_at.isoformat() if self.request_initiated_at else None
|
||||
),
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
# True when enc_vault contains items in the old format (has a plaintext
|
||||
# 'name' field instead of enc_name/iv_name). Grantor should re-provision.
|
||||
'enc_vault_is_legacy': self._enc_vault_is_legacy(),
|
||||
}
|
||||
|
||||
def _enc_vault_is_legacy(self) -> bool:
|
||||
"""
|
||||
Return True if the stored enc_vault snapshot was created before the
|
||||
enc_name migration — i.e. any item has a 'name' key (plaintext) but
|
||||
lacks 'enc_name'. Returns False if no snapshot exists or all items
|
||||
use the new format.
|
||||
"""
|
||||
if not self.enc_vault:
|
||||
return False
|
||||
try:
|
||||
import json
|
||||
items = json.loads(self.enc_vault)
|
||||
if not isinstance(items, list):
|
||||
return False
|
||||
# Old format: item has 'name' and no 'enc_name'
|
||||
return any(
|
||||
isinstance(item, dict) and 'name' in item and 'enc_name' not in item
|
||||
for item in items
|
||||
)
|
||||
except (ValueError, TypeError):
|
||||
return False
|
||||
Reference in New Issue
Block a user