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.
- ScriptCollection/Executables.py +22 -3
- ScriptCollection/GeneralUtilities.py +42 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/AccountChecks.py +71 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/ContainerChecks.py +34 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/FileSystemChecks.py +141 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/KernelChecks.py +49 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/LogChecks.py +39 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/NetworkChecks.py +67 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/PackageIntegrityChecks.py +62 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/PersistenceChecks.py +99 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/ProcessChecks.py +88 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/SSHChecks.py +56 -0
- ScriptCollection/LinuxServerSecurityCheck/Checks/__init__.py +0 -0
- ScriptCollection/LinuxServerSecurityCheck/LinuxServerSecurityChecker.py +90 -0
- ScriptCollection/LinuxServerSecurityCheck/LinuxSystemAccess.py +85 -0
- ScriptCollection/LinuxServerSecurityCheck/PackageOwnershipLookup.py +42 -0
- ScriptCollection/LinuxServerSecurityCheck/SecurityCheckBase.py +19 -0
- ScriptCollection/LinuxServerSecurityCheck/SecurityFinding.py +19 -0
- ScriptCollection/LinuxServerSecurityCheck/SuspiciousCommandPatterns.py +46 -0
- ScriptCollection/LinuxServerSecurityCheck/SystemAccessBase.py +244 -0
- ScriptCollection/LinuxServerSecurityCheck/SystemEntities.py +45 -0
- ScriptCollection/LinuxServerSecurityCheck/__init__.py +0 -0
- ScriptCollection/OCIImages/AbstractImageHandler.py +14 -26
- ScriptCollection/OCIImages/AbstractTagPatternImageHandler.py +46 -0
- ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebian.py +5 -14
- ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebianSlim.py +5 -14
- ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGeneric.py +6 -15
- ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGenericV.py +6 -15
- ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGitlabCE.py +7 -8
- ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerGitlabEE.py +7 -8
- ScriptCollection/OCIImages/OCIImageManager.py +73 -68
- ScriptCollection/OCIImages/OCIRegistryClient.py +117 -0
- ScriptCollection/ScriptCollectionCore.py +9 -4
- ScriptCollection/TFCPS/Android/TFCPS_CodeUnitSpecific_Android.py +479 -0
- ScriptCollection/TFCPS/Android/__init__.py +0 -0
- ScriptCollection/TFCPS/CPP/TFCPS_CodeUnitSpecific_CPP.py +6 -5
- ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py +38 -4
- ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +4 -4
- ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py +1 -0
- ScriptCollection/TFCPS/Rust/CargoLockFile.py +151 -0
- ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py +5 -0
- ScriptCollection/TFCPS/SCTaskRunnerServer.py +55 -9
- ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py +6 -2
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py +14 -0
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +19 -0
- ScriptCollection/TFCPS/TFCPS_RemoteBuild.py +39 -11
- ScriptCollection/TFCPS/TFCPS_Tools_General.py +34 -2
- {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/METADATA +3 -3
- {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/RECORD +52 -27
- {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/entry_points.txt +1 -0
- {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.71.dist-info → scriptcollection-4.4.73.dist-info}/top_level.txt +0 -0
|
@@ -6,6 +6,7 @@ from ..ScriptCollectionCore import ScriptCollectionCore
|
|
|
6
6
|
from ..GeneralUtilities import VersionEcholon
|
|
7
7
|
from ..SCLog import LogLevel
|
|
8
8
|
from .AbstractImageHandler import AbstractImageHandler
|
|
9
|
+
from .OCIRegistryClient import OCIRegistryClient
|
|
9
10
|
from .ConcreteImageHandlers.ImageHandlerDebian import ImageHandlerDebian
|
|
10
11
|
from .ConcreteImageHandlers.ImageHandlerDebianSlim import ImageHandlerDebianSlim
|
|
11
12
|
from .ConcreteImageHandlers.ImageHandlerGeneric import ImageHandlerGeneric
|
|
@@ -17,6 +18,7 @@ class OCIImageManager:
|
|
|
17
18
|
|
|
18
19
|
__sc:ScriptCollectionCore=None
|
|
19
20
|
image_handler:list[AbstractImageHandler] = None
|
|
21
|
+
registry_client:OCIRegistryClient = None
|
|
20
22
|
#image-names for which it was already logged that the fallback-registry is used. The lookup happens for every image of
|
|
21
23
|
#the repository and often several times per build, so without this the same hint would flood the log.
|
|
22
24
|
__images_with_reported_fallback_registry:set[str] = None
|
|
@@ -30,21 +32,23 @@ class OCIImageManager:
|
|
|
30
32
|
self.__sc=sc
|
|
31
33
|
self.__images_with_reported_fallback_registry=set()
|
|
32
34
|
self.__availability_of_image=dict()
|
|
35
|
+
self.registry_client=OCIRegistryClient(self.__sc)
|
|
36
|
+
#the order matters: the first handler which can handle a tag is used, so the specific handlers have to be listed before the generic ones.
|
|
33
37
|
self.image_handler=[
|
|
34
|
-
ImageHandlerDebian(),
|
|
35
|
-
ImageHandlerDebianSlim(),
|
|
36
|
-
ImageHandlerGeneric(),
|
|
37
|
-
ImageHandlerGenericV(),
|
|
38
38
|
ImageHandlerGitlabCE(),
|
|
39
39
|
ImageHandlerGitlabEE(),
|
|
40
|
+
ImageHandlerDebianSlim(),
|
|
41
|
+
ImageHandlerDebian(),
|
|
42
|
+
ImageHandlerGenericV(),
|
|
43
|
+
ImageHandlerGeneric(),
|
|
40
44
|
]
|
|
41
45
|
|
|
42
46
|
@GeneralUtilities.check_arguments
|
|
43
|
-
def get_image_handler(self,image_name:str)->AbstractImageHandler:
|
|
44
|
-
for image_handler in self.image_handler:
|
|
45
|
-
if image_handler.can_handle(image_name):
|
|
47
|
+
def get_image_handler(self,image_name:str,tag:str)->AbstractImageHandler:
|
|
48
|
+
for image_handler in self.image_handler:
|
|
49
|
+
if image_handler.can_handle(image_name,tag):
|
|
46
50
|
return image_handler
|
|
47
|
-
raise ValueError(f"No image-handler available for image \"{image_name}\".")
|
|
51
|
+
raise ValueError(f"No image-handler available for tag \"{tag}\" of image \"{image_name}\".")
|
|
48
52
|
|
|
49
53
|
@GeneralUtilities.check_arguments
|
|
50
54
|
def get_repository_image_definition_file(self,repository:str)->str:
|
|
@@ -189,7 +193,10 @@ class OCIImageManager:
|
|
|
189
193
|
|
|
190
194
|
@GeneralUtilities.check_arguments
|
|
191
195
|
def update_default_tag_for_images_in_image_definitions_file(self,repository:str,search_in_custom_registry_only_if_available:bool)->None:
|
|
192
|
-
file
|
|
196
|
+
"""Updates the default-tag of every image in the image-definition-file of the repository to the latest available tag with the same format.
|
|
197
|
+
If search_in_custom_registry_only_if_available is True then only the custom registry which is defined for an image on this machine is
|
|
198
|
+
asked for newer tags, so that only tags are chosen which are available there; an image without custom registry keeps its tag then."""
|
|
199
|
+
file=self.get_repository_image_definition_file(repository)
|
|
193
200
|
GeneralUtilities.assert_file_exists(file)
|
|
194
201
|
lines=GeneralUtilities.read_nonempty_lines_from_file(file)
|
|
195
202
|
new_lines:list[str]=[]
|
|
@@ -205,41 +212,61 @@ class OCIImageManager:
|
|
|
205
212
|
registry_address=line_parts[1]
|
|
206
213
|
default_tag=line_parts[2]
|
|
207
214
|
tag=default_tag
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if not search_in_custom_registry_only_if_available:
|
|
219
|
-
addresses_to_check.append(registry_address)
|
|
220
|
-
newest_versions:set[Version]={default_tag}
|
|
221
|
-
current_version=Version(default_tag)
|
|
222
|
-
for address in addresses_to_check:
|
|
223
|
-
newest_versions_for_address=self.get_latest_of_image(image_name,address,current_version,VersionEcholon.LatestVersion)
|
|
224
|
-
if newest_versions_for_address is not None:
|
|
225
|
-
newest_versions.update(newest_versions_for_address)
|
|
226
|
-
GeneralUtilities.assert_condition(len(newest_versions)>0,f"Could not find any version for image {image_name} in registry {registry_address}.")
|
|
227
|
-
newest_version=max(newest_versions)
|
|
228
|
-
tag=self.version_to_tag(image_name,newest_version)
|
|
229
|
-
except Exception as e:
|
|
230
|
-
self.__sc.log.log(f"Could not get tag for image {image_name} from registry {registry_address}. Reason: {str(e)}",LogLevel.Warning)
|
|
215
|
+
addresses_to_check=self.__get_registry_addresses_to_search_for_newer_tags(image_name,registry_address,search_in_custom_registry_only_if_available)
|
|
216
|
+
if len(addresses_to_check)==0:
|
|
217
|
+
self.__sc.log.log(f"The tag of image \"{image_name}\" is not updated because no custom registry is defined for it in \"{self.get_global_docker_image_registries_file()}\".",LogLevel.Warning)
|
|
218
|
+
else:
|
|
219
|
+
try:
|
|
220
|
+
tag=self.get_latest_tag_of_image(image_name,addresses_to_check,default_tag,VersionEcholon.LatestVersion)
|
|
221
|
+
except Exception as e:
|
|
222
|
+
self.__sc.log.log(f"Could not determine the latest tag of image \"{image_name}\" using the registries {', '.join(addresses_to_check)}. Reason: {type(e).__name__}: {str(e)}",LogLevel.Warning)
|
|
223
|
+
if tag!=default_tag:
|
|
224
|
+
self.__sc.log.log(f"Update tag of image \"{image_name}\" from \"{default_tag}\" to \"{tag}\".",LogLevel.Information)
|
|
231
225
|
new_lines.append(f"{image_name};{registry_address};{tag}")
|
|
232
226
|
GeneralUtilities.write_lines_to_file(file,new_lines)
|
|
233
227
|
|
|
234
228
|
@GeneralUtilities.check_arguments
|
|
235
|
-
def
|
|
236
|
-
result=
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
229
|
+
def __get_registry_addresses_to_search_for_newer_tags(self,image_name:str,upstream_registry_address:str,search_in_custom_registry_only_if_available:bool)->list[str]:
|
|
230
|
+
result:list[str]=[]
|
|
231
|
+
if self.custom_registry_is_defined(image_name):
|
|
232
|
+
#the custom registry-address is used directly (and not get_registry_address_for_image) because this function does not
|
|
233
|
+
#pull an image but asks the registry which tags it has, so it does not matter whether that registry currently provides
|
|
234
|
+
#the image with the tag which is defined at the moment.
|
|
235
|
+
result.append(self.get_custom_registry_address_for_image(image_name))
|
|
236
|
+
if not search_in_custom_registry_only_if_available:
|
|
237
|
+
result.append(upstream_registry_address)
|
|
238
|
+
return result
|
|
239
|
+
|
|
240
|
+
@GeneralUtilities.check_arguments
|
|
241
|
+
def get_latest_tag_of_image(self,image_name:str,registry_addresses:list[str],current_tag:str,echolon:VersionEcholon)->str:
|
|
242
|
+
"""Returns the tag the image should be updated to according to the echolon, considering the tags of all given registry-addresses
|
|
243
|
+
(always without tag, for example "docker.io/library/debian").
|
|
244
|
+
Only tags with the same format as the current tag are candidates (see AbstractImageHandler.tag_has_same_format). The current tag is
|
|
245
|
+
always a candidate, so the result is never a downgrade."""
|
|
246
|
+
image_handler=self.get_image_handler(image_name,current_tag)
|
|
247
|
+
if echolon==VersionEcholon.NoUpdate:
|
|
248
|
+
return current_tag
|
|
249
|
+
candidate_tags:list[str]=[current_tag]
|
|
250
|
+
for registry_address in registry_addresses:
|
|
251
|
+
for tag in self.registry_client.get_tags(registry_address):
|
|
252
|
+
if tag not in candidate_tags and image_handler.tag_has_same_format(image_name,tag,current_tag):
|
|
253
|
+
candidate_tags.append(tag)
|
|
254
|
+
if echolon==VersionEcholon.CustomAlgorithm:
|
|
255
|
+
return image_handler.get_latest_tag_custom(image_name,current_tag,candidate_tags)
|
|
256
|
+
tags_by_version:dict[Version,str]={}
|
|
257
|
+
for tag in candidate_tags:
|
|
258
|
+
#setdefault, because different tags can represent the same version (like "13.4" and "13.04"); then the first one (the current tag if affected) is used.
|
|
259
|
+
tags_by_version.setdefault(image_handler.tag_to_version(image_name,tag),tag)
|
|
260
|
+
current_version=image_handler.tag_to_version(image_name,current_tag)
|
|
261
|
+
return tags_by_version[self.choose_version(set(tags_by_version.keys()),current_version,echolon)]
|
|
262
|
+
|
|
263
|
+
@GeneralUtilities.check_arguments
|
|
264
|
+
def choose_version(self,available_versions:set[Version],current_version:Version,echolon:VersionEcholon)->Version:
|
|
265
|
+
"""Returns the version out of the available versions which should be used according to the echolon.
|
|
266
|
+
available_versions must contain current_version. The echolons NoUpdate and CustomAlgorithm are not handled here because they do
|
|
267
|
+
not choose out of the available versions."""
|
|
268
|
+
GeneralUtilities.assert_condition(current_version in available_versions,f"The available versions do not contain the current version {current_version}.")
|
|
269
|
+
result:Version=None
|
|
243
270
|
match echolon:
|
|
244
271
|
case VersionEcholon.LatestPatch:#caution: this never updates the minor or major version
|
|
245
272
|
#take the latest available patch-version for the current minor-version of the image.
|
|
@@ -260,11 +287,8 @@ class OCIImageManager:
|
|
|
260
287
|
case VersionEcholon.LatestVersion:#usual case for most images
|
|
261
288
|
#take the latest available version of the image.
|
|
262
289
|
result=max(available_versions)
|
|
263
|
-
case
|
|
264
|
-
|
|
265
|
-
result=image_handler.get_latest_version_custom(image_name,registry_address,current_version)
|
|
266
|
-
case VersionEcholon.NoUpdate:
|
|
267
|
-
result = current_version
|
|
290
|
+
case _:
|
|
291
|
+
raise ValueError(f"Echolon \"{echolon.name}\" does not choose a version out of the available versions.")
|
|
268
292
|
return result
|
|
269
293
|
|
|
270
294
|
@GeneralUtilities.check_arguments
|
|
@@ -292,24 +316,6 @@ class OCIImageManager:
|
|
|
292
316
|
if len(higher_values)==0:
|
|
293
317
|
return None
|
|
294
318
|
return min(higher_values)
|
|
295
|
-
|
|
296
|
-
@GeneralUtilities.check_arguments
|
|
297
|
-
def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
|
|
298
|
-
"""registry_address must have one of these formats: "myregistry.example.com/debian" or "docker.io/debian" or "docker.io/myuser/debian".
|
|
299
|
-
returns something like ["13.2-slim", "13.2", "13.3-slim", "13.3"]."""
|
|
300
|
-
return self.get_image_handler(image_name).get_available_tags_of_image(image_name,registry_address)
|
|
301
|
-
|
|
302
|
-
@GeneralUtilities.check_arguments
|
|
303
|
-
def tag_to_version(self,image_name:str,tag:str)->Version:
|
|
304
|
-
"""registry_address must have one of these formats: "myregistry.example.com/debian" or "docker.io/debian" or "docker.io/myuser/debian"."""
|
|
305
|
-
return self.get_image_handler(image_name).tag_to_version(image_name, tag)
|
|
306
|
-
|
|
307
|
-
@GeneralUtilities.check_arguments
|
|
308
|
-
def version_to_tag(self,image_name:str,version:Version)->str:
|
|
309
|
-
"""registry_address must have one of these formats: "myregistry.example.com/debian" or "docker.io/debian" or "docker.io/myuser/debian".
|
|
310
|
-
returns something like "13.3-slim".
|
|
311
|
-
If there are multiple tags available for a certain version then the image-handler decides which one will be returned."""
|
|
312
|
-
return self.get_image_handler(image_name).version_to_tag(image_name,version)
|
|
313
319
|
|
|
314
320
|
@GeneralUtilities.check_arguments
|
|
315
321
|
def get_images_used_in_docker_compose_file(self,docker_compose_file:str)->dict[str,tuple[str,str,str]]:#returns dict[service_name,[image_name,image_address,current_tag]]
|
|
@@ -346,15 +352,14 @@ class OCIImageManager:
|
|
|
346
352
|
image_name=service_information[0]
|
|
347
353
|
image_address=service_information[1]
|
|
348
354
|
current_tag=service_information[2]
|
|
349
|
-
image_handler=self.get_image_handler(image_name)
|
|
355
|
+
image_handler=self.get_image_handler(image_name,current_tag)
|
|
350
356
|
effective_echolon=per_image_echolons.get(image_name,default_echolon)
|
|
351
357
|
if effective_echolon is None:
|
|
352
|
-
effective_echolon=image_handler.get_default_echolon_for_update()
|
|
358
|
+
effective_echolon=image_handler.get_default_echolon_for_update(image_name)
|
|
353
359
|
if verbose:
|
|
354
360
|
self.__sc.log.log(f"Service \"{service}\": checking image \"{image_address}:{current_tag}\" using echolon \"{effective_echolon.name}\".",LogLevel.Information)
|
|
355
|
-
|
|
356
|
-
new_tag
|
|
357
|
-
if new_tag is not None and new_tag != current_tag:
|
|
361
|
+
new_tag=self.get_latest_tag_of_image(image_name,[image_address],current_tag,effective_echolon)
|
|
362
|
+
if new_tag != current_tag:
|
|
358
363
|
new_image_reference = f"{image_address}:{new_tag}"
|
|
359
364
|
if verbose:
|
|
360
365
|
self.__sc.log.log(f"Service \"{service}\": updating image \"{image_address}\" from tag \"{current_tag}\" to tag \"{new_tag}\".",LogLevel.Information)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import re
|
|
3
|
+
from urllib.parse import urlencode
|
|
4
|
+
import requests
|
|
5
|
+
from ..GeneralUtilities import GeneralUtilities
|
|
6
|
+
from ..ScriptCollectionCore import ScriptCollectionCore
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OCIRegistryClient:
|
|
10
|
+
"""Reads information about images from OCI-registries using the OCI-distribution-api (see
|
|
11
|
+
https://github.com/opencontainers/distribution-spec/blob/main/spec.md ), which is implemented by docker-hub, ghcr.io,
|
|
12
|
+
quay.io, mcr.microsoft.com and by a custom deployed docker-registry as well. So there is one implementation for all registries
|
|
13
|
+
and no registry-specific api is used."""
|
|
14
|
+
|
|
15
|
+
__sc: ScriptCollectionCore = None
|
|
16
|
+
__docker_hub_address: str = "docker.io"
|
|
17
|
+
__docker_hub_api_host: str = "registry-1.docker.io"
|
|
18
|
+
__page_size: int = 1000
|
|
19
|
+
__timeout_in_seconds: int = 30
|
|
20
|
+
|
|
21
|
+
def __init__(self, sc: ScriptCollectionCore):
|
|
22
|
+
self.__sc = sc
|
|
23
|
+
|
|
24
|
+
@GeneralUtilities.check_arguments
|
|
25
|
+
def split_registry_address(self, registry_address: str) -> tuple[str, str]:
|
|
26
|
+
"""Splits an image-address without tag into the host of the registry and the repository inside the registry, following the
|
|
27
|
+
rules of docker: the first segment is a host if it contains a "." or a ":" or if it is "localhost", otherwise the image is
|
|
28
|
+
located on docker-hub. On docker-hub an image without namespace belongs to the namespace "library".
|
|
29
|
+
Examples: "docker.io/debian" -> ("docker.io", "library/debian"), "aniondev/scbuilder" -> ("docker.io", "aniondev/scbuilder"),
|
|
30
|
+
"myregistry.example.com:5000/debian" -> ("myregistry.example.com:5000", "debian")."""
|
|
31
|
+
segments = registry_address.split("/")
|
|
32
|
+
first_segment = segments[0]
|
|
33
|
+
if len(segments) > 1 and ("." in first_segment or ":" in first_segment or first_segment == "localhost"):
|
|
34
|
+
host = first_segment
|
|
35
|
+
repository = "/".join(segments[1:])
|
|
36
|
+
else:
|
|
37
|
+
host = OCIRegistryClient.__docker_hub_address
|
|
38
|
+
repository = registry_address
|
|
39
|
+
if host == OCIRegistryClient.__docker_hub_address and "/" not in repository:
|
|
40
|
+
repository = f"library/{repository}"
|
|
41
|
+
return (host, repository)
|
|
42
|
+
|
|
43
|
+
@GeneralUtilities.check_arguments
|
|
44
|
+
def get_tags(self, registry_address: str) -> list[str]:
|
|
45
|
+
"""Returns all tags of the image which is located at the given image-address (without tag), for example
|
|
46
|
+
"docker.io/library/debian" or "ghcr.io/betterleaks/betterleaks".
|
|
47
|
+
If credentials for the registry are defined on this machine (see
|
|
48
|
+
ScriptCollectionCore.get_docker_registry_credentials_from_environment_variables) then they are used, otherwise the registry is
|
|
49
|
+
accessed anonymously."""
|
|
50
|
+
host, repository = self.split_registry_address(registry_address)
|
|
51
|
+
api_host = OCIRegistryClient.__docker_hub_api_host if host == OCIRegistryClient.__docker_hub_address else host
|
|
52
|
+
credentials = self.__get_credentials(host)
|
|
53
|
+
result: list[str] = []
|
|
54
|
+
url = f"https://{api_host}/v2/{repository}/tags/list?n={OCIRegistryClient.__page_size}"
|
|
55
|
+
authorization_header: str = None
|
|
56
|
+
while url is not None:
|
|
57
|
+
response = self.send_get_request(url, authorization_header)
|
|
58
|
+
if response.status_code == 401 and authorization_header is None:
|
|
59
|
+
authorization_header = self.__get_authorization_header(response.headers.get("WWW-Authenticate"), credentials)
|
|
60
|
+
response = self.send_get_request(url, authorization_header)
|
|
61
|
+
response.raise_for_status()
|
|
62
|
+
result.extend(response.json().get("tags") or [])
|
|
63
|
+
url = self.__get_url_of_next_page(api_host, response)
|
|
64
|
+
return result
|
|
65
|
+
|
|
66
|
+
@GeneralUtilities.check_arguments
|
|
67
|
+
def send_get_request(self, url: str, authorization_header: str) -> requests.Response:
|
|
68
|
+
"""Sends a get-request. This is the only function of this class which communicates with a server."""
|
|
69
|
+
headers = {}
|
|
70
|
+
if authorization_header is not None:
|
|
71
|
+
headers["Authorization"] = authorization_header
|
|
72
|
+
return requests.get(url, headers=headers, timeout=OCIRegistryClient.__timeout_in_seconds)
|
|
73
|
+
|
|
74
|
+
@GeneralUtilities.check_arguments
|
|
75
|
+
def __get_credentials(self, host: str) -> tuple[str, str]:
|
|
76
|
+
"""Returns (username, password) of the registry with the given host or None if no credentials are defined for it."""
|
|
77
|
+
for address, username, password in self.__sc.get_docker_registry_credentials_from_environment_variables():
|
|
78
|
+
if address.rstrip("/") == host:
|
|
79
|
+
return (username, password)
|
|
80
|
+
return None
|
|
81
|
+
|
|
82
|
+
@GeneralUtilities.check_arguments
|
|
83
|
+
def __get_authorization_header(self, authentication_challenge: str, credentials: tuple[str, str]) -> str:
|
|
84
|
+
"""Returns the value of the authorization-header which answers the given challenge (the WWW-Authenticate-header of a 401-response)."""
|
|
85
|
+
GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(authentication_challenge), "The registry requires authentication but does not tell how.")
|
|
86
|
+
scheme = authentication_challenge.split(" ", 1)[0].lower()
|
|
87
|
+
if scheme == "basic":
|
|
88
|
+
GeneralUtilities.assert_condition(credentials is not None, "The registry requires basic-authentication but no credentials are defined for it.")
|
|
89
|
+
return self.__get_basic_authorization_header(credentials)
|
|
90
|
+
GeneralUtilities.assert_condition(scheme == "bearer", f"Unsupported authentication-scheme in challenge \"{authentication_challenge}\".")
|
|
91
|
+
parameters = dict(re.findall(r'(\w+)="([^"]*)"', authentication_challenge))
|
|
92
|
+
GeneralUtilities.assert_condition("realm" in parameters, f"No realm defined in challenge \"{authentication_challenge}\".")
|
|
93
|
+
token_parameters = {key: value for key, value in parameters.items() if key in ("service", "scope")}
|
|
94
|
+
token_url = f"{parameters['realm']}?{urlencode(token_parameters)}"
|
|
95
|
+
token_authorization_header = None if credentials is None else self.__get_basic_authorization_header(credentials)
|
|
96
|
+
response = self.send_get_request(token_url, token_authorization_header)
|
|
97
|
+
response.raise_for_status()
|
|
98
|
+
token_data = response.json()
|
|
99
|
+
token = token_data.get("token") or token_data.get("access_token")
|
|
100
|
+
GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(token), f"The token-service \"{parameters['realm']}\" did not return a token.")
|
|
101
|
+
return f"Bearer {token}"
|
|
102
|
+
|
|
103
|
+
@GeneralUtilities.check_arguments
|
|
104
|
+
def __get_basic_authorization_header(self, credentials: tuple[str, str]) -> str:
|
|
105
|
+
encoded_credentials = base64.b64encode(f"{credentials[0]}:{credentials[1]}".encode("utf-8")).decode("ascii")
|
|
106
|
+
return f"Basic {encoded_credentials}"
|
|
107
|
+
|
|
108
|
+
@GeneralUtilities.check_arguments
|
|
109
|
+
def __get_url_of_next_page(self, api_host: str, response: requests.Response) -> str:
|
|
110
|
+
"""Returns the url of the next page of a paginated tag-list or None if the response contains the last page."""
|
|
111
|
+
next_link = response.links.get("next")
|
|
112
|
+
if next_link is None:
|
|
113
|
+
return None
|
|
114
|
+
next_url: str = next_link["url"]
|
|
115
|
+
if next_url.startswith("/"):
|
|
116
|
+
next_url = f"https://{api_host}{next_url}"
|
|
117
|
+
return next_url
|
|
@@ -41,7 +41,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
|
|
|
41
41
|
from .ProgramRunnerPopen import ProgramRunnerPopen
|
|
42
42
|
from .SCLog import SCLog, LogLevel
|
|
43
43
|
|
|
44
|
-
version = "4.4.
|
|
44
|
+
version = "4.4.73"
|
|
45
45
|
__version__ = version
|
|
46
46
|
|
|
47
47
|
class VSCodeWorkspaceShellTask:
|
|
@@ -4396,14 +4396,19 @@ OCR-content:
|
|
|
4396
4396
|
return False
|
|
4397
4397
|
return True
|
|
4398
4398
|
|
|
4399
|
-
def reclaim_space_from_docker(self,remove_containers:bool,
|
|
4399
|
+
def reclaim_space_from_docker(self,remove_containers:bool,remove_named_volumes:bool,remove_images:bool, amount_of_attempts: int = 5):
|
|
4400
4400
|
self.log.log("Reclaim disk space from docker...",LogLevel.Debug)
|
|
4401
4401
|
if remove_containers:
|
|
4402
4402
|
self.run_program_with_retry("docker","container prune -f",amount_of_attempts=amount_of_attempts)
|
|
4403
|
-
|
|
4404
|
-
|
|
4403
|
+
self.run_program_with_retry("docker","network prune -f",amount_of_attempts=amount_of_attempts)# networks are only unused when the containers which used them are removed.
|
|
4404
|
+
if remove_named_volumes:
|
|
4405
|
+
self.run_program_with_retry("docker","volume prune -a -f",amount_of_attempts=amount_of_attempts)# since docker 23 "volume prune" without "-a" only removes anonymous volumes.
|
|
4406
|
+
else:
|
|
4407
|
+
self.run_program_with_retry("docker","volume prune -f",amount_of_attempts=amount_of_attempts)# removes only anonymous volumes.
|
|
4405
4408
|
if remove_images:
|
|
4406
4409
|
self.run_program_with_retry("docker","image prune -a -f",amount_of_attempts=amount_of_attempts)
|
|
4410
|
+
else:
|
|
4411
|
+
self.run_program_with_retry("docker","image prune -f",amount_of_attempts=amount_of_attempts)# removes only dangling images (untagged leftovers of builds).
|
|
4407
4412
|
self.run_program_with_retry("docker","builder prune -a -f",amount_of_attempts=amount_of_attempts)
|
|
4408
4413
|
self.run_program_with_retry("docker","buildx prune -a -f",amount_of_attempts=amount_of_attempts,throw_exception_if_exitcode_is_not_zero=False) # buildx prune is not available on every machine.
|
|
4409
4414
|
self.run_program_with_retry("docker","system df",print_live_output=self.log.loglevel==LogLevel.Debug,amount_of_attempts=amount_of_attempts)
|