You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raiseException(f"The following .csv or .mlmodel files exist in '{lookupsDirectory}', but are not referenced by a lookup file: {[str(path) forpathinunusedLookupFiles]}")
Get all of the Security Content Object Files rooted in a given directory. These will almost
43
+
certain be YML files, but could be other file types as specified by the user
44
+
45
+
Args:
46
+
path (pathlib.Path): The root path at which to enumerate all Security Content Files. All directories will be traversed.
47
+
allowedFileExtensions (set[str], optional): File extensions which are allowed to be present in this directory. In most cases, we do not want to allow the presence of non-YML files. Defaults to [".yml"].
48
+
fileExtensionsToReturn (set[str], optional): Filenames with extensions that should be returned from this function. For example, the lookups/ directory contains YML, CSV, and MLMODEL directories, but only the YMLs are Security Content Objects for constructing Lookyps. Defaults to[".yml"].
49
+
50
+
Raises:
51
+
Exception: Will raise an exception if allowedFileExtensions is not a subset of fileExtensionsToReturn.
52
+
Exception: Will raise an exception if the path passed to the function does not exist or is not a directory
53
+
Exception: Will raise an exception if there are any files rooted in the directory which are not in allowedFileExtensions
54
+
55
+
Returns:
56
+
list[pathlib.Path]: list of files with an extension in fileExtensionsToReturn found in path
raiseException(f"allowedFileExtensions {allowedFileExtensions} MUST be a subset of fileExtensionsToReturn {fileExtensionsToReturn}, but it is not")
60
+
61
+
ifnotpath.exists() ornotpath.is_dir():
62
+
raiseException(f"Unable to get security_content files, required directory '{str(path)}' does not exist or is not a directory")
63
+
64
+
allowedFiles:list[pathlib.Path] = []
65
+
erroneousFiles:list[pathlib.Path] = []
66
+
#Get every single file extension
67
+
forfilePathinpath.glob("**/*.*"):
68
+
iffilePath.suffixinallowedFileExtensions:
69
+
# Yes these are allowed
70
+
allowedFiles.append(filePath)
71
+
else:
72
+
# No these have not been allowed
73
+
erroneousFiles.append(filePath)
74
+
75
+
iflen(erroneousFiles):
76
+
raiseException(f"The following files are not allowed in the directory '{path}'. Only files with the extensions {allowedFileExtensions} are allowed:{[str(filePath) forfilePathinerroneousFiles]}")
77
+
78
+
# There were no errorneous files, so return the requested files
0 commit comments