Skip to content

Commit 6220d20

Browse files
committed
fix config merging; fix config loading
1 parent 99343b3 commit 6220d20

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

cycode/cli/user_settings/configuration_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def add_exclusion(self, scope: str, scan_type: str, exclusion_type: str, value:
8282
@staticmethod
8383
def _merge_exclusions(local_exclusions: dict, global_exclusions: dict) -> dict:
8484
keys = set(list(local_exclusions.keys()) + list(global_exclusions.keys()))
85-
return {key: local_exclusions.get(key, []) + global_exclusions.get(key, []) for key in keys}
85+
return {key: (local_exclusions.get(key) or []) + (global_exclusions.get(key) or []) for key in keys}
8686

8787
def get_or_create_installation_id(self) -> str:
8888
config_file_manager = self.get_config_file_manager()

cycode/cli/utils/yaml_utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import yaml
66

7+
from cycode.logger import get_logger
8+
9+
logger = get_logger('YAML Utils')
10+
711

812
def _deep_update(source: dict[Hashable, Any], overrides: dict[Hashable, Any]) -> dict[Hashable, Any]:
913
for key, value in overrides.items():
@@ -15,10 +19,16 @@ def _deep_update(source: dict[Hashable, Any], overrides: dict[Hashable, Any]) ->
1519
return source
1620

1721

18-
def _yaml_safe_load(file: TextIO) -> dict[Hashable, Any]:
22+
def _yaml_object_safe_load(file: TextIO) -> dict[Hashable, Any]:
1923
# loader.get_single_data could return None
2024
loaded_file = yaml.safe_load(file)
21-
if loaded_file is None:
25+
26+
if not isinstance(loaded_file, dict):
27+
# forbid literals at the top level
28+
logger.debug(
29+
'YAML file does not contain a dictionary at the top level: %s',
30+
{'filename': file.name, 'actual_type': type(loaded_file)},
31+
)
2232
return {}
2333

2434
return loaded_file
@@ -29,7 +39,7 @@ def read_yaml_file(filename: str) -> dict[Hashable, Any]:
2939
return {}
3040

3141
with open(filename, encoding='UTF-8') as file:
32-
return _yaml_safe_load(file)
42+
return _yaml_object_safe_load(file)
3343

3444

3545
def write_yaml_file(filename: str, content: dict[Hashable, Any]) -> None:

0 commit comments

Comments
 (0)