API Config Parser

File location
  • Bundled implementation: source/client/python/cfgparser.py

  • Cluster implementation: cluster/app/source/python/cfgparser.py

Dataclasses

class cfgparser.API

A dataclass for parsed API entry.

workdir: str

API working directory.

environ: Dict[str, Any]

API runtime environment variables.

install: List[Union[str, List[str]]]

List of installation commands.

scripts: List[Union[str, List[str]]]

List of detection commands.

report: str

Report generation command.

remote: bool

If the API required remote execution, i.e. through the BroAPT-Daemon server.

shared: str

Sharing identifier, i.e. which MIME type the API entry is shared with.

inited = multiprocessing.Value('B', False)

Initied flag.

locked: multiprocessing.Lock

Multiprocessing runtime lock.

Functions

cfgparser.parse_cmd(context: Dict[str, Any], mimetype: str, environ: Dict[str, Any])

Parse API of mimetype.

Parameters
  • context – API configuration context.

  • mimetype (str) – MIME type of the API.

  • environ – Global environment variables.

Raises

ReportNotFoundError – If report section not presented in context.

cfgparser.parse(root: str)

Parse API configuration file api.yml.

Parameters

root (str) – Root path to the APIs.

Returns

The parsed API entries, i.e. API_DICT.

Return type

Dict[str, API]

Constants

cfgparser.MEDIA_TYPE: Tuple[str]
('application',
 'audio',
 # 'example',  ## preserved for default API
 'font',
 'image',
 'message',
 'model',
 'multipart',
 'text',
 'video')

Possible media types.

cfgparser.API_DICT: Dict[str, API]

Database for API entries.

cfgparser.API_LOCK: Dict[str, multiprocessing.Lock]

Database for multiprocessing lock.

cfgparser.API_INIT: Dict[str, multiprocessing.Value]

Database for inited flags.

Exceptions

exception cfgparser.ConfigError
Bases

Exception

Invalid config.

exception cfgparser.DefaultNotFoundError
Bases

ConfigError

The default fallback API for MIME type example not found.

exception cfgparser.ReportNotFoundError
Bases

ConfigError

The report section not found in API.