Coverage for /usr/local/lib/python3.10/site-packages/opal_common-0.0.0-py3.10.egg/opal_common/git_utils/bundle_utils.py: 0%
33 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 11:54 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 11:54 +0000
1from pathlib import Path
2from typing import List
4from opal_common.schemas.policy import DataModule, PolicyBundle, RegoModule
7class BundleUtils:
8 MAX_INDEX = 10000
10 @staticmethod
11 def sorted_policy_modules_to_load(
12 bundle: PolicyBundle, ignore=None
13 ) -> List[RegoModule]:
14 """Policy modules sorted according to manifest."""
15 manifest_paths = [Path(path) for path in bundle.manifest]
17 def key_function(module: RegoModule) -> int:
18 """This method reduces the module to a number that can be act as
19 sorting key.
21 the number is the index in the manifest list, so basically
22 we sort according to manifest.
23 """
24 try:
25 return manifest_paths.index(Path(module.path))
26 except ValueError:
27 return BundleUtils.MAX_INDEX
29 return sorted(bundle.policy_modules, key=key_function)
31 @staticmethod
32 def sorted_data_modules_to_load(bundle: PolicyBundle) -> List[DataModule]:
33 """Data modules sorted according to manifest."""
34 manifest_paths = [Path(path) for path in bundle.manifest]
36 def key_function(module: DataModule) -> int:
37 try:
38 return manifest_paths.index(Path(module.path))
39 except ValueError:
40 return BundleUtils.MAX_INDEX
42 return sorted(bundle.data_modules, key=key_function)
44 @staticmethod
45 def sorted_policy_modules_to_delete(bundle: PolicyBundle) -> List[Path]:
46 if bundle.deleted_files is None:
47 return []
48 # already sorted
49 return bundle.deleted_files.policy_modules
51 @staticmethod
52 def sorted_data_modules_to_delete(bundle: PolicyBundle) -> List[Path]:
53 if bundle.deleted_files is None:
54 return []
55 # already sorted
56 return bundle.deleted_files.data_modules