AutomA WebUI
You will find all documentations about function used in front and back in the WebUI project. The two technologies used are Python for backend and Javascript for frontend:
You will find all documentations about function used in front and back in the WebUI project. The two technologies used are Python for backend and Javascript for frontend:
All python documentation are generated with the pydoc-markdown
class SingletonSupportedSystems()
This class is a sigleton object for SupportedSystems class
class SupportedSystems(SingletonSupportedSystems)
This class saves and checks path of the env selected by user.
def reset_params()
Reset varibles of path, used when they are errors
def get_entire_path()
The method checks and return the complete environment path else raise Exception
Raises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledReturns:
str
- The complete environment path selected by the userdef set_playbooks_location(path: str)
Check and set the location of the playbook directory
Arguments:
path
str - The path of the playbook locationRaises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filleddef get_os() -> list[str]
Search for OS directories contained in the playbook directory
Raises:
VariablePathNotDefined
- If variable are not filledReturns:
list[str]
- The list of OS availables in {playbook}/def get_os_type() -> list[str]
Search for OS type directories contained in the OS directory selected
Raises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledReturns:
list[str]
- The list of OS type availables in {playbook}/{OS}/def get_os_version() -> list[str]
Search for OS version directories contained in the OS type selected
Raises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledReturns:
list[str]
- The list of OS version availables in {playbook}/{OS}/{OS_TYPE}/def set_os(os: str) -> None
Set the OS selected by the user
Arguments:
os
str - OS name selectedRaises:
VariablePathNotDefined
- If variables are not filleddef set_os_type(os_type: str)
Set the OS type selected by the user
Arguments:
os_type
str - OS type name selectedRaises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filleddef set_os_version(os_version: str)
Set the OS version selected by the user
Arguments:
os_version
str - OS version name selectedRaises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledclass SingletonRecommendationsSelected()
This class is a sigleton object for RecommendationSelected class
class RecommendationsSelected(SingletonRecommendationsSelected)
This class keep in memory which recommendations has been selected
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 recommendationRaises:
PathDoesNotExist
- If the path {path}/questions.yml does not existReturns:
dict
- A dict that represents the questions.yml filedef 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 selectionRaises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledReturns:
list[str]
- The list of categories in the pathdef 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 listsupported_systems
SupportedSystems - singleton that contains the user env selectionReturns:
list[str]
- the list of references contained in the categorydef 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 selectedreference
str - The reference to listsupported_systems
SupportedSystems - singleton that contains the user env selectionRaises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledReturns:
list[str]
- The list of recommendations in the reference dir from the categorydef 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 fileanswer
type - answer provided by the userReturns:
bool
- True if the type corresponds, else Falsedef 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 recommendationanswer_list
list[dict] - list of the answers provided by the userRaises:
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 answersReturns:
dict[str]
- The answers the inject in playbook templatedef run_ansible_playbook()
This function call runner function from ansible to run the playbook.master.yml with the inventory.yml
Raises:
PathDoesNotExist
- If the path of playbook.master.yml or inventory.yml does not existdef playbook_render_write(dir_path: str, variables: dict)
This function take the playbook.yml.j2 template to inject into all answers from user input. After this, the function is writing the playbook as ‘playbook.yml’ in the directory
Arguments:
dir_path
str - The path of the recommendation where template is storedvariables
dict - A dict containing variable names and variable values to
render in the templateRaises:
PathDoesNotExist
- If the specified path does not existdef list_dir_in_dir(path: str) -> list[str]
This method is a os.listdir wrapper to return only directories without the .git dir
Arguments:
path
str - Dir to listReturns:
list[str]
- List of the directories contained in pathclass SingletonRecommendationID()
Sigleton of the RecommendationID class
class RecommendationID(SingletonRecommendationID)
This class manage the ID of each recommendation. To avoid to put ID in recommendation directories and files, the class RecommendationID manage dynamically ID by adding missing pair ID/path in the ID file. Futhermore, all ID are UUID from the uuid.uuid4()
def set_playbooks_location(path: str)
Check and set the location of the playbook directory
Arguments:
path
str - The path of the playbook locationRaises:
PathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filleddef set_id_file_location(path: str)
Set the location of the ID/PATH pair file
Arguments:
path
str - Path of the fileRaises:
VariablePathNotDefined
- If variables are not filleddef attribute_new_playbooks(all_recommendation_paths: list[str])
Add missing pair ID/PATH in the file. The pair ID/PATH are not deleted when a playbook is removed.
Arguments:
all_recommendation_paths
list[str] - list of all recommendation pathsdef get_available_playbooks() -> list[str]
browse all folders in the playbook folder to retrieve all recommendation paths
Returns:
list[str]
- all recommendation pathsdef get_id_from_path(path: str) -> str
Translate a path to an ID. The ID is used mainly in the front-end
Arguments:
path
str - path to translateRaises:
IDDoesNotExist
- If the path doesn’t have an IDPathDoesNotExist
- If the specified path does not existVariablePathNotDefined
- If variables are not filledReturns:
str
- The path’s IDdef get_path_from_id(id: str) -> str
Translate an ID to a path. The path is used mainly in the back-end
Arguments:
id
str - The id to translateRaises:
IDDoesNotExist
- If the ID does not existVariablePathNotDefined
- If variables are not filledReturns:
str
- The ID’s pathclass SingletonHostsSelected()
This class is a sigleton object for HostsSelected class
class Host()
This class represents one host object to export it to yml for the ansible inventory
def __init__(hostname: str, host_ip: str, host_port: int)
Create Host instance and fill hostname, host_ip and host_port
Arguments:
hostname
str - The name of the hosthost_ip
str - The ip or fqdn of the hosthost_port
int - The ssh port of the hostRaises:
ValueError
- If there are missing value, raise the Exceptiondef set_connection_method(connection_method: int, username: str,
pass_or_keyfile: str)
Fill connection_method, username and pass_or_keyfile.
Arguments:
connection_method
HostConnectionMethod - Value from the Enum, define user/password or user/keyfile connection methodusername
str - user to connect on host using sshpass_or_keyfile
str - password or the path of the keyfile to connect on host using sshRaises:
ValueError
- If there are missing value, raise the Exceptiondef set_sudo_access(sudo_username: str, sudo_password: str)
Fill sudo_username and sudo_password to permits privilege escalation
Arguments:
sudo_username
str - username of a user with sudo privilegesudo_password
str - password of a user with sudo privilegeRaises:
ValueError
- If there are missing value, raise the Exceptiondef get_yml() -> str
Render the Host instance into a string with yml syntax for the Ansible inventory file
Raises:
ValueError
- If the value of connection_method is not in the EnumReturns:
str
- The yml stringclass HostsSelected(SingletonHostsSelected)
This class keep in memory which hosts are selected and their configuration
def add_host(host: dict)
Create a host and add it to the list of hosts
Arguments:
host
dict - Dict that contains value to add hostRaises:
HostAlreadyAdded : If the hostname already exists
ValueError
- If there are missing value, raise the Exceptiondef is_hostname_unique(new_hostname: str) -> bool
Check if the hostname has already been added
Arguments:
new_hostname
str - The hostname to checkRaises:
ValueError
- If there are missing value, raise the ExceptionReturns:
bool
- True if the hostname is unique else Falseclass SingletonConfiguration()
Sigleton of the Configuration class
class Configuration(SingletonConfiguration)
This class read configuration file and retrieve variables. If a variable is not present the variable is set with a default value.
def get(config_key)
return the config value of the key specified in arg
def read_configuration()
Read the configuration file and set required variables
You will find here the javascript documentation from the frontend. Documentation has been generated with jsdoc2md
Render recommendation line adding elements to the DOM
Param | Type | Description |
---|---|---|
item | Recommendation | Recommendation retrieve by the back |
Generate button radio and fill it from local storage
Returns: HTMLElement - th element containing a element with radio.
Param | Type | Description |
---|---|---|
line | Recommendation | Recommendation line HTML |
id | string | ID Item |
Unsave id from the local storage
Param | Type | Description |
---|---|---|
id | string | ID Item |
Render inventory line adding elements to the DOM
Param | Type | Description |
---|---|---|
host | Inventory | Host from inventory |
Render cell
Param | Type | Description |
---|---|---|
textDisplayed | Recommendation | Text added in the celle |
Fill selector with values and bind verification function
Param | Type | Description |
---|---|---|
type | type | name of the selector |
values | type | values |
verificationFunction | type | values |
Load data of the selector from storage
Param | Type | Description |
---|---|---|
select_item | M.FormSelect | Select element |
selectorId | string | id of the selector |
Store data of the selector into storage
Param | Type | Description |
---|---|---|
value | string | value to store |
selectorId | string | id of the selector |
Remove an attribute to valid button
Param | Type | Description |
---|---|---|
attributeName | string | Name of the attribute |
Change disabled attribute in validation button
Param | Type | Description |
---|---|---|
bool | boolean | value of disabled attribute |
attributeName | string | Name of the attribute |
Reinit selector options, remove all options except the first one.
Summary: Remove all options in the dom except the first because in our case this first option is used as a placeholder for the moment
Param | Type | Description |
---|---|---|
selector | M.FormSelect | selector to clean |
Reset child
Summary: In our workflow reset a child selector has to reinit a child ONLY if the child is already visible
Param | Type | Description |
---|---|---|
childName | string | child name selector |
If the modal template is already instatiated, the function open it else it creates the modal. It takes the configuration of the question to choose which elements need to be added to the modal (select, input, chips, …)
Summary: Display a modal template and fill it from config question
Param | Type | Description |
---|---|---|
_id | _id | question UUID |
Get answer value by id recommendation and index question from local storage
Returns: answer - answer - if exists or null
Param | Type | Description |
---|---|---|
id | string | id of recommendation |
indexQuestion | number | index of the question |
Initialize Material components. This function need to be called after adding components to the DOM. This method is useful because in our case, our components are returned by our functions before adding them to the DOM. Some errors appears with Select component with this workflow. It’s base on global scope variable ‘MATERIALIZE_FIFO’
Summary: Initialize Material components wich need to be added to the DOM before
init
Create validation button and bind it with the click event.
Render question from ‘render_field_str’ method in case of ‘str’ : input Render question from ‘render_field_list_str’ method in case of ’list’ : chips Render question from ‘render_field_choice_str’ method in case of ‘choice’ : select
Summary: Render question depending on the answer type
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
Render question method in case of ‘str’ : it creates an input
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
Render question method in case of ’list’ : it creates a chips element
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
Render question method in case of ‘choice’ : it creates a select element The Select element is an
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
Get data from chips in case of ’list’, it takes values from a chips elements and add it to the local storage
Param | Type | Description |
---|---|---|
inputComponent | input_component | Chips element |
configType | configType | Configuration of the field |
Get data from input in case of ‘str’, it takes valueand add it to the local storage
Param | Type | Description |
---|---|---|
inputComponent | input_component | Chips element |
configType | configType | Configuration of the field |
Update local storage with a new value. If the answer value is empty, it’s remove from local storage. If there’s already a value present, we update this value.
Summary: Update local storage with a new value.
Param | Type | Description |
---|---|---|
inputComponent | inputComponent | inputComponent is a DOM Element, it has an id : UUIDRecommendation-index |
dataToSave | dataToSave | Data already process for the back, this value will be sent |
configType | configType | config type of the question |
Manage selected IDS. Based on verification about storage item with UUID of the recommendation. If an item with the same id does not exists, we remove the id from the data We also check the local storage to create it if it’s not exists.
Summary: Manage selected IDS stored in store
Param | Type | Description |
---|---|---|
id | ParamDataTypeHere | ID of recommendation |
Store answer data to localStorage
Param | Type | Description |
---|---|---|
id | inputComponent | Id of recommendation |
valueFormat | inputComponent | Data formated by our function to be store |
dataToSave | inputComponent | data to check if it’s not empty in order to remove local storage |
Format a value in order to be store in local storage. It’s a JSON format with three keys : value, formatType, index
Returns: string - Object - id, valueFormat
Param | Type | Description |
---|---|---|
inputComponent | inputComponent | Input component is needed to retrieve the index of answer and id recommendation |
dataToSave | inputComponent | Data in value |
configType | inputComponent | Configuration of this answer to send type answer to the back |