data_export_10.py 860 B

123456789101112131415161718192021222324
  1. def is_authenticated(account_pk):
  2. account = models.RemoteAccount.objects.get(pk=account_pk)
  3. if account.has_access():
  4. url = settings.SUPPORT_AUTH_URL
  5. auth_header = make_auth_header(account)
  6. info = get_ts_info()
  7. params = {
  8. "version": info.get("version", "Version Missing"),
  9. "serial_number": info.get("serialnumber", "Serial Missing"),
  10. }
  11. try:
  12. response = requests.get(
  13. url, params=params, headers=auth_header, verify=False
  14. )
  15. except requests.exceptions.RequestException as err:
  16. logger.error("Request Exception: {0}".format(err))
  17. else:
  18. if response.ok:
  19. return True
  20. else:
  21. logger.error("Authentication failure at {0}: {1}".format(url, response))
  22. return False