|
| 1 | +from django.db import models |
| 2 | +from django.conf import settings |
| 3 | + |
| 4 | +from api.models import AuditedModel |
| 5 | + |
| 6 | +class Service(AuditedModel): |
| 7 | + owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT) |
| 8 | + app = models.ForeignKey('App', on_delete=models.CASCADE) |
| 9 | + procfile_type = models.TextField(blank=False, null=False, unique=False) |
| 10 | + path_pattern = models.TextField(blank=False, null=False, unique=False) |
| 11 | + |
| 12 | + class Meta: |
| 13 | + get_latest_by = 'created' |
| 14 | + unique_together = (('app', 'procfile_type')) |
| 15 | + ordering = ['-created'] |
| 16 | + |
| 17 | + def __str__(self): |
| 18 | + return "{}-{}".format(self.app.id, str(self.procfile_type)) |
| 19 | + |
| 20 | + def as_dict(self): |
| 21 | + return { |
| 22 | + "procfile_type": self.procfile_type, |
| 23 | + "path_pattern": self.path_pattern |
| 24 | + } |
| 25 | + |
| 26 | + def save(self, *args, **kwargs): |
| 27 | + # app = str(self.app) |
| 28 | + # domain = str(self.domain) |
| 29 | + |
| 30 | + # # get config for the service |
| 31 | + # config = self._load_service_config(app, 'router') |
| 32 | + |
| 33 | + # # See if domains are available |
| 34 | + # if 'domains' not in config: |
| 35 | + # config['domains'] = '' |
| 36 | + |
| 37 | + # # convert from string to list to work with and filter out empty strings |
| 38 | + # domains = [_f for _f in config['domains'].split(',') if _f] |
| 39 | + # if domain not in domains: |
| 40 | + # domains.append(domain) |
| 41 | + # config['domains'] = ','.join(domains) |
| 42 | + |
| 43 | + # self._save_service_config(app, 'router', config) |
| 44 | + |
| 45 | + # Save to DB |
| 46 | + return super(Service, self).save(*args, **kwargs) |
| 47 | + |
| 48 | + def delete(self, *args, **kwargs): |
| 49 | + # app = str(self.app) |
| 50 | + # domain = str(self.domain) |
| 51 | + |
| 52 | + # # Deatch cert, updates k8s |
| 53 | + # if self.certificate: |
| 54 | + # self.certificate.detach(domain=domain) |
| 55 | + |
| 56 | + # # get config for the service |
| 57 | + # config = self._load_service_config(app, 'router') |
| 58 | + |
| 59 | + # # See if domains are available |
| 60 | + # if 'domains' not in config: |
| 61 | + # config['domains'] = '' |
| 62 | + |
| 63 | + # # convert from string to list to work with and filter out empty strings |
| 64 | + # domains = [_f for _f in config['domains'].split(',') if _f] |
| 65 | + # if domain in domains: |
| 66 | + # domains.remove(domain) |
| 67 | + # config['domains'] = ','.join(domains) |
| 68 | + |
| 69 | + # self._save_service_config(app, 'router', config) |
| 70 | + |
| 71 | + # Delete from DB |
| 72 | + return super(Service, self).delete(*args, **kwargs) |
0 commit comments