utils.questions_parser.py

read_questions_file

def read_questions_file(path: str) -> dict

Take a recommendation path and read the questions.yml file linked to

Arguments:

  • path str - 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_systems SupportedSystems - singleton that contains the user env selection

Raises:

  • PathDoesNotExist - If the specified path does not exist
  • VariablePathNotDefined - 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:

  • category str - The category to list
  • supported_systems SupportedSystems - 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:

  • category str - One of the category available in env selected
  • reference str - The reference to list
  • supported_systems SupportedSystems - singleton that contains the user env selection

Raises:

  • PathDoesNotExist - If the specified path does not exist
  • VariablePathNotDefined - 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) -> bool

This method check is the type provided by the user is correct

Arguments:

  • type_asked str - type asked in the questions.yml file
  • answer type - 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_path str - path of the recommendation
  • answer_list list[dict] - list of the answers provided by the user

Raises:

  • AnswerIsRequired - If the answers is present but no value
  • WrongAnswerType - If the type provived textually of in object instance is wrong
  • PathDoesNotExist - If the specified path does not exist
  • IndexError - If there are missing answers

Returns:

  • dict[str] - The answers the inject in playbook template