Skip to content

Commit

Permalink
Adds need_meta_data feature for existing keys.
Browse files Browse the repository at this point in the history
- implemented /api/key/merge.meta_data_json (available with backend api v1.1.1)
  • Loading branch information
wie-niet committed Dec 19, 2024
1 parent 9c05301 commit bd4861d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libs/module/DjangoBackendRfidAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,15 @@ def lookup(self, key, target, nfc_tools, *args, **kwargs):
meta_data = nfc_tools.collect_meta()
logger.info(f"card meta info: {meta_data}")
else:
# need meta data?
if self.keys[key].get("need_meta_data", False):
logger.info(f"key ('{key}') need_meta_data")
meta_data = nfc_tools.collect_meta()
# when succeeded:
if self.api_key_merge_meta_data_json(key, json.dumps(meta_data)):
del self.keys[key]["need_meta_data"]

# has access comform access rule?
has_access, msg = self.acl_has_access(key)
known_key = True

Expand All @@ -606,6 +615,25 @@ def request_post(self, path, data={}):

return resp.json()

def api_key_merge_meta_data_json(self, key, meta_data_json="{}"):
"""
api request to merge meta_data_json with key.
returns boolean True on succes, False or None on error.
"""
try:
resp = self.request_post(
f"/api/key/merge.meta_data_json",
{"key": key, "meta_data_json": meta_data_json},
)
logger.debug(f"DEBUG: resp: {resp}")
# api should return saved=True | saved=False
return resp.get("saved", None)
except Exception as e:
logger.warning(
f"Unexpected Exception during api_key_merge_meta_data_json. {e}",
exc_info=e,
)

def long_poll_events(self):

long_poll = self.requests.get(
Expand Down

0 comments on commit bd4861d

Please sign in to comment.