1
1
from pathlib import Path
2
2
from typing import Any , Union , Type
3
- #from contentctl import contentctl
4
3
from contentctl .input .yml_reader import YmlReader
5
- from contentctl .objects .config import test_common , test_servers , test
4
+ from contentctl .objects .config import test_common , test , test_servers
6
5
from contentctl .objects .security_content_object import SecurityContentObject
6
+ from contentctl .input .director import DirectorOutputDto
7
7
8
-
9
- def configFromFile (path :Path = Path ("contentctl.yml" ), config : dict [str ,Any ]= {},
10
- configType :Type [Union [test ,test_servers ]]= test )-> Union [test ,test_servers ]:
8
+ def config_from_file (path :Path = Path ("contentctl.yml" ), config : dict [str ,Any ]= {},
9
+ configType :Type [Union [test ,test_servers ]]= test )-> test_common :
11
10
12
11
"""
13
12
Fetch a configuration object that can be used for a number of different contentctl
@@ -36,23 +35,23 @@ def configFromFile(path:Path=Path("contentctl.yml"), config: dict[str,Any]={},
36
35
except Exception as e :
37
36
raise Exception (f"Failed to load contentctl configuration from file '{ path } ': { str (e )} " )
38
37
39
- #Apply settings that have been overridden from the ones in the file
38
+ # Apply settings that have been overridden from the ones in the file
40
39
try :
41
40
yml_dict .update (config )
42
41
except Exception as e :
43
42
raise Exception (f"Failed updating dictionary of values read from file '{ path } '"
44
43
f" with the dictionary of arguments passed: { str (e )} " )
45
44
46
45
# The function below will throw its own descriptive exception if it fails
47
- configObject = configFromDict (yml_dict , configType = configType )
46
+ configObject = config_from_dict (yml_dict , configType = configType )
48
47
49
48
return configObject
50
49
51
50
52
51
53
52
54
- def configFromDict (config : dict [str ,Any ]= {},
55
- configType :Type [Union [test ,test_servers ]]= test )-> Union [ test , test_servers ] :
53
+ def config_from_dict (config : dict [str ,Any ]= {},
54
+ configType :Type [Union [test ,test_servers ]]= test )-> test_common :
56
55
"""
57
56
Fetch a configuration object that can be used for a number of different contentctl
58
57
operations including validate, build, inspect, test, and test_servers. A dict will
@@ -79,7 +78,7 @@ def configFromDict(config: dict[str,Any]={},
79
78
return test_object
80
79
81
80
82
- def updateConfig (config :Union [test ,test_servers ], ** key_value_updates :dict [str ,Any ])-> Union [ test , test_servers ] :
81
+ def update_config (config :Union [test ,test_servers ], ** key_value_updates :dict [str ,Any ])-> test_common :
83
82
84
83
"""Update any relevant keys in a config file with the specified values.
85
84
Full validation will be performed after this update and descriptive errors
@@ -109,8 +108,8 @@ def updateConfig(config:Union[test,test_servers], **key_value_updates:dict[str,A
109
108
# Collect any errors that may occur
110
109
errors :list [Exception ] = []
111
110
112
- #We need to do this one by one because the extra:forbid argument does not appear to
113
- #be respected, but validate_assignmen
111
+ # We need to do this one by one because the extra:forbid argument does not appear to
112
+ # be respected at this time.
114
113
for key , value in key_value_updates .items ():
115
114
try :
116
115
setattr (config_copy ,key ,value )
@@ -123,8 +122,8 @@ def updateConfig(config:Union[test,test_servers], **key_value_updates:dict[str,A
123
122
return config_copy
124
123
125
124
126
- from contentctl . input . director import DirectorOutputDto
127
- def contentToDict (director :DirectorOutputDto )-> dict [str ,list [dict [str ,Any ]]]:
125
+
126
+ def content_to_dict (director :DirectorOutputDto )-> dict [str ,list [dict [str ,Any ]]]:
128
127
output_dict :dict [str ,list [dict [str ,Any ]]] = {}
129
128
for contentType in ['detections' ,'stories' ,'baselines' ,'investigations' ,
130
129
'playbooks' ,'macros' ,'lookups' ,'deployments' ,'ssa_detections' ]:
@@ -133,7 +132,6 @@ def contentToDict(director:DirectorOutputDto)->dict[str,list[dict[str,Any]]]:
133
132
t :list [SecurityContentObject ] = getattr (director ,contentType )
134
133
135
134
for item in t :
136
- print (item .model_dump ())
137
135
output_dict [contentType ].append (item .model_dump ())
138
136
return output_dict
139
137
0 commit comments