pyfsr.connector_dev

Local ConnectorsV2 development helpers: scaffold, package, deploy.

The full connector flow a coding agent (or a human) drives from a checkout:

  1. scaffold_connector() – write a minimal, installable connector skeleton (info.json, connector.py, operations.py, requirements.txt).

  2. edit the generated files (add operations, config fields, icons).

  3. package_connector() – build the dist/<name>-<version>.tgz bundle FortiSOAR installs, preferring git-tracked files.

  4. deploy_connector() – upload the bundle ($replace so redeploys are idempotent), wait for the connector to activate, optionally configure it, and healthcheck.

CLI: pyfsr connector scaffold|package|deploy (see pyfsr.cli.connector).

Attributes

Functions

scaffold_connector(→ list[pathlib.Path])

Write an installable ConnectorsV2 skeleton and return the paths.

package_connector(→ pathlib.Path)

Build <out_dir>/<name>-<version>.tgz unpacking to one <name>/ dir.

wait_for_active(→ None)

Poll list_configured(refresh=True) until name shows up active.

deploy_connector(→ dict[str, Any])

Package (if source is a checkout), install, activate, configure, healthcheck.

Module Contents

pyfsr.connector_dev.REQUIRED_FILES = ('info.json', 'connector.py', 'operations.py', 'requirements.txt')[source]
pyfsr.connector_dev.scaffold_connector(name: str, directory: str | pathlib.Path | None = None, *, label: str | None = None, description: str = 'A custom FortiSOAR connector.', ops: list[dict] | None = None) → list[pathlib.Path][source]

Write an installable ConnectorsV2 skeleton and return the paths.

By default the skeleton has one configuration field (server), one operation (ping) and a health check, so it packages, installs, configures and runs end to end before any real logic is added.

With ops (a list of {operation, title?, description?, method?, parameters?:[{name,type?,required?,title?}], output_schema?}) the skeleton instead gets a shared, antipattern-clean request helper and one handler per op over a base_url/api_key/verify configuration – a real-API foundation to fill in, not just a hello-world. Refuses to overwrite.

pyfsr.connector_dev.package_connector(directory: str | pathlib.Path = '.', *, out_dir: str | pathlib.Path | None = None, version: str | None = None) → pathlib.Path[source]

Build <out_dir>/<name>-<version>.tgz unpacking to one <name>/ dir.

Ports the ConnectorsV2 package.sh: prefer git-tracked files, drop tests, packaging furniture and caches, and require the four core files. Returns the bundle path. out_dir defaults to <directory>/dist.

version overrides the version used for the bundle name AND injected into the archived info.json – the source file is left untouched. This is how a redeploy ships a bumped version without a ghost connector.

pyfsr.connector_dev.wait_for_active(client, name: str, timeout: float = 180.0, interval: float = 3.0) → None[source]

Poll list_configured(refresh=True) until name shows up active.

The install job finishing does not mean the connector record is live yet (live-verified in lab deploys), so installs must wait on the listing.

pyfsr.connector_dev.deploy_connector(client, source: str | pathlib.Path, *, config: dict[str, Any] | None = None, config_name: str = 'Default', replace: bool = True, timeout: float = 180.0, on_existing_version: str = 'bump_patch') → dict[str, Any][source]

Package (if source is a checkout), install, activate, configure, healthcheck.

source is a connector directory (packaged first) or a built .tgz. With config, an idempotent named configuration is upserted and marked default, then healthchecked. Returns a summary dict of what happened.

GHOST-CONNECTOR GUARD. FortiSOAR keys a connector by name+version; reinstalling the SAME version over a changed bundle can leave a stale “ghost” alongside the new code. on_existing_version controls what happens when the box already has this connector at the version being deployed:

  • "bump_patch" (default): bump the patch and ship that instead (a directory is repackaged, a built .tgz re-versioned); the result records bumped.

  • "error": raise, so the caller bumps info.json deliberately.

  • "allow": install over it anyway (the old behaviour).