Resources
- class htv.resources.HtvVault(path=None)[source]
Bases:
object
Dataclass representing the HtbVault. It allows to manage the vault, adding/removing/opening resources, listing them or initializing/deleting the entire vault
- Variables:
_path – [Path] Path to the vault. May contain environment variables
- Parameters:
[str|Path] (path) – Path to the vault. If None, the default directory from conf will be used
- static clean()[source]
Clean-up vault
Deletes hidden directories created by text editors, in addition to cached and temp files. These files/dirs usually start by ‘.’ or ‘_’. .gitignore file and .git dir are always excluded.
- Return type:
int
- Returns:
0 on success. 1 if an error occurred
- static remove_resources(*args)[source]
Remove resources from the vault
- Parameters:
args – resource(s) name or index
- Return type:
int
- Returns:
The number of resources deleted
- makedirs(reset=False)[source]
Create vault dir structure
- Parameters:
reset (
bool
) – If True, and the vault already exists, the vault is deleted and reset to initial state- Return type:
int
- Returns:
0 if vault initialized successfully. 1 otherwise
- add_resources(res, _stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]
Add resource(s) to the vault
- Parameters:
res (
HtvResource
|list
[HtvResource
]) –HtbResource
or a list of them. If None, user will be prompt to input required Resource data_stdout (
tqdm
|TextIO
) – Stdout to log information. Default to STDOUT
- Return type:
int
- Returns:
number of resources added successfully
- list_resources(*args, regex=None)[source]
List resources from the vault
- Parameters:
args – resource types
HtbResource.type
regex (
str
) – regex applied on the resource name. If None, no filter is applied
- Return type:
list
[Path
]- Returns:
A list with the resources found, or None if no match
- use_resource(*args)[source]
Opens resource(s)
- Parameters:
args – Name(s) and/or index(es) of the resources to be opened
- Return type:
HtvResource
|list
[HtvResource
] |None
- Returns:
A HtbResource, or a list of them. None if the resource could not be opened
- class htv.resources.HtvResource(**kwargs)[source]
Bases:
CustomResource
Dataclass representing a generic HtbResource. This class is the parent of all resource types that can be found in HTB
- Variables:
__type__ – [str] Resource type ID (short-name). Possible values datasources/sources.yml
__resource_dir__ – [str] Location for these resources within the vault (relative path)
# :ivar _metadata: [
Metadata
]: resource information
- class htv.resources.HtvPath(**kwargs)[source]
Bases:
HtvResource
Abstract class representing a Path in the HTB academy
- Variables:
_sections – [list] Collection of modules and/or exercises
- property progress: str
Completion status string
- property sections
Collection of modules and/or exercises
- class htv.resources.HtvModule(**kwargs)[source]
Bases:
HtvResource
Modules represent some knowledge that is related together around a topic. It includes Sections, which are single pages focused on a single subtopic.
Modules can be aggregated in a
HtvPath
- Variables:
_sections – list[str] Module sections (
Section
)
- class Section(__type__=None, title=None, number=1)[source]
Bases:
object
Sections are like data-pills. A post, not long, focused on a single topic
Dataclass representing a Section of a
HtbModule
- Variables:
__type__ – [str] Type of section (interactive, document)
title – [str] Section title used in the section template. May contain spaces
name – [str] Secured file name (
utils.FsTools.secure_filename()
)
- Parameters:
__type__ – Type of section (interactive, document)
title (
str
) – Section title, may contain spaces
- class htv.resources.HtvExercise(**kwargs)[source]
Bases:
HtvResource
Abstract class representing a resource from HTB lab
- Variables:
_tasks – [list[
Task
]] List of tasks associated to this resource
- class Task(text=None, answer=None, points=None, number=None)[source]
Bases:
object
Dataclass representing a Task within a
HtbResource
- Variables:
number – [int] Task number (default 1)
text – [str] Task text, brief question or goal
answer – [str] Task answer or solution (default None)
points – [int] Points obtained when completing the task