# Path: salt_observer/models.py
# class Domain(MarkdownContent):
#     ''' Represents a Fully qualified domain name '''
# 
#     fqdn = models.CharField(max_length=255)
#     minion = models.ManyToManyField('Minion', blank=True)
#     _ssl_lab_status = models.TextField(default='{}')
# 
#     can_speak_https = models.BooleanField(help_text='Is there a service listening on port 443')
#     public = models.BooleanField(help_text='Is this domain public accessible')
#     valid = models.BooleanField()
# 
#     @property
#     def ssl_lab_status(self):
#         try:
#             return json.loads(self._ssl_lab_status)
#         except ValueError:
#             return dict()
# 
#     @ssl_lab_status.setter
#     def ssl_lab_status(self, value):
#         self._ssl_lab_status = json.dumps(value)
# 
#     def check_if_valid(self, commit=True):
#         try:
#             a = requests.get('http://{}/'.format(self.fqdn), timeout=5, verify=False)
#             b = requests.get('https://{}/'.format(self.fqdn), timeout=5, verify=False)
#         except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
#             self.valid = False
#         else:
#             self.valid = True
# 
#         if commit:
#             self.save()
# 
#     def minion_count(self):
#         return len(self.minion.all())
# 
#     def worst_grade(self):
#         if self.ssl_lab_status.get('grades', []):
#             return max([g for g in self.ssl_lab_status.get('grades', [])])
#         return '0'
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.check_if_valid(commit=False)
#         super().save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.fqdn


from django.core.management.base import BaseCommand
from salt_observer.models import Domain



class Command(BaseCommand):
    help = 'Check all domains if they are valid'

    def handle(self, *args, **kwargs):
        ''' Check every domain '''


# Path: salt_observer/models.py
# class Domain(MarkdownContent):
#     ''' Represents a Fully qualified domain name '''
# 
#     fqdn = models.CharField(max_length=255)
#     minion = models.ManyToManyField('Minion', blank=True)
#     _ssl_lab_status = models.TextField(default='{}')
# 
#     can_speak_https = models.BooleanField(help_text='Is there a service listening on port 443')
#     public = models.BooleanField(help_text='Is this domain public accessible')
#     valid = models.BooleanField()
# 
#     @property
#     def ssl_lab_status(self):
#         try:
#             return json.loads(self._ssl_lab_status)
#         except ValueError:
#             return dict()
# 
#     @ssl_lab_status.setter
#     def ssl_lab_status(self, value):
#         self._ssl_lab_status = json.dumps(value)
# 
#     def check_if_valid(self, commit=True):
#         try:
#             a = requests.get('http://{}/'.format(self.fqdn), timeout=5, verify=False)
#             b = requests.get('https://{}/'.format(self.fqdn), timeout=5, verify=False)
#         except (requests.exceptions.ConnectionError, requests.exceptions.Timeout):
#             self.valid = False
#         else:
#             self.valid = True
# 
#         if commit:
#             self.save()
# 
#     def minion_count(self):
#         return len(self.minion.all())
# 
#     def worst_grade(self):
#         if self.ssl_lab_status.get('grades', []):
#             return max([g for g in self.ssl_lab_status.get('grades', [])])
#         return '0'
# 
#     def save(self, *args, **kwargs):
#         if not self.id:
#             self.check_if_valid(commit=False)
#         super().save(*args, **kwargs)
# 
#     def __str__(self):
#         return self.fqdn


# Path: salt_observer/management/commands/checkdomainvalidity.py
from django.core.management.base import BaseCommand
from salt_observer.models import Domain




class Command(BaseCommand):
    help = 'Check all domains if they are valid'

    def handle(self, *args, **kwargs):
        ''' Check every domain '''


        for domain in Domain.objects.all():