Coverage for frappe_manager / ssl_manager / storage_config.py: 67%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-07-02 18:35 +0530

1""" 

2Configuration for SSL certificate storage locations. 

3 

4This module provides a dataclass that encapsulates all path-related configuration 

5for SSL certificate storage, decoupling the certificate management logic from 

6infrastructure-specific directory structures. 

7""" 

8 

9from dataclasses import dataclass 

10from pathlib import Path 

11 

12 

13@dataclass 

14class SSLStorageConfig: 

15 """ 

16 Configuration for SSL certificate storage locations. 

17 

18 This class holds all path information needed for certificate management, 

19 separating configuration from business logic and making the system more testable. 

20 

21 Attributes: 

22 ssl_dir: Root directory where ACME client stores certificates (host filesystem) 

23 ssl_dir_container: Root directory where ACME client stores certificates (container filesystem) 

24 certs_dir: Directory where nginx-proxy looks for certificates (host filesystem) 

25 certs_dir_container: Directory where nginx-proxy looks for certificates (container filesystem) 

26 vhostd_dir: Directory for nginx-proxy vhost.d configuration files (host filesystem) 

27 webroot_dir: Directory for HTTP-01 challenge files (host filesystem) 

28 validate_on_init: Whether to validate paths exist during initialization (default: False) 

29 """ 

30 

31 ssl_dir: Path 

32 """Root directory where ACME client stores certificates (host filesystem)""" 

33 

34 ssl_dir_container: Path 

35 """Root directory where ACME client stores certificates (container filesystem)""" 

36 

37 certs_dir: Path 

38 """Directory where nginx-proxy looks for certificates (host filesystem)""" 

39 

40 certs_dir_container: Path 

41 """Directory where nginx-proxy looks for certificates (container filesystem)""" 

42 

43 vhostd_dir: Path 

44 """Directory for nginx-proxy vhost.d configuration files (host filesystem)""" 

45 

46 webroot_dir: Path 

47 """Directory for HTTP-01 challenge files (host filesystem)""" 

48 

49 validate_on_init: bool = False 

50 """Whether to validate paths exist during initialization""" 

51 

52 def __post_init__(self): 

53 """Validate paths if requested.""" 

54 if self.validate_on_init: 

55 self.validate() 

56 

57 def validate(self) -> None: 

58 """ 

59 Validate that the configuration is valid. 

60 

61 Raises: 

62 ValueError: If any required path is invalid or doesn't exist 

63 """ 

64 if not self.ssl_dir.exists(): 

65 raise ValueError(f"SSL root directory does not exist: {self.ssl_dir}") 

66 

67 if not self.certs_dir.exists(): 

68 raise ValueError(f"Certificates directory does not exist: {self.certs_dir}") 

69 

70 if not self.vhostd_dir.exists(): 

71 raise ValueError(f"vhost.d directory does not exist: {self.vhostd_dir}") 

72 

73 if not self.webroot_dir.exists(): 

74 raise ValueError(f"Webroot directory does not exist: {self.webroot_dir}")