Checks, configuration and provenance¶
forward_sdk.checks ¶
Building check definitions: path checks from a trace query, and NQE checks.
A path check's definition is Forward's intent check: the check type, the path
query as filters (the same shape the Search page sends, so
:class:forward_sdk.trace.PathQuery builds it) and optional noise types and
header fields. Pass the definition as definition in the body of
client.checks.add_check::
from forward_sdk import checks
from forward_sdk.trace import ChainHop, Endpoint, PathQuery, device, subnet
flow = PathQuery(
from_=Endpoint(subnet("10.10.10.10/32")),
chain=[ChainHop("through", device("r2"))],
to=Endpoint(subnet("10.20.20.20/32"), headers=[{"ip_proto": ["6"], "tp_dst": ["8080"]}]),
)
client.checks.add_check(
snapshot_id=snapshot_id,
body={"definition": checks.existential(flow), "name": "app via r2"},
persistent=True,
)
Source: Forward's IntentCheck, ExistsCheck, NqeCheck and
ApiCheckType. Existential and Isolation checks of this shape, and NQE
checks, were used live on 26.10.6 by the AutoCon6 workshop, persistent ones
judged on predicted snapshots too. Mirrors the Go SDK v0.8.41, and its
validation rules as corrected in v0.8.47 and v0.8.48.
existential ¶
existential(
query: PathQuery,
*,
noise_types: Sequence[str] = (),
header_fields_with_defaults: Sequence[str] = (),
return_path: Literal["ANY", "SYMMETRIC"] | None = None,
) -> dict[str, Any]
A check that passes when the traffic query describes has a path.
Give the query's from_ and to and header filters, and a chain hop to
require one ("through r2"). return_path also requires a path back:
"ANY", or "SYMMETRIC" for one through the same devices in reverse.
noise_types are traffic classes to ignore (Forward's NoiseType
names), and header_fields_with_defaults the fields Forward may assume a
default for (only ip_tos, ip_frag_offset, tp_src,
tcp_flags, app_id, url and user_id).
isolation ¶
isolation(
query: PathQuery,
*,
noise_types: Sequence[str] = (),
header_fields_with_defaults: Sequence[str] = (),
) -> dict[str, Any]
A check that passes when the traffic query describes has NO path.
reachability ¶
reachability(
query: PathQuery,
*,
noise_types: Sequence[str] = (),
header_fields_with_defaults: Sequence[str] = (),
) -> dict[str, Any]
A check that passes when ALL the traffic query describes is delivered.
nqe_check ¶
nqe_check(
query_id: str, params: Mapping[str, Any] | None = None
) -> dict[str, Any]
A check that runs a published NQE library query (Q_...), with optional parameters.
Without params the check takes its name from the query, and Forward
answers 400 to a name beside it (seen live on 26.10.6), so send
{"definition": nqe_check(...)} alone. With params a name is
REQUIRED. An NQE check never takes a note or tags. See
:func:validate_new_check.
validate_new_check ¶
validate_new_check(body: Any) -> None
Refuse, without a request, a check body Forward would answer with a 400.
Forward's rules (NewNetworkCheck): no name on a Predefined or a
non-parameterized NQE check, a name required on a parameterized NQE
check, no note on an NQE check, tags only on a path check
(Existential, Isolation, Reachability), and perfMonitoringEnabled only
on an Existential one. add_check does not call this (a build may accept
what another refuses); call it where an early, plain message helps. Takes
the body as a mapping with Forward's field names, or a request model.
Names and notes are trimmed, as Forward does, and Forward's older type
names (ExistentialCheck, NetworkQuery and so on) count as the
current ones.
Raises:
| Type | Description |
|---|---|
ForwardConfigurationError
|
The body has no definition, or breaks a rule. |
forward_sdk.configuration ¶
Reading Forward's configuration responses.
Every configuration route answers with a one-entry object, {property:
value}, and Forward lower-cases the property name on the wire, so the key
for FIREWALL_PREDICT is firewall_predict. The value is typed per
property: a boolean, an integer, a string or an enum name.
PropertySource
dataclass
¶
A property's effective value and where it comes from.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
Any
|
What takes effect for the org. |
source |
str
|
|
config_value ¶
config_value(response: Any) -> Any
The value out of a configuration response, whatever the key.
Accepts the generated ConfigValue model or a plain mapping. Returns
None for an empty response, which Forward does not send for a known
property; an unknown property is a 400 instead.
The three routes answer differently for the same property and the
difference is the point. The global route reports the fixed default and
never an org's override, so it keeps saying False after an org has set
True; the org-effective routes report what actually governs. Read from
the scope you care about, not the one that happens to be reachable.
describe_properties ¶
describe_properties(
effective: Any,
org_configured: Any,
global_configured: Any,
) -> dict[str, PropertySource]
Say, for every property, what it is set to and which scope set it.
Forward has no route that reports a value's source, so it is derived from three listings, each of which the client can fetch::
effective = client.configuration.get_org_config_values(filter="OFF")
org = client.configuration.get_org_config_values(filter="CONFIGURED")
glob = client.configuration.get_global_config_values(filter="CONFIGURED")
sources = describe_properties(effective, org, glob)
For another org, as a Forward support account, read that org's listings
instead: get_org_scoped_config_values(org_id=..., filter="OFF") and
filter="CONFIGURED". The per-property overrides list
(get_global_config_property_org_overrides) is not a substitute: it holds
stored rows, including those of deleted orgs, not effective values.
The org wins if it set the property, then the global scope, and otherwise the
value is the compiled default. No route exposes that default on its own, so
default means "nobody changed it", not a value you can read back.
Arguments may be the generated ConfigValues models or plain mappings.
Property names are compared case-insensitively, since Forward lower-cases
them on the wire and documents them in upper case.
forward_sdk.provenance ¶
Tying a snapshot back to the collector output it was made from.
Before uploading a snapshot ZIP, :func:describe_archive hashes it and lists
what it holds, and :meth:ArchiveProvenance.note turns that into a short note
to upload with it, so anyone holding the ZIP can confirm which snapshot it
became (and the reverse)::
from forward_sdk.provenance import describe_archive
archive = describe_archive("collection.zip")
snapshot = client.snapshots.upload("collection.zip", note=archive.note("pre-change"))
Files are grouped by device from names of the form "<device>,<file>", the
naming Forward lists a snapshot's raw files under and the AutoCon6 workshop saw
in its collector's archives; the directory part of an entry's path is ignored.
Any other name is listed in other_files. Asked for by the AutoCon6 workshop.
ArchiveProvenance
dataclass
¶
What a snapshot ZIP is: its name, size, SHA-256 and contents.
note ¶
note(prefix: str | None = None) -> str
A one-line snapshot note naming the archive and its SHA-256.
prefix (a change id, say) goes first. The full hash is kept; the
rest is a count, so the note stays short.
describe_archive ¶
describe_archive(path: str | Path) -> ArchiveProvenance
Hash a snapshot ZIP and list its devices and files, without unpacking it.
The hash is streamed, so the archive's size does not matter to memory.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
No such file. |
ForwardConfigurationError
|
The file is not a ZIP. |
forward_sdk.snapshot_package ¶
Reading a snapshot package: its sources.json index, and its logs with credentials masked.
A snapshot package is the ZIP client.snapshots.export returns. At its top
level Forward writes sources.json: one entry per collection source (a
classic device, a controller, a cloud account, a Kubernetes cluster). The reason
to read it is relatedDevicesWithoutSnapshots, the devices the parser
generated for a source that have no snapshot of their own and so never appear
as devices. No REST route reports them, and they are the only explanation for a
snapshot that processed with zero devices::
from forward_sdk.snapshot_package import read_sources
sources = read_sources("package.zip")
print(sources.devices_without_snapshots())
Preview: the entry's shape was read from a real package by the Go SDK (v0.8.57),
not from Forward's source, so only the fields seen are named and raw keeps
each entry whole.
SnapshotPackageSource
dataclass
¶
One collection source in sources.json.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The source's name. |
related_devices_without_snapshots |
tuple[str, ...]
|
Devices generated for this source that have no snapshot of their own. |
files |
tuple[str, ...]
|
The source's package files, named |
created_by |
str | None
|
The connection type that created the source, such as
|
error |
str | None
|
Forward's collection error enum; |
raw |
dict[str, Any]
|
The whole entry as Forward wrote it, unknown fields included. |
SnapshotPackageSources
dataclass
¶
parse_sources ¶
parse_sources(
data: str | bytes | Mapping[str, Any],
) -> SnapshotPackageSources
Decode sources.json ({"sources": [...]}) from its text or parsed form.
Raises:
| Type | Description |
|---|---|
ForwardConfigurationError
|
The text is not JSON, or an entry is not an object. |
read_sources ¶
read_sources(path: str | Path) -> SnapshotPackageSources
Open a snapshot package ZIP and decode its top-level sources.json.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
No such file. |
ForwardConfigurationError
|
The file is not a ZIP, or has no |
redact_log ¶
redact_log(text: str) -> str
A package log (cli-execution.log and the like) with credentials masked.
Masks everything after Authorization: or Proxy-Authorization: on a
line, and any Bearer <token> or Basic <token> elsewhere; line endings
are kept. Forward writes a Kubernetes bearer token into
cli-execution.log unmasked, so run this before a package log is stored,
shown or made into a fixture. It masks the shapes it knows; it does not
prove that no secret remains. The same patterns as the Go SDK.
forward_sdk.classic_devices ¶
Classic-device connection types, and the result of creating a device with its credential.
client.classic_devices.list_device_conn_types() answers a map of type id to
metadata. Without for_="ui" it lists only the types Forward offers to end
users; with it, every type that can be a classic device, internal and
in-development ones included. :func:conn_type_exposed applies Forward's own
rule to one entry. Mirrors the Go SDK (v0.8.55).
ClassicDeviceWithCredential
dataclass
¶
What networks.create_classic_device_with_api_key made.
Attributes:
| Name | Type | Description |
|---|---|---|
credential |
Any
|
The |
device |
Any
|
The classic device that uses it ( |
conn_type_exposed ¶
conn_type_exposed(info: Mapping[str, Any]) -> bool
Whether Forward offers this connection type to end users.
Forward's own rule (isExposed): PRODUCTION and TECH_PREVIEW only.
A missing or unknown status is not exposed.