ScriptCollection 4.4.71__py3-none-any.whl → 4.4.73__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. ScriptCollection/Executables.py +22 -3
  2. ScriptCollection/GeneralUtilities.py +42 -0
  3. ScriptCollection/LinuxServerSecurityCheck/Checks/AccountChecks.py +71 -0
  4. ScriptCollection/LinuxServerSecurityCheck/Checks/ContainerChecks.py +34 -0
  5. ScriptCollection/LinuxServerSecurityCheck/Checks/FileSystemChecks.py +141 -0
  6. ScriptCollection/LinuxServerSecurityCheck/Checks/KernelChecks.py +49 -0
  7. ScriptCollection/LinuxServerSecurityCheck/Checks/LogChecks.py +39 -0
  8. ScriptCollection/LinuxServerSecurityCheck/Checks/NetworkChecks.py +67 -0
  9. ScriptCollection/LinuxServerSecurityCheck/Checks/PackageIntegrityChecks.py +62 -0
  10. ScriptCollection/LinuxServerSecurityCheck/Checks/PersistenceChecks.py +99 -0
  11. ScriptCollection/LinuxServerSecurityCheck/Checks/ProcessChecks.py +88 -0
  12. ScriptCollection/LinuxServerSecurityCheck/Checks/SSHChecks.py +56 -0
  13. ScriptCollection/LinuxServerSecurityCheck/Checks/__init__.py +0 -0
  14. ScriptCollection/LinuxServerSecurityCheck/LinuxServerSecurityChecker.py +90 -0
  15. ScriptCollection/LinuxServerSecurityCheck/LinuxSystemAccess.py +85 -0
  16. ScriptCollection/LinuxServerSecurityCheck/PackageOwnershipLookup.py +42 -0
  17. ScriptCollection/LinuxServerSecurityCheck/SecurityCheckBase.py +19 -0
  18. ScriptCollection/LinuxServerSecurityCheck/SecurityFinding.py +19 -0
  19. ScriptCollection/LinuxServerSecurityCheck/SuspiciousCommandPatterns.py +46 -0
  20. ScriptCollection/LinuxServerSecurityCheck/SystemAccessBase.py +244 -0
  21. ScriptCollection/LinuxServerSecurityCheck/SystemEntities.py +45 -0
  22. ScriptCollection/LinuxServerSecurityCheck/__init__.py +0 -0
  23. ScriptCollection/OCIImages/AbstractImageHandler.py +14 -26
  24. ScriptCollection/OCIImages/AbstractTagPatternImageHandler.py +46 -0
  25. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebian.py +5 -14
  26. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebianSlim.py +5 -14
  27. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGeneric.py +6 -15
  28. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGenericV.py +6 -15
  29. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGitlabCE.py +7 -8
  30. ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGitlabEE.py +7 -8
  31. ScriptCollection/OCIImages/OCIImageManager.py +73 -68
  32. ScriptCollection/OCIImages/OCIRegistryClient.py +117 -0
  33. ScriptCollection/ScriptCollectionCore.py +9 -4
  34. ScriptCollection/TFCPS/Android/TFCPS_CodeUnitSpecific_Android.py +479 -0
  35. ScriptCollection/TFCPS/Android/__init__.py +0 -0
  36. ScriptCollection/TFCPS/CPP/TFCPS_CodeUnitSpecific_CPP.py +6 -5
  37. ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py +38 -4
  38. ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +4 -4
  39. ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py +1 -0
  40. ScriptCollection/TFCPS/Rust/CargoLockFile.py +151 -0
  41. ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py +5 -0
  42. ScriptCollection/TFCPS/SCTaskRunnerServer.py +55 -9
  43. ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py +6 -2
  44. ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py +14 -0
  45. ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +19 -0
  46. ScriptCollection/TFCPS/TFCPS_RemoteBuild.py +39 -11
  47. ScriptCollection/TFCPS/TFCPS_Tools_General.py +34 -2
  48. {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/METADATA +3 -3
  49. {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/RECORD +52 -27
  50. {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/entry_points.txt +1 -0
  51. {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/WHEEL +0 -0
  52. {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,244 @@
1
+ import ipaddress
2
+ import os
3
+ import posixpath
4
+ import stat
5
+ import sys
6
+ from abc import ABC, abstractmethod
7
+ from collections.abc import Iterator
8
+ from .SystemEntities import UserAccount, ProcessInformation, ProgramResult, SocketInformation
9
+
10
+
11
+ class SystemAccessBase(ABC):
12
+ """Read-only access to the system which is checked.
13
+ All paths are absolute paths of the checked system.
14
+ The abstract methods are the primitives which access the system; everything else is derived from them,
15
+ so that a testcase only has to replace the primitives."""
16
+
17
+ maximal_size_of_text_files: int = 50 * 1024 * 1024
18
+ seconds_per_day: int = 24 * 60 * 60
19
+
20
+ @abstractmethod
21
+ def current_user_is_root(self) -> bool:
22
+ raise NotImplementedError
23
+
24
+ @abstractmethod
25
+ def read_bytes(self, path: str, maximal_amount_of_bytes: int) -> bytes | None:
26
+ """Returns the first bytes of the file or None if the file does not exist (anymore)."""
27
+ raise NotImplementedError
28
+
29
+ @abstractmethod
30
+ def list_folder(self, path: str) -> list[str] | None:
31
+ """Returns the names of the entries of the folder or None if the folder does not exist (anymore)."""
32
+ raise NotImplementedError
33
+
34
+ @abstractmethod
35
+ def get_lstat(self, path: str) -> os.stat_result | None:
36
+ """Returns the stat-information of the path itself (a symlink is not followed) or None if the path does not exist (anymore)."""
37
+ raise NotImplementedError
38
+
39
+ @abstractmethod
40
+ def path_exists(self, path: str) -> bool:
41
+ """Returns whether the path exists. Symlinks are followed."""
42
+ raise NotImplementedError
43
+
44
+ @abstractmethod
45
+ def read_link(self, path: str) -> str | None:
46
+ """Returns the target of the symlink or None if the symlink does not exist (anymore) or has no target (for example /proc/<pid>/exe of a kernel-thread)."""
47
+ raise NotImplementedError
48
+
49
+ @abstractmethod
50
+ def program_is_available(self, program: str) -> bool:
51
+ raise NotImplementedError
52
+
53
+ @abstractmethod
54
+ def run_program(self, program: str, arguments: list[str]) -> ProgramResult:
55
+ """Runs a program which must not change anything on the system."""
56
+ raise NotImplementedError
57
+
58
+ @abstractmethod
59
+ def get_file_attribute_flags(self, path: str) -> int | None:
60
+ """Returns the inode-flags (as shown by lsattr) of a regular file or None if the filesystem does not support them."""
61
+ raise NotImplementedError
62
+
63
+ @abstractmethod
64
+ def get_current_time(self) -> float:
65
+ raise NotImplementedError
66
+
67
+ def read_text(self, path: str) -> str | None:
68
+ content = self.read_bytes(path, SystemAccessBase.maximal_size_of_text_files)
69
+ if content is None:
70
+ return None
71
+ return content.decode("utf-8", errors="replace")
72
+
73
+ def is_regular_file(self, path: str) -> bool:
74
+ file_stat = self.get_lstat(path)
75
+ return file_stat is not None and stat.S_ISREG(file_stat.st_mode)
76
+
77
+ def is_symlink(self, path: str) -> bool:
78
+ file_stat = self.get_lstat(path)
79
+ return file_stat is not None and stat.S_ISLNK(file_stat.st_mode)
80
+
81
+ def is_folder(self, path: str) -> bool:
82
+ file_stat = self.get_lstat(path)
83
+ return file_stat is not None and stat.S_ISDIR(file_stat.st_mode)
84
+
85
+ def is_binary_content(self, content: bytes) -> bool:
86
+ return b"\0" in content[:8192]
87
+
88
+ def list_files_recursively(self, folder: str, excluded_folders: set[str]) -> Iterator[tuple[str, os.stat_result]]:
89
+ """Yields every non-folder-entry (regular files, symlinks, ...) below the folder together with its lstat-information.
90
+ Symlinks to folders are not followed. Folders contained in excluded_folders are not entered."""
91
+ folders_to_visit: list[str] = [folder]
92
+ while len(folders_to_visit) > 0:
93
+ current_folder = folders_to_visit.pop()
94
+ entries = self.list_folder(current_folder)
95
+ if entries is None:
96
+ continue
97
+ for entry in sorted(entries):
98
+ path = posixpath.join(current_folder, entry)
99
+ entry_stat = self.get_lstat(path)
100
+ if entry_stat is None:
101
+ continue
102
+ if stat.S_ISDIR(entry_stat.st_mode):
103
+ if path not in excluded_folders:
104
+ folders_to_visit.append(path)
105
+ else:
106
+ yield path, entry_stat
107
+
108
+ def list_regular_files_recursively(self, folder: str) -> list[str]:
109
+ return [path for path, file_stat in self.list_files_recursively(folder, set()) if stat.S_ISREG(file_stat.st_mode)]
110
+
111
+ def path_is_alias(self, path: str) -> bool:
112
+ """Returns whether the path is reachable only through a symlinked top-level-folder (for example /lib/systemd on a system with merged /usr),
113
+ so that its content is already reachable through another path."""
114
+ parts = [part for part in path.split("/") if part != ""]
115
+ current = ""
116
+ for part in parts[:-1]:
117
+ current = current + "/" + part
118
+ if self.is_symlink(current):
119
+ return True
120
+ return False
121
+
122
+ def get_users(self) -> list[UserAccount]:
123
+ content = self.read_text("/etc/passwd")
124
+ if content is None:
125
+ raise FileNotFoundError("/etc/passwd does not exist.")
126
+ result: list[UserAccount] = []
127
+ for line in content.splitlines():
128
+ if line.strip() == "" or line.startswith("#"):
129
+ continue
130
+ fields = line.split(":")
131
+ if len(fields) < 7:
132
+ continue
133
+ result.append(UserAccount(fields[0], int(fields[2]), int(fields[3]), fields[5], fields[6]))
134
+ return result
135
+
136
+ def get_home_folders(self) -> list[str]:
137
+ result: list[str] = []
138
+ for user in self.get_users():
139
+ if user.home_folder not in result and user.home_folder.startswith("/") and self.is_folder(user.home_folder):
140
+ result.append(user.home_folder)
141
+ return result
142
+
143
+ def get_minimal_uid_of_regular_users(self) -> int:
144
+ content = self.read_text("/etc/login.defs")
145
+ if content is not None:
146
+ for line in content.splitlines():
147
+ fields = line.split()
148
+ if len(fields) == 2 and fields[0] == "UID_MIN":
149
+ return int(fields[1])
150
+ # 1000 is the value which shadow-utils uses when UID_MIN is not defined in /etc/login.defs.
151
+ return 1000
152
+
153
+ def get_process_ids(self) -> list[int]:
154
+ entries = self.list_folder("/proc")
155
+ if entries is None:
156
+ raise FileNotFoundError("/proc does not exist.")
157
+ return sorted(int(entry) for entry in entries if entry.isdigit())
158
+
159
+ def get_process(self, pid: int) -> ProcessInformation | None:
160
+ """Returns None if the process does not exist (anymore)."""
161
+ status = self.read_text(f"/proc/{pid}/status")
162
+ if status is None:
163
+ return None
164
+ name = ""
165
+ uid = -1
166
+ for line in status.splitlines():
167
+ if line.startswith("Name:"):
168
+ name = line[len("Name:"):].strip()
169
+ elif line.startswith("Uid:"):
170
+ uid = int(line.split()[1])
171
+ commandline_bytes = self.read_bytes(f"/proc/{pid}/cmdline", 65536)
172
+ if commandline_bytes is None:
173
+ return None
174
+ commandline = commandline_bytes.replace(b"\0", b" ").decode("utf-8", errors="replace").strip()
175
+ executable = self.read_link(f"/proc/{pid}/exe")
176
+ return ProcessInformation(pid, name, uid, executable, commandline)
177
+
178
+ def get_processes(self) -> list[ProcessInformation]:
179
+ result: list[ProcessInformation] = []
180
+ for pid in self.get_process_ids():
181
+ process = self.get_process(pid)
182
+ if process is not None:
183
+ result.append(process)
184
+ return result
185
+
186
+ def get_processes_by_socket_inode(self) -> dict[int, list[ProcessInformation]]:
187
+ result: dict[int, list[ProcessInformation]] = {}
188
+ for process in self.get_processes():
189
+ file_descriptors = self.list_folder(f"/proc/{process.pid}/fd")
190
+ if file_descriptors is None:
191
+ continue
192
+ for file_descriptor in file_descriptors:
193
+ target = self.read_link(f"/proc/{process.pid}/fd/{file_descriptor}")
194
+ if target is not None and target.startswith("socket:[") and target.endswith("]"):
195
+ inode = int(target[len("socket:["):-1])
196
+ processes = result.setdefault(inode, [])
197
+ if process not in processes:
198
+ processes.append(process)
199
+ return result
200
+
201
+ def get_sockets(self) -> list[SocketInformation]:
202
+ """Returns the tcp- and udp-sockets of all network-namespaces (so also the sockets of containers)."""
203
+ socket_tables: list[str] = []
204
+ known_namespaces: set[str] = set()
205
+ for pid in self.get_process_ids():
206
+ namespace = self.read_link(f"/proc/{pid}/ns/net")
207
+ if namespace is not None and namespace not in known_namespaces:
208
+ known_namespaces.add(namespace)
209
+ socket_tables.append(f"/proc/{pid}/net")
210
+ if len(socket_tables) == 0:
211
+ socket_tables.append("/proc/net")
212
+ result: list[SocketInformation] = []
213
+ known_inodes: set[int] = set()
214
+ for socket_table in socket_tables:
215
+ for protocol in ["tcp", "tcp6", "udp", "udp6"]:
216
+ content = self.read_text(f"{socket_table}/{protocol}")
217
+ if content is None:
218
+ continue
219
+ for socket_information in SystemAccessBase.parse_socket_table(protocol, content):
220
+ if socket_information.inode == 0 or socket_information.inode not in known_inodes:
221
+ known_inodes.add(socket_information.inode)
222
+ result.append(socket_information)
223
+ return result
224
+
225
+ @staticmethod
226
+ def parse_socket_table(protocol: str, content: str) -> list[SocketInformation]:
227
+ result: list[SocketInformation] = []
228
+ for line in content.splitlines()[1:]:
229
+ fields = line.split()
230
+ if len(fields) < 10:
231
+ continue
232
+ local_address, local_port = SystemAccessBase.decode_socket_address(fields[1])
233
+ remote_address, remote_port = SystemAccessBase.decode_socket_address(fields[2])
234
+ result.append(SocketInformation(protocol, local_address, local_port, remote_address, remote_port, fields[3].upper(), int(fields[9])))
235
+ return result
236
+
237
+ @staticmethod
238
+ def decode_socket_address(hex_address: str) -> tuple[str, int]:
239
+ """Decodes an address like "0100007F:0035" from /proc/net/tcp. The address consists of 32-bit-words in host-byte-order."""
240
+ address_part, port_part = hex_address.split(":")
241
+ raw_address = bytes.fromhex(address_part)
242
+ if sys.byteorder == "little":
243
+ raw_address = b"".join(raw_address[index:index + 4][::-1] for index in range(0, len(raw_address), 4))
244
+ return str(ipaddress.ip_address(raw_address)), int(port_part, 16)
@@ -0,0 +1,45 @@
1
+ from dataclasses import dataclass
2
+
3
+
4
+ @dataclass(frozen=True)
5
+ class UserAccount:
6
+ name: str
7
+ uid: int
8
+ gid: int
9
+ home_folder: str
10
+ shell: str
11
+
12
+
13
+ @dataclass(frozen=True)
14
+ class ProcessInformation:
15
+ pid: int
16
+ name: str
17
+ uid: int
18
+ executable: str | None
19
+ """Target of /proc/<pid>/exe as seen from the mount-namespace of the process. None for kernel-threads and zombies."""
20
+ commandline: str
21
+
22
+ def is_kernel_thread_or_zombie(self) -> bool:
23
+ return self.executable is None and self.commandline == ""
24
+
25
+ def describe(self) -> str:
26
+ return f"pid {self.pid} (name \"{self.name}\", uid {self.uid}, executable \"{self.executable}\", commandline \"{self.commandline[:300]}\")"
27
+
28
+
29
+ @dataclass(frozen=True)
30
+ class ProgramResult:
31
+ exit_code: int
32
+ stdout: str
33
+ stderr: str
34
+
35
+
36
+ @dataclass(frozen=True)
37
+ class SocketInformation:
38
+ protocol: str
39
+ local_address: str
40
+ local_port: int
41
+ remote_address: str
42
+ remote_port: int
43
+ state: str
44
+ """Hex-state as written in /proc/net/tcp, for example "0A" for listening tcp-sockets."""
45
+ inode: int
File without changes
@@ -1,45 +1,33 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from packaging.version import Version
3
- from ..GeneralUtilities import GeneralUtilities, VersionEcholon
3
+ from ..GeneralUtilities import VersionEcholon
4
4
 
5
5
  class AbstractImageHandler(ABC):
6
-
7
- @abstractmethod
8
- def can_handle(self,image_name:str)->bool:
9
- raise NotImplementedError()#because it is abstract
10
-
11
- def _protected_get_credentials_for_registry(self,registry_address:str,username_str:str)->tuple[str,str]:
12
- """return (username, password) for basic auth.
13
- Data will be taken from the registries which are declared in the environment-variables-configuration-file or in the environment
14
- (see ScriptCollectionCore.get_docker_registry_credentials_from_environment_variables) if available.
15
- If no credentials are available then None will be returned for the missing values."""
16
- raise NotImplementedError()
17
-
18
- def _protected_get_tags_from_images_from_custom_registry(self,registry_address:str)->list[str]:
19
- raise NotImplementedError()
20
-
21
- def _protected_get_tags_from_images_from_docker_hub(self,registry_address:str,tag_filter:str)->list[str]:
22
- GeneralUtilities.assert_condition(registry_address.startswith("docker.io/",f"Image \"{registry_address}\" is not from docker-hub."))
23
- raise NotImplementedError()
24
-
6
+ """An image-handler knows the format of the tags of certain images: which tags of a registry are candidates for an update of a
7
+ given tag and which version a tag represents. The tags themselves are read from the registry by the OCIRegistryClient."""
8
+
25
9
  @abstractmethod
26
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
10
+ def can_handle(self,image_name:str,tag:str)->bool:
11
+ """Returns whether this handler knows the format of the given tag of the given image."""
27
12
  raise NotImplementedError()#because it is abstract
28
13
 
29
14
  @abstractmethod
30
- def tag_to_version(self,image_name:str,tag:str)->Version:
15
+ def tag_has_same_format(self,image_name:str,tag:str,reference_tag:str)->bool:
16
+ """Returns whether the given tag has the same format as the reference-tag, which means it is a candidate for an update of the
17
+ reference-tag. Example: for the reference-tag "13.4-slim" the tag "13.5-slim" has the same format but "13.5" and "13-slim" do not."""
31
18
  raise NotImplementedError()#because it is abstract
32
19
 
33
20
  @abstractmethod
34
- def version_to_tag(self,image_name:str,version:Version)->str:
21
+ def tag_to_version(self,image_name:str,tag:str)->Version:
35
22
  raise NotImplementedError()#because it is abstract
36
23
 
37
24
  @abstractmethod
38
25
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
39
26
  raise NotImplementedError()#because it is abstract
40
27
 
41
- def get_latest_version_custom(self,image_name:str,registry_address:str,current_version:Version)->Version:
42
- """Determines the latest version of an image using an image-specific custom algorithm.
28
+ def get_latest_tag_custom(self,image_name:str,current_tag:str,candidate_tags:list[str])->str:
29
+ """Determines the tag the image should be updated to using an image-specific custom algorithm.
30
+ candidate_tags contains the current tag and all available tags which have the same format as the current tag.
43
31
  This is used when the echolon VersionEcholon.CustomAlgorithm is selected.
44
32
  Image-handlers which want to support a custom algorithm must override this method."""
45
- raise NotImplementedError(f"Image-handler \"{type(self).__name__}\" does not define a custom algorithm for determining the latest version of image \"{image_name}\".")
33
+ raise ValueError(f"Image-handler \"{type(self).__name__}\" does not define a custom algorithm for determining the latest version of image \"{image_name}\".")
@@ -0,0 +1,46 @@
1
+ import re
2
+ from abc import abstractmethod
3
+ from packaging.version import Version
4
+ from ..GeneralUtilities import GeneralUtilities
5
+ from .AbstractImageHandler import AbstractImageHandler
6
+
7
+ class AbstractTagPatternImageHandler(AbstractImageHandler):
8
+ """Base for image-handlers whose tags consist of an optional prefix, a numeric version and an optional suffix, for example
9
+ "13.4-slim" (prefix "", version "13.4", suffix "-slim") or "v1.62.1-noble" (prefix "v", version "1.62.1", suffix "-noble").
10
+ Two tags have the same format if they have the same prefix, the same suffix and the same amount of version-parts. The suffix
11
+ must start with "-", "_" or "+" so that it can be separated from the version unambiguously."""
12
+
13
+ __tag_pattern=re.compile(r"^(?P<prefix>v?)(?P<version>\d+(?:\.\d+)*)(?P<suffix>(?:[-_+].*)?)$")
14
+
15
+ @abstractmethod
16
+ def _protected_accepts_tag_parts(self,image_name:str,prefix:str,suffix:str)->bool:
17
+ """Returns whether this handler is responsible for tags with the given prefix and suffix of the given image."""
18
+ raise NotImplementedError()#because it is abstract
19
+
20
+ def can_handle(self,image_name:str,tag:str)->bool:
21
+ tag_parts=self.__split_tag(tag)
22
+ if tag_parts is None:
23
+ return False
24
+ return self._protected_accepts_tag_parts(image_name,tag_parts[0],tag_parts[2])
25
+
26
+ def tag_has_same_format(self,image_name:str,tag:str,reference_tag:str)->bool:
27
+ tag_parts=self.__split_tag(tag)
28
+ reference_tag_parts=self.__split_tag(reference_tag)
29
+ if tag_parts is None or reference_tag_parts is None:
30
+ return False
31
+ same_prefix=tag_parts[0]==reference_tag_parts[0]
32
+ same_amount_of_version_parts=len(tag_parts[1].split("."))==len(reference_tag_parts[1].split("."))
33
+ same_suffix=tag_parts[2]==reference_tag_parts[2]
34
+ return same_prefix and same_amount_of_version_parts and same_suffix
35
+
36
+ def tag_to_version(self,image_name:str,tag:str)->Version:
37
+ tag_parts=self.__split_tag(tag)
38
+ GeneralUtilities.assert_condition(tag_parts is not None,f"Tag \"{tag}\" of image \"{image_name}\" does not have the format <prefix><version><suffix>.")
39
+ return Version(tag_parts[1])
40
+
41
+ def __split_tag(self,tag:str)->tuple[str,str,str]:
42
+ """Returns (prefix, version, suffix) of the tag or None if the tag does not have the format <prefix><version><suffix>."""
43
+ match=AbstractTagPatternImageHandler.__tag_pattern.match(tag)
44
+ if match is None:
45
+ return None
46
+ return (match.group("prefix"),match.group("version"),match.group("suffix"))
@@ -1,20 +1,11 @@
1
- from packaging.version import Version
2
1
  from ...GeneralUtilities import VersionEcholon
3
- from ..AbstractImageHandler import AbstractImageHandler
2
+ from ..AbstractTagPatternImageHandler import AbstractTagPatternImageHandler
4
3
 
5
- class ImageHandlerDebian(AbstractImageHandler):
4
+ class ImageHandlerDebian(AbstractTagPatternImageHandler):
5
+ """Handles the tags of debian without variant, for example "13.4"."""
6
6
 
7
- def can_handle(self,image_name:str)->bool:
8
- raise NotImplementedError()#TODO
9
-
10
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
11
- raise NotImplementedError()
12
-
13
- def tag_to_version(self,image_name:str,tag:str)->Version:
14
- raise NotImplementedError()
15
-
16
- def version_to_tag(self,image_name:str,version:Version)->str:
17
- raise NotImplementedError()
7
+ def _protected_accepts_tag_parts(self,image_name:str,prefix:str,suffix:str)->bool:
8
+ return image_name.lower()=="debian" and prefix=="" and suffix==""
18
9
 
19
10
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
20
11
  return VersionEcholon.LatestPatch
@@ -1,20 +1,11 @@
1
- from packaging.version import Version
2
1
  from ...GeneralUtilities import VersionEcholon
3
- from ..AbstractImageHandler import AbstractImageHandler
2
+ from ..AbstractTagPatternImageHandler import AbstractTagPatternImageHandler
4
3
 
5
- class ImageHandlerDebianSlim(AbstractImageHandler):
4
+ class ImageHandlerDebianSlim(AbstractTagPatternImageHandler):
5
+ """Handles the tags of the slim-variant of debian, for example "13.4-slim"."""
6
6
 
7
- def can_handle(self,image_name:str)->bool:
8
- raise NotImplementedError()#TODO
9
-
10
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
11
- raise NotImplementedError()
12
-
13
- def tag_to_version(self,image_name:str,tag:str)->Version:
14
- raise NotImplementedError()
15
-
16
- def version_to_tag(self,image_name:str,version:Version)->str:
17
- raise NotImplementedError()
7
+ def _protected_accepts_tag_parts(self,image_name:str,prefix:str,suffix:str)->bool:
8
+ return image_name.lower()=="debian" and prefix=="" and suffix=="-slim"
18
9
 
19
10
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
20
11
  return VersionEcholon.LatestPatch
@@ -1,20 +1,11 @@
1
- from packaging.version import Version
2
1
  from ...GeneralUtilities import VersionEcholon
3
- from ..AbstractImageHandler import AbstractImageHandler
2
+ from ..AbstractTagPatternImageHandler import AbstractTagPatternImageHandler
4
3
 
5
- class ImageHandlerGeneric(AbstractImageHandler):
4
+ class ImageHandlerGeneric(AbstractTagPatternImageHandler):
5
+ """Handles tags which consist of a numeric version and an optional suffix, for example "12.2.2", "1.2026.8" or "7.2-26.04_edge"."""
6
6
 
7
- def can_handle(self,image_name:str)->bool:
8
- raise NotImplementedError()#TODO
9
-
10
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
11
- raise NotImplementedError()
12
-
13
- def tag_to_version(self,image_name:str,tag:str)->Version:
14
- raise NotImplementedError()
15
-
16
- def version_to_tag(self,image_name:str,version:Version)->str:
17
- raise NotImplementedError()
7
+ def _protected_accepts_tag_parts(self,image_name:str,prefix:str,suffix:str)->bool:
8
+ return prefix==""
18
9
 
19
10
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
20
- raise NotImplementedError()
11
+ return VersionEcholon.LatestVersion
@@ -1,20 +1,11 @@
1
- from packaging.version import Version
2
1
  from ...GeneralUtilities import VersionEcholon
3
- from ..AbstractImageHandler import AbstractImageHandler
2
+ from ..AbstractTagPatternImageHandler import AbstractTagPatternImageHandler
4
3
 
5
- class ImageHandlerGenericV(AbstractImageHandler):
4
+ class ImageHandlerGenericV(AbstractTagPatternImageHandler):
5
+ """Handles tags which consist of the prefix "v", a numeric version and an optional suffix, for example "v1.41.2" or "v1.62.1-noble"."""
6
6
 
7
- def can_handle(self,image_name:str)->bool:
8
- raise NotImplementedError()#TODO
9
-
10
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
11
- raise NotImplementedError()
12
-
13
- def tag_to_version(self,image_name:str,tag:str)->Version:
14
- raise NotImplementedError()
15
-
16
- def version_to_tag(self,image_name:str,version:Version)->str:
17
- raise NotImplementedError()
7
+ def _protected_accepts_tag_parts(self,image_name:str,prefix:str,suffix:str)->bool:
8
+ return prefix=="v"
18
9
 
19
10
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
20
- raise NotImplementedError()
11
+ return VersionEcholon.LatestVersion
@@ -3,18 +3,17 @@ from ...GeneralUtilities import VersionEcholon
3
3
  from ..AbstractImageHandler import AbstractImageHandler
4
4
 
5
5
  class ImageHandlerGitlabCE(AbstractImageHandler):
6
+ """Recognizes the tags of GitLab ce (for example "18.5.1-ce.0"), so that they are not handled by a generic handler: an update of
7
+ GitLab must respect the required upgrade-stops, which is not implemented yet."""
6
8
 
7
- def can_handle(self,image_name:str)->bool:
8
- raise NotImplementedError()#TODO
9
+ def can_handle(self,image_name:str,tag:str)->bool:
10
+ return "gitlab" in image_name.lower() and tag.endswith("-ce.0")
9
11
 
10
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
11
- raise NotImplementedError()
12
+ def tag_has_same_format(self,image_name:str,tag:str,reference_tag:str)->bool:
13
+ raise NotImplementedError(f"Updating the tag of image \"{image_name}\" (GitLab ce) is not implemented yet.")
12
14
 
13
15
  def tag_to_version(self,image_name:str,tag:str)->Version:
14
- raise NotImplementedError()
15
-
16
- def version_to_tag(self,image_name:str,version:Version)->str:
17
- raise NotImplementedError()
16
+ raise NotImplementedError(f"Updating the tag of image \"{image_name}\" (GitLab ce) is not implemented yet.")
18
17
 
19
18
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
20
19
  return VersionEcholon.CustomAlgorithm
@@ -3,18 +3,17 @@ from ...GeneralUtilities import VersionEcholon
3
3
  from ..AbstractImageHandler import AbstractImageHandler
4
4
 
5
5
  class ImageHandlerGitlabEE(AbstractImageHandler):
6
+ """Recognizes the tags of GitLab ee (for example "18.5.1-ee.0"), so that they are not handled by a generic handler: an update of
7
+ GitLab must respect the required upgrade-stops, which is not implemented yet."""
6
8
 
7
- def can_handle(self,image_name:str)->bool:
8
- raise NotImplementedError()#TODO
9
+ def can_handle(self,image_name:str,tag:str)->bool:
10
+ return "gitlab" in image_name.lower() and tag.endswith("-ee.0")
9
11
 
10
- def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
11
- raise NotImplementedError()
12
+ def tag_has_same_format(self,image_name:str,tag:str,reference_tag:str)->bool:
13
+ raise NotImplementedError(f"Updating the tag of image \"{image_name}\" (GitLab ee) is not implemented yet.")
12
14
 
13
15
  def tag_to_version(self,image_name:str,tag:str)->Version:
14
- raise NotImplementedError()
15
-
16
- def version_to_tag(self,image_name:str,version:Version)->str:
17
- raise NotImplementedError()
16
+ raise NotImplementedError(f"Updating the tag of image \"{image_name}\" (GitLab ee) is not implemented yet.")
18
17
 
19
18
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
20
19
  return VersionEcholon.CustomAlgorithm