old_contents: import requests
  from collections import defaultdict
  from requests.exceptions import RequestException
  
  from django.conf import settings
  from django.utils.dateparse import parse_datetime
  
  import sal.plugin
  import server.utils as utils
  
  
  class CryptStatus(sal.plugin.DetailPlugin):
  
      description = 'FileVault Escrow Status'
  
      supported_os_families = [sal.plugin.OSFamilies.darwin]
  
      def get_context(self, machine, **kwargs):
          context = defaultdict(str)
          context['title'] = self.description
  
          crypt_url = utils.get_setting('crypt_url', None).rstrip()
  
          if crypt_url:
              try:
                  verify = settings.ROOT_CA
              except AttributeError:
                  verify = True
  
              request_url = '{}/verify/{}/recovery_key/'.format(crypt_url, machine.serial)
              try:
                  response = requests.get(request_url, verify=verify)
                  if response.status_code == requests.codes.ok:
                      output = response.json()
                      # Have template link to machine info page rather
                      # than Crypt root.
                      machine_url = '{}/info/{}'.format(crypt_url, machine.serial)
              except RequestException:
                  # Either there was an error or the machine hasn't been
                  # seen.
                  output = None
                  machine_url = crypt_url
  
              if output:
                  context['escrowed'] = output['escrowed']
                  if output['escrowed']:
                      context['date_escrowed'] = parse_datetime(output['date_escrowed'])
  
          context['crypt_url'] = machine_url
          return context
  
new_contents: import requests
  from collections import defaultdict
  from requests.exceptions import RequestException
  
  from django.conf import settings
  from django.utils.dateparse import parse_datetime
  
  import sal.plugin
  import server.utils as utils
  
  
  class CryptStatus(sal.plugin.DetailPlugin):
  
      description = 'FileVault Escrow Status'
  
      supported_os_families = [sal.plugin.OSFamilies.darwin]
  
      def get_context(self, machine, **kwargs):
          context = defaultdict(str)
          context['title'] = self.description
  
          crypt_url = utils.get_setting('crypt_url', None)
          if crypt_url:
              crypt_url = crypt_url.rstrip()
  
          if crypt_url:
              try:
                  verify = settings.ROOT_CA
              except AttributeError:
                  verify = True
  
              request_url = '{}/verify/{}/recovery_key/'.format(crypt_url, machine.serial)
              try:
                  response = requests.get(request_url, verify=verify)
                  if response.status_code == requests.codes.ok:
                      output = response.json()
                      # Have template link to machine info page rather
                      # than Crypt root.
                      machine_url = '{}/info/{}'.format(crypt_url, machine.serial)
              except RequestException:
                  # Either there was an error or the machine hasn't been
                  # seen.
                  output = None
                  machine_url = crypt_url
  
              if output:
                  context['escrowed'] = output['escrowed']
                  if output['escrowed']:
                      context['date_escrowed'] = parse_datetime(output['date_escrowed'])
  
          context['crypt_url'] = machine_url
          return context
  
subject: Fix #267 (#269)