Coverage for frappe_manager / ssl_manager / proxy_storage.py: 33%
18 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:35 +0530
« prev ^ index » next coverage.py v7.13.5, created at 2026-07-02 18:35 +0530
1"""
2Provides access to nginx-proxy volume mount paths.
4This module separates the concern of reading Docker volume configurations
5from controlling nginx operations, improving testability and separation of concerns.
6"""
8from pathlib import Path
10from frappe_manager.docker import ComposeFile, DockerVolumeMount, DockerVolumeType
11from frappe_manager.utils.helpers import create_class_from_dict
14class ProxyStoragePaths:
15 """
16 Provides access to nginx-proxy volume mount paths.
18 This class is responsible only for reading and exposing the Docker volume
19 mount configuration for the nginx-proxy service. It does not perform any
20 operations on nginx itself.
22 Attributes:
23 service_name: Name of the nginx service in docker-compose
24 compose_file_manager: The compose file manager for reading volumes
25 dirs: Dynamic attribute containing volume mount information
26 """
28 def __init__(
29 self,
30 service_name: str,
31 compose_file_manager: ComposeFile,
32 ):
33 """
34 Initialize the proxy storage paths reader.
36 Args:
37 service_name: Name of the nginx service (e.g., 'nginx', 'nginx-proxy')
38 compose_file_manager: The compose file manager for reading volumes
39 """
40 self.service_name = service_name
41 self.compose_file_manager = compose_file_manager
42 self.dirs = self._get_docker_volume_dirs()
44 def _get_docker_volume_dirs(self):
45 """
46 Read volume mount paths from the compose file.
48 Returns:
49 A dynamic class instance with attributes for each volume mount.
50 Each attribute is a DockerVolumeMount object providing both host
51 and container paths.
52 """
54 all_volumes: list[DockerVolumeMount] = self.compose_file_manager.get_service_volumes(self.service_name)
55 dirs = {}
56 for volume in all_volumes:
57 if volume.type == DockerVolumeType.bind:
58 # Ensure host is a Path object to access .name property
59 host_path = Path(volume.host) if not isinstance(volume.host, Path) else volume.host
60 name = str(host_path.name)
61 dirs[name] = volume
62 dirs_class = create_class_from_dict("dirs", dirs)
63 return dirs_class()