application_api_key_cache.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. # coding=utf-8
  2. """
  3. @project: MaxKB
  4. @Author:虎
  5. @file: application_api_key_cache.py
  6. @date:2024/7/25 11:30
  7. @desc:
  8. """
  9. from django.core.cache import cache
  10. from django.db.models import QuerySet
  11. from application.models import ApplicationApiKey
  12. from common.constants.cache_version import Cache_Version
  13. from common.utils.cache_util import get_cache
  14. @get_cache(cache_key=Cache_Version.APPLICATION_API_KEY.get_key_func(),
  15. use_get_data=lambda secret_key, use_get_data: use_get_data,
  16. version=Cache_Version.APPLICATION_API_KEY.get_version())
  17. def get_application_api_key(secret_key, use_get_data):
  18. application_api_key = QuerySet(ApplicationApiKey).filter(secret_key=secret_key[7:]).first()
  19. return {'allow_cross_domain': application_api_key.allow_cross_domain,
  20. 'cross_domain_list': application_api_key.cross_domain_list}
  21. def del_application_api_key(secret_key):
  22. cache.delete(Cache_Version.APPLICATION_API_KEY.get_key(secret_key=secret_key, use_get_data=True),
  23. version=Cache_Version.APPLICATION_API_KEY.get_version())