Converters

Converters are used within URL definitions of Django. They can be used to add additional custom path components to URLs.

New converter classes will be automatically added when Django loads the defined URLs.To create a new string-based converter, just follow a simple structure and add the code to the specified file.

converters.py
# [...]
class MyIDConverter(StringConverter):
    regex = r"some-value-\d{4}"
# [...]

In URL definitions we can access this newly defined converter by using its class name:

urls.py
urlpatterns = [
    # The name must be lower-case and without 'converter' at the end
    path("/some/path/<myid:pk>", MyModelView.as_view(), name=...),
]

The following default converters will be registered on application start:

Default Converters

Class

URL name

Regex

FindingTemplateIDConverter

findingtemplateid

r"FT-[\w-]{36}-[\w-]{36}"

VulnerabilityIDConverter

vulnerabilityid

r"SV-[\w-]{36}-[\w-]{36}"

FindingIDConverter

findingid

r"SF-[\w-]{36}-[\w-]{36}"

MD5Converter

md5

r"[0-9a-fA-F]{32}"

HostIDConverter

hostid

r"hst_[\dA-Za-z-]{36}"

ComponentIdConverter

componentid

r"cpt_[\dA-Za-z-]{36}"

DependencyIdConverter

dependencyid

r"([0-9a-fA-F]{32}){2}"

Components

class mastf.MASTF.converters.StringConverter[source]

Base class for string-based converters.

mastf.MASTF.converters.listconverters() dict[source]

Returns all converters of this module.

The mapped name will be the class name transformed to lower case and with the "converter" extra removed.

Returns:

a dictionary storing all registered converter classes

Return type:

dict