Skip to content

Commit e2786ed

Browse files
committed
refactoring some items
1 parent ac81155 commit e2786ed

File tree

1 file changed

+9
-46
lines changed

1 file changed

+9
-46
lines changed

jamftf/config_ingest.py

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,6 @@
2828

2929
def parse_config_file(path: str) -> list[Resource]:
3030
"""
31-
Parse a configuration file and return a list of Resource objects.
32-
33-
This function processes a filepath, extracting resource
34-
definitions and any exclusion rules. It performs validation on the configuration
35-
structure and creates Resource objects based on the provided specifications.
36-
37-
Args:
38-
path (string): A dictionary containing the configuration data.
39-
40-
Returns:
41-
List[Resource]: A list of instantiated Resource objects.
42-
43-
Raises:
44-
KeyError: If the required resources block is missing from the config.
45-
DataError: If there are invalid keys or missing required keys in the config.
46-
InvalidResourceTypeError: If an invalid resource type is specified.
47-
48-
The function expects the following structure in the config_json:
49-
- An optional 'exclude_block' key for specifying resources to exclude.
50-
- A required 'resources' key containing resource definitions.
51-
52-
Each resource definition should include 'active', 'validate', and other
53-
required keys as specified in REQUIRED_RESOURCE_CONFIG_KEYS.
5431
"""
5532

5633
# // TODO sanitise the path
@@ -66,29 +43,6 @@ def parse_config_file(path: str) -> list[Resource]:
6643

6744
def parse_config_dict(config_json: dict) -> List[Resource]:
6845
"""
69-
Parse a configuration file and return a list of Resource objects.
70-
71-
This function processes a JSON configuration dictionary, extracting resource
72-
definitions and any exclusion rules. It performs validation on the configuration
73-
structure and creates Resource objects based on the provided specifications.
74-
75-
Args:
76-
config_json (dict): A dictionary containing the configuration data.
77-
78-
Returns:
79-
List[Resource]: A list of instantiated Resource objects.
80-
81-
Raises:
82-
KeyError: If the required resources block is missing from the config.
83-
DataError: If there are invalid keys or missing required keys in the config.
84-
InvalidResourceTypeError: If an invalid resource type is specified.
85-
86-
The function expects the following structure in the config_json:
87-
- An optional 'exclude_block' key for specifying resources to exclude.
88-
- A required 'resources' key containing resource definitions.
89-
90-
Each resource definition should include 'active', 'validate', and other
91-
required keys as specified in REQUIRED_RESOURCE_CONFIG_KEYS.
9246
"""
9347
out = []
9448
exclude_block = {}
@@ -107,30 +61,39 @@ def parse_config_dict(config_json: dict) -> List[Resource]:
10761
res_block: dict = config_json[RESOURCE_BLOCK_CONFIG_KEY]
10862
k: str
10963
v: dict
64+
65+
# for res key, keys
11066
for k, v in res_block.items():
11167

68+
# If invalid resource
11269
if k not in ALL_RESOURCE_TYPES:
11370
raise InvalidResourceTypeError(f"invalid resource type: {k}")
11471

72+
# If it contains an invalid config key
11573
for i in v:
11674
if i not in VALID_RESOURCE_CONFIG_KEYS:
11775
raise DataError(f"invalid config key: {i}")
11876

77+
# If missing a required config key
11978
for i in REQUIRED_RESOURCE_CONFIG_KEYS:
12079
if i not in v:
12180
raise DataError(f"missing required config key: {i}")
12281

82+
# If the resource should be validated
12383
validate = v["validate"]
12484
if not isinstance(validate, bool):
12585
raise AssertionError(f"validate key is of the wrong type: {validate}, {type(validate)}")
12686

87+
# If the resource should be prossessed.
12788
active = v["active"]
12889
if not isinstance(active, bool):
12990
raise AssertionError(f"active key is of the wrong type: {active}, {type(active)}")
13091

92+
# If inactive, skip
13193
if not active:
13294
continue
13395

96+
13497
out.append(
13598
RESOURCE_TYPE_OBJECT_MAP[k](
13699
options=Options().from_json(v),

0 commit comments

Comments
 (0)