utils.questions_parser.py
read_questions_file
def read_questions_file(path: str) -> dictTake a recommendation path and read the questions.yml file linked to
Arguments:
pathstr - Path of the recommendation
Raises:
PathDoesNotExist- If the path {path}/questions.yml does not exist
Returns:
dict- A dict that represents the questions.yml file
list_categories
def list_categories(supported_systems: SupportedSystems) -> list[str]List categories contained in the environment selected by the user
Arguments:
supported_systemsSupportedSystems - singleton that contains the user env selection
Raises:
PathDoesNotExist- If the specified path does not existVariablePathNotDefined- If variables are not filled
Returns:
list[str]- The list of categories in the path
list_reference
def list_reference(category: str,
supported_systems: SupportedSystems) -> list[str]List all reference base (ANSSI, CIS, etc) from a category
Arguments:
categorystr - The category to listsupported_systemsSupportedSystems - singleton that contains the user env selection
Returns:
list[str]- the list of references contained in the category
list_recommendations
def list_recommendations(category: str, reference: str,
supported_systems: SupportedSystems) -> list[str]List recommendation available in the reference directory in a category
Arguments:
categorystr - One of the category available in env selectedreferencestr - The reference to listsupported_systemsSupportedSystems - singleton that contains the user env selection
Raises:
PathDoesNotExist- If the specified path does not existVariablePathNotDefined- If variables are not filled
Returns:
list[str]- The list of recommendations in the reference dir from the category
is_type_ok
def is_type_ok(type_asked: str, answer) -> boolThis method check is the type provided by the user is correct
Arguments:
type_askedstr - type asked in the questions.yml fileanswertype - answer provided by the user
Returns:
bool- True if the type corresponds, else False
check_answers
def check_answers(r_path: str, answer_list: list[dict]) -> dict[str]Take the answer provided by the user and check if it is conform in comparaison of the questions.yml. It check, the type, the real format, if value exists in case of required “true”. If everything is correct, return the dict object to inject in the playbook template (playbook.yml.j2).
Arguments:
r_pathstr - path of the recommendationanswer_listlist[dict] - list of the answers provided by the user
Raises:
AnswerIsRequired- If the answers is present but no valueWrongAnswerType- If the type provived textually of in object instance is wrongPathDoesNotExist- If the specified path does not existIndexError- If there are missing answers
Returns:
dict[str]- The answers the inject in playbook template