2
2
import shutil
3
3
import os
4
4
import pathlib
5
-
6
- from pydantic import RootModel
7
5
from contentctl .objects .config import test
8
6
from contentctl .output .yml_writer import YmlWriter
9
7
@@ -17,26 +15,44 @@ def execute(self, config: test) -> None:
17
15
18
16
YmlWriter .writeYmlFile (str (config .path / 'contentctl.yml' ), config .model_dump ())
19
17
18
+
20
19
#Create the following empty directories:
21
- for emptyDir in ['lookups' , 'baselines' , 'docs' , 'reporting' , 'investigations' ]:
20
+ for emptyDir in ['lookups' , 'baselines' , 'data_sources' , 'docs' , 'reporting' , 'investigations' ,
21
+ 'detections/application' , 'detections/cloud' , 'detections/endpoint' ,
22
+ 'detections/network' , 'detections/web' , 'macros' , 'stories' ]:
22
23
#Throw an error if this directory already exists
23
- (config .path / emptyDir ).mkdir (exist_ok = False )
24
+ (config .path / emptyDir ).mkdir (exist_ok = False , parents = True )
25
+
26
+ # If this is not a bare config, then populate
27
+ # a small amount of content into the directories
28
+ if not config .bare :
29
+ #copy the contents of all template directories
30
+ for templateDir , targetDir in [
31
+ ('../templates/detections/' , 'detections' ),
32
+ ('../templates/data_sources/' , 'data_sources' ),
33
+ ('../templates/macros/' , 'macros' ),
34
+ ('../templates/stories/' , 'stories' ),
35
+ ]:
36
+ source_directory = pathlib .Path (os .path .dirname (__file__ ))/ templateDir
37
+ target_directory = config .path / targetDir
38
+
39
+ # Do not throw an exception if the directory exists. In fact, it was
40
+ # created above when the structure of the app was created.
41
+ shutil .copytree (source_directory , target_directory , dirs_exist_ok = True )
24
42
25
-
26
- #copy the contents of all template directories
43
+ # The contents of app_template must ALWAYS be copied because it contains
44
+ # several special files.
45
+ # For now, we also copy the deployments because the ability to create custom
46
+ # deployment files is limited with built-in functionality.
27
47
for templateDir , targetDir in [
28
48
('../templates/app_template/' , 'app_template' ),
29
- ('../templates/deployments/' , 'deployments' ),
30
- ('../templates/detections/' , 'detections' ),
31
- ('../templates/data_sources/' , 'data_sources' ),
32
- ('../templates/macros/' ,'macros' ),
33
- ('../templates/stories/' , 'stories' ),
49
+ ('../templates/deployments/' , 'deployments' )
34
50
]:
35
51
source_directory = pathlib .Path (os .path .dirname (__file__ ))/ templateDir
36
52
target_directory = config .path / targetDir
37
53
#Throw an exception if the target exists
38
54
shutil .copytree (source_directory , target_directory , dirs_exist_ok = False )
39
-
55
+
40
56
# Create a README.md file. Note that this is the README.md for the repository, not the
41
57
# one which will actually be packaged into the app. That is located in the app_template folder.
42
58
shutil .copyfile (pathlib .Path (os .path .dirname (__file__ ))/ '../templates/README.md' ,'README.md' )
0 commit comments