Coverage for lynceus/files/storage.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.10.0, created at 2025-07-29 08:46 +0000

1""" 

2Storage metadata classes allowing to easily configure various user, group and topic storages (default, and extra ones). 

3 

4Inside Lynceus since version 0.7.0 (instead of LynceusCLI) to share unique key creation algorithm across all projects. 

5 

6""" 

7 

8from abc import ABC 

9from dataclasses import dataclass 

10 

11from lynceus.utils import cleansed_str_value 

12 

13 

14@dataclass 

15class StorageMetadataBase(ABC): 

16 """ 

17 Abstract base class for storage metadata configurations. 

18 

19 Provide the foundation for different types of storage metadata including 

20 user storages, group storages, and other specialized storage configurations. 

21 This class defines the common interface and basic functionality needed 

22 to create and manage various storage containers with unique naming, 

23 access permissions, and caching behaviors. 

24 

25 Attributes 

26 ---------- 

27 instance_id : str 

28 Unique identifier allowing environment discrimination 

29 """ 

30 

31 # The Instance ID (allowing to have an environment discrimination) 

32 instance_id: str 

33 

34 def cleansed_instance_id(self) -> str: 

35 """ 

36 Get a cleansed version of the instance ID. 

37 

38 Apply string cleansing operations to ensure the instance ID 

39 is safe for use in storage names and paths. 

40 

41 Returns 

42 ------- 

43 str 

44 Cleansed instance ID string 

45 """ 

46 return cleansed_str_value(self.instance_id) 

47 

48 def build_unique_storage_name(self) -> str: 

49 """ 

50 Build a unique storage name for this metadata instance. 

51 

52 Abstract method that subclasses must implement to generate 

53 a unique identifier for storage containers or buckets. 

54 

55 Returns 

56 ------- 

57 str 

58 Unique storage name 

59 

60 Raises 

61 ------ 

62 NotImplementedError 

63 If not implemented by subclass 

64 """ 

65 raise NotImplementedError() 

66 

67 def get_cache_toggle(self) -> bool: 

68 """ 

69 Get the cache toggle setting for this storage. 

70 

71 Abstract method that subclasses must implement to specify 

72 whether caching should be enabled for this storage type. 

73 

74 Returns 

75 ------- 

76 bool 

77 True if caching should be enabled, False otherwise 

78 

79 Raises 

80 ------ 

81 NotImplementedError 

82 If not implemented by subclass 

83 """ 

84 raise NotImplementedError() 

85 

86 def get_access_permission(self) -> str: 

87 """ 

88 Get the access permission level for this storage. 

89 

90 Abstract method that subclasses must implement to specify 

91 the access permissions required for this storage type. 

92 

93 Returns 

94 ------- 

95 str 

96 Access permission level identifier 

97 

98 Raises 

99 ------ 

100 NotImplementedError 

101 If not implemented by subclass 

102 """ 

103 raise NotImplementedError() 

104 

105 def build_storage_prefix(self) -> str: 

106 """ 

107 Build a storage prefix for organizing files within the storage. 

108 

109 Abstract method that subclasses must implement to generate 

110 a prefix used for organizing files within the storage container. 

111 

112 Returns 

113 ------- 

114 str 

115 Storage prefix path 

116 

117 Raises 

118 ------ 

119 NotImplementedError 

120 If not implemented by subclass 

121 """ 

122 raise NotImplementedError() 

123 

124 def build_mount_path_relative_to_home_dir(self) -> str: 

125 """ 

126 Build a mount path relative to the user's home directory. 

127 

128 Abstract method that subclasses must implement to generate 

129 a local mount path for accessing the storage relative to the home directory. 

130 

131 Returns 

132 ------- 

133 str 

134 Mount path relative to home directory 

135 

136 Raises 

137 ------ 

138 NotImplementedError 

139 If not implemented by subclass 

140 """ 

141 raise NotImplementedError()