2023-10-24 16:59:02 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2017-06-09 08:28:44 +00:00
|
|
|
|
|
|
|
from orchestra.contrib.orchestration import ServiceController
|
|
|
|
|
2024-03-19 19:08:13 +00:00
|
|
|
from . import ApacheTrafficByName, NextCloudAPIMixin
|
2017-06-09 08:28:44 +00:00
|
|
|
from .. import settings
|
|
|
|
|
|
|
|
|
|
|
|
class NextCloudController(NextCloudAPIMixin, ServiceController):
|
|
|
|
"""
|
|
|
|
Creates a wordpress site on a WordPress MultiSite installation.
|
|
|
|
|
|
|
|
You should point it to the database server
|
|
|
|
"""
|
|
|
|
verbose_name = _("nextCloud SaaS")
|
|
|
|
model = 'saas.SaaS'
|
|
|
|
default_route_match = "saas.service == 'nextcloud'"
|
|
|
|
doc_settings = (settings,
|
|
|
|
('SAAS_NEXTCLOUD_API_URL',)
|
|
|
|
)
|
|
|
|
|
|
|
|
def update_or_create(self, saas, server):
|
|
|
|
try:
|
|
|
|
self.api_get('users/%s' % saas.name)
|
|
|
|
except RuntimeError:
|
2024-01-03 17:53:46 +00:00
|
|
|
if getattr(saas, 'password', None):
|
2017-06-09 08:28:44 +00:00
|
|
|
self.create(saas)
|
2024-01-03 17:53:46 +00:00
|
|
|
self.update_group(saas)
|
|
|
|
self.update_quota(saas)
|
2017-06-09 08:28:44 +00:00
|
|
|
else:
|
|
|
|
raise
|
|
|
|
else:
|
2024-01-03 17:53:46 +00:00
|
|
|
if getattr(saas, 'password', None):
|
|
|
|
self.update_password(saas)
|
|
|
|
else:
|
|
|
|
self.update_group(saas)
|
|
|
|
self.update_quota(saas)
|
2024-01-03 18:49:42 +00:00
|
|
|
if saas.is_active:
|
|
|
|
self.enable_user(saas)
|
|
|
|
else:
|
|
|
|
self.disable_user(saas)
|
|
|
|
|
2024-01-04 18:10:17 +00:00
|
|
|
def remove(self, saas, server):
|
|
|
|
self.api_delete('users/%s' % saas.name)
|
|
|
|
|
2024-10-30 12:29:34 +00:00
|
|
|
def save(self, saas):
|
2024-01-04 18:10:17 +00:00
|
|
|
self.append(self.update_or_create, saas)
|
2024-01-03 17:53:46 +00:00
|
|
|
|
2017-06-09 08:28:44 +00:00
|
|
|
def delete(self, saas):
|
|
|
|
self.append(self.remove, saas)
|
|
|
|
|
|
|
|
|
|
|
|
class NextcloudTraffic(ApacheTrafficByName):
|
|
|
|
__doc__ = ApacheTrafficByName.__doc__
|
|
|
|
verbose_name = _("nextCloud SaaS Traffic")
|
|
|
|
default_route_match = "saas.service == 'nextcloud'"
|
|
|
|
doc_settings = (settings,
|
|
|
|
('SAAS_TRAFFIC_IGNORE_HOSTS', 'SAAS_NEXTCLOUD_LOG_PATH')
|
|
|
|
)
|
|
|
|
log_path = settings.SAAS_NEXTCLOUD_LOG_PATH
|