discovery
napt.discovery
Discovery package: strategies, registry, and orchestration.
Two flows feed into discover_recipe:
- Version-first strategies (api_github, api_json, web_scrape) implement DiscoveryStrategy: they discover a version and its download URL without touching the file. The orchestrator looks them up in the explicit table in napt.discovery.registry.
- url_download is a separate flow at run_url_download. It is not in the registry because it cannot determine the version without the file.
Both end in resolve_installer, which reuses the previous download when nothing changed, and otherwise downloads the file, reads the version from an MSI or MSIX installer, and files it under that version.
The discovery orchestrator dispatches to one of the two flows based
on the recipe's discovery.strategy value.
Built-in strategies
- api_github: queries the GitHub releases API for the latest tag.
- api_json: extracts version and download URL from a JSON endpoint.
- web_scrape: parses a vendor download page for both fields.
napt.discovery.base
Discovery strategy protocol and shared helpers.
A discovery strategy answers a single question: "what is the latest version of this app, and where can it be downloaded from?" Strategies return that answer as a RemoteVersion dataclass. They do not download files themselves; the orchestrator does.
Built-in strategies
- api_github: queries the GitHub releases API for the latest tag.
- api_json: extracts version and download URL from a JSON endpoint.
- web_scrape: parses a vendor download page for both fields.
The fourth flow (url_download) is not a registered strategy. It
downloads a fixed URL and extracts the version from the file itself,
which is a different shape than the strategies in this module. The
discovery orchestrator dispatches to that flow directly when a recipe
uses strategy: url_download.
Design Philosophy
- Strategies are
typing.Protocoltypes. Implementations are matched structurally; no inheritance is required. - Strategies are pure functions of configuration. They have no state and no I/O of files.
- Dispatch is an explicit name-to-class table in napt.discovery.registry.
- resolve_installer turns a RemoteVersion into a StrategyResult by reusing the previous download or fetching a new one. Strategies don't call it themselves; the orchestrator does.
RemoteVersion
dataclass
Version and download URL discovered from a remote source.
Returned by every DiscoveryStrategy implementation. The orchestrator passes this to resolve_installer to decide whether the file needs to be downloaded.
Attributes:
| Name | Type | Description |
|---|---|---|
version |
str
|
Raw version string extracted from the remote source
(for example, |
download_url |
str
|
URL the installer can be fetched from. |
source |
str
|
Name of the strategy that produced this result, used
for logging and result reporting (for example, |
Source code in napt/discovery/base.py
StrategyResult
dataclass
Resolved discovery result, ready to be recorded in deployment state.
Returned by resolve_installer for every flow. Captures everything the orchestrator needs to record the pending release and build a public DiscoverResult.
Attributes:
| Name | Type | Description |
|---|---|---|
version |
str
|
Version string for the resolved file. |
version_source |
str
|
Where the version came from: |
file_path |
Path
|
Path to the resolved installer on disk. This is either a freshly downloaded file or one an earlier run downloaded. |
sha256 |
str
|
SHA-256 hex digest of the resolved file. |
download_url |
str
|
URL the file came from, recorded with the pending release. |
Source code in napt/discovery/base.py
DiscoveryStrategy
Bases: Protocol
Protocol for version discovery strategies.
A strategy queries a remote source (API, web page, etc.) and returns the latest version plus its download URL. Strategies do not download files or write to disk. Those concerns belong to the orchestrator.
Implementations need FIELDS, a discover and a
validate_config method with the signatures below. The config
loader runs validate_config on the merged configuration and stops
on any error before discover is called, so discover reads its
fields directly.
Attributes:
| Name | Type | Description |
|---|---|---|
FIELDS |
frozenset[str]
|
Every |
Source code in napt/discovery/base.py
discover
Discovers the latest version and its download URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged and validated recipe configuration dict. |
required |
Returns:
| Type | Description |
|---|---|
RemoteVersion
|
Latest version, the URL it can be downloaded from, and the |
RemoteVersion
|
strategy's own name as the source identifier. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When the remote data does not match the recipe's patterns or paths. |
NetworkError
|
On request failures, or remote values too long to match a pattern on. |
Source code in napt/discovery/base.py
validate_config
Validates strategy-specific configuration fields without network calls.
Implementations should check field presence, types, and format only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged recipe configuration dict. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Human-readable error messages. Empty when configuration is valid. |
Source code in napt/discovery/base.py
first_capture
Returns what a recipe pattern captures from a remote string.
A pattern with capture groups yields group 1, otherwise the whole
match. A group that took no part in the match (an optional group whose
text was absent) counts as no match: it would otherwise turn into the
text None or a missing link.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
Pattern[str]
|
The compiled recipe pattern. |
required |
text
|
str
|
The string to search. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The captured text, or None when the pattern did not match. |
Source code in napt/discovery/base.py
bounded
Returns a remote string once it is short enough to match a pattern on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string a recipe pattern will run over. |
required |
what
|
str
|
What the string is, for the error message. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The value unchanged. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
If the value is longer than |
Source code in napt/discovery/base.py
require_usable_version
Rejects a version that cannot name a folder or that a device would misread.
The version names the download folder (downloads/<id>/<version>)
and later the build folder, so a value with a path separator or ..
is refused before any folder is created from it.
It is also what the detection and requirements scripts compare on a
device, and they take each part's leading digits with a part that has
none counting as 0. A version whose first part has no digits (v2.0,
latest) therefore reads as version 0 there: every device would
report it installed and no device would ever upgrade to it. Such a
version is refused so the recipe gets fixed instead. The scripts cast
each part to a 64-bit integer, so a part of more than 18 digits, which
may not fit, is refused as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
Version read from the installer, or reported by a strategy for an installer that carries no version of its own. |
required |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the version is not a plain folder name, does not start with a digit, or has a part of more than 18 digits. |
Source code in napt/discovery/base.py
napt.discovery.fields
Field checks and the request helper the discovery strategies share.
Every strategy's validate_config reports the same three things about a
field (missing, wrong type, empty) and compiles the same kinds of pattern,
and every version-first strategy fetches one URL the same way. Those live
here so each strategy holds only its own rules, and so a message about
discovery.repo reads like the messages napt.validation produces for
every other section.
Validation runs before any discover method is called: the config
loader validates the merged configuration and refuses to continue on any
error. A discover method therefore reads its fields directly and
checks only what the remote data turns out to be.
require_str
Checks that a required field is present and a non-empty string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, Any]
|
The |
required |
key
|
str
|
The field name. |
required |
errors
|
list[str]
|
List to append errors to. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The value when it passes, otherwise None. |
Source code in napt/discovery/fields.py
optional_str
Checks that a field, when present, is a non-empty string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
dict[str, Any]
|
The |
required |
key
|
str
|
The field name. |
required |
errors
|
list[str]
|
List to append errors to. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The value when present and valid, otherwise None. |
Source code in napt/discovery/fields.py
check_regex
Checks that a field's value compiles as a regular expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The pattern text. |
required |
key
|
str
|
The field name, for the message. |
required |
errors
|
list[str]
|
List to append errors to. |
required |
Source code in napt/discovery/fields.py
check_format
Checks that a field's value is a format string over capture groups.
The groups are passed by position, so every replacement field must be
a number ({0}, {1}) or empty ({}); a named field would
fail at discovery time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The format string. |
required |
key
|
str
|
The field name, for the message. |
required |
errors
|
list[str]
|
List to append errors to. |
required |
Source code in napt/discovery/fields.py
fetch
fetch(
url: str,
*,
what: str,
headers: dict[str, str] | None = None,
hosts: set[str] | None = None
) -> requests.Response
Fetches a URL for a strategy and checks the response succeeded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to fetch. |
required |
what
|
str
|
What is being fetched, for messages ( |
required |
headers
|
dict[str, str] | None
|
Request headers, secrets already expanded. |
None
|
hosts
|
set[str] | None
|
The hosts a redirect may go to when the headers carry a secret, from bound_hosts; None follows redirects freely. |
None
|
Returns:
| Type | Description |
|---|---|
Response
|
The successful response. |
Raises:
| Type | Description |
|---|---|
NetworkError
|
On transport failure, a redirect off the bound hosts, or a status that is not success. |
Source code in napt/discovery/fields.py
fetch_text
fetch_text(
url: str,
*,
what: str,
max_bytes: int,
headers: dict[str, str] | None = None,
hosts: set[str] | None = None
) -> str
Fetches a text document for a strategy, refusing one over a size cap.
The body is read in pieces and the download stops as soon as it passes
max_bytes, so a URL that points at a large file is refused without
downloading it. A Content-Length header over the cap is refused before
any of the body is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to fetch. |
required |
what
|
str
|
What is being fetched, for messages ( |
required |
max_bytes
|
int
|
The largest body to accept. |
required |
headers
|
dict[str, str] | None
|
Request headers, secrets already expanded. |
None
|
hosts
|
set[str] | None
|
The hosts a redirect may go to when the headers carry a secret, from bound_hosts; None follows redirects freely. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The document, decoded with the charset the response declares (UTF-8 when it declares none). |
Raises:
| Type | Description |
|---|---|
NetworkError
|
On transport failure, a redirect off the bound hosts,
a status that is not success, or a body over |
Source code in napt/discovery/fields.py
extract_version
Reads the version a recipe pattern captures from a remote string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern_text
|
str
|
The recipe's |
required |
text
|
str
|
The string to search, already bounded. |
required |
what
|
str
|
What the string is, for the message ( |
required |
Returns:
| Type | Description |
|---|---|
str
|
Capture group 1 when the pattern has one, otherwise the whole |
str
|
match. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the pattern does not match, or a capture group took no part in the match. |
Source code in napt/discovery/fields.py
napt.discovery.registry
Explicit registry of discovery strategies.
Maps each discovery.strategy recipe value to the class implementing
it. Dispatch is a plain table lookup: nothing registers itself at import
time, and this module's imports are what pull in the strategy
implementations.
Adding a strategy
- Implement DiscoveryStrategy
in a new module under
napt/discovery/, withFIELDSnaming every recipe field it reads. - Import the class here and add it to the table.
Note
url_download is intentionally absent from the table. It
downloads the file before it can determine the version, which does
not fit the version-first contract, so the discovery orchestrator
dispatches to
run_url_download
directly.
get_strategy
Returns a discovery strategy instance by name.
Strategies are stateless, so a fresh instance is created on every call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Strategy name as written in recipe YAML under
|
required |
Returns:
| Type | Description |
|---|---|
DiscoveryStrategy
|
New instance of the requested strategy. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the name is not in the registry. The message lists the available strategies for troubleshooting. |
Source code in napt/discovery/registry.py
napt.discovery.resolve
Turns what a strategy found into an installer on disk.
Every discovery flow ends here. A strategy produces a download URL and,
for the version-first strategies, the version it believes that URL
serves. This module downloads the file, reads the version out of it when
the installer can report one (MSI ProductVersion, MSIX
Identity.Version), and files it under downloads/<id>/<version>/.
The installer's own version is the one recorded, because it is what the
detection and requirements scripts compare against on a device; the
version a page or API reported is only the trigger that caused the
download.
Skipping Downloads
Each app has one sidecar file, downloads/<id>/.download.json,
recording what was last resolved: the trigger (the URL and, when the
strategy supplied one, the version it reported), the server's
ETag and Last-Modified, and the installer's version, name,
and hash. The next run compares its trigger against that record:
- A version-first strategy that reports the same version as last time
from the same link reuses the installer without a request,
provided that version and the installer's own agree as a device
would compare them (
4.41.106and4.41.106.0do). The link is compared without its query string, where some vendor pages put a token that changes on every visit. When the version agrees but the link changed (a switched asset, a re-published release), or when the version and the installer's own disagree (a page updated before the file behind it, or a pattern capturing the wrong value), the report cannot vouch that nothing changed: the run asks the server instead, asurl_downloaddoes. url_downloadhas no version to compare, so it sends theETag/Last-Modifiedback as a conditional request and reuses the installer when the server answers HTTP 304, or answers 200 with the same validator (a server that ignores conditional requests; the body is not read).
The sidecar is a hint, not a record. Anything wrong with it, including an installer on disk that no longer matches the recorded hash, means one full download, never an error, and it is written only after the installer is in place.
Filing
A download lands in a per-run folder (downloads/<id>/.incoming-*)
until its version is known, so two runs for one app never touch each
other's partial file; a folder a crashed run left behind is removed
once it is a day old. A file already filed under the same version with
different bytes (a vendor re-releasing a version under one filename)
is kept beside the new one under a hash-suffixed name, because the
published release may have been built from it and napt build
selects the installer by hash.
resolve_installer
resolve_installer(
url: str,
app_dir: Path,
*,
source: str,
discovered_version: str | None = None
) -> StrategyResult
Resolves a strategy's finding to an installer on disk.
Reuses the app's last download when the sidecar shows the trigger is unchanged (see the module description); otherwise downloads the file, reads its version, and files it under that version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL the installer is served from. |
required |
app_dir
|
Path
|
The app's download directory ( |
required |
source
|
str
|
Name of the strategy, recorded as the version source when the installer cannot report its own version. |
required |
discovered_version
|
str | None
|
Version the strategy reported for |
None
|
Returns:
| Type | Description |
|---|---|
StrategyResult
|
Resolved version, its source, file path, and SHA-256 hash. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the file's version cannot be used as a folder
name, or if |
NetworkError
|
On download failures. |
PackagingError
|
If the installer's version cannot be read. |
Source code in napt/discovery/resolve.py
napt.discovery.url_download
url_download discovery flow.
This module is intentionally not a
DiscoveryStrategy. The
strategies in napt.discovery.base produce a
RemoteVersion from configuration
alone (version-first). url_download cannot do that: it has no
remote endpoint to query for the version, so it must download the
installer and read the version from the file itself. The discovery
orchestrator special-cases strategy: url_download and dispatches to
run_url_download directly.
The download, the version read, and the reuse of an unchanged file all
happen in napt.discovery.resolve, shared with the version-first
strategies. With no version to compare, this flow relies on the server's
ETag / Last-Modified to learn whether the file changed.
Supported File Types
.msi: version is read from the MSI ProductVersion property..msix: version is read from the package's Identity element.- Other extensions raise ConfigError. For those installers, use a version-first strategy.
The recipe reference defines each field.
run_url_download
Downloads a fixed URL and reads the version from the resulting file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged recipe configuration dict containing
|
required |
output_dir
|
Path
|
Base directory to download into. The file lands
in |
required |
Returns:
| Type | Description |
|---|---|
StrategyResult
|
Resolved version, file path, and SHA-256 hash. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the downloaded file is not an MSI or MSIX, or its version cannot name a folder. |
NetworkError
|
On download failures. |
PackagingError
|
If the installer's version cannot be read. |
Source code in napt/discovery/url_download.py
validate_url_download_config
Validates url_download configuration fields.
Called by napt.validation.validate_config to compose the url_download field rules into the overall recipe validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged recipe configuration dict. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Human-readable error messages. Empty when configuration is valid. |
Source code in napt/discovery/url_download.py
napt.discovery.web_scrape
Web scraping discovery strategy.
Fetches a vendor download page, locates a download link, and extracts the version from that link's URL. Use this when a vendor has neither a JSON API nor a GitHub releases feed.
Recipe Example (CSS selector, recommended):
discovery:
strategy: web_scrape
page_url: "https://www.7-zip.org/download.html"
link_selector: 'a[href$="-x64.msi"]'
version_pattern: "7z(\\d{2})(\\d{2})-x64"
version_format: "{0}.{1}" # transforms ("25", "01") -> "25.01"
The recipe reference defines
each field, including the link_pattern regex fallback.
Finding a CSS Selector
- Open the download page in Chrome / Edge / Firefox.
- Right-click the download link -> Inspect.
- Right-click the highlighted element -> Copy -> Copy selector.
- Simplify the result. Common shapes:
a[href$=".msi"](links ending in .msi)a[href*="x64"](links containing "x64")a.download(links withclass="download")
Note
The selector / pattern is expected to match exactly one link; the
first match is used. Relative URLs in the page are resolved against
page_url.
WebScrapeStrategy
Discovery strategy for scraping vendor download pages.
Source code in napt/discovery/web_scrape.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
discover
Discovers version and download URL by scraping a vendor page.
Fetches discovery.page_url, locates a download link with
either link_selector (CSS) or link_pattern (regex),
and extracts the version from the matched link using
version_pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged and validated recipe configuration dict
containing |
required |
Returns:
| Type | Description |
|---|---|
RemoteVersion
|
Discovered version, the matched link's URL, and |
RemoteVersion
|
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
When a selector or pattern matches nothing, or
|
NetworkError
|
On page fetch failure, a page larger than NAPT parses, or a matched link too long to match a pattern on. |
Source code in napt/discovery/web_scrape.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
validate_config
Validate web_scrape strategy configuration.
Checks for required fields and correct types without making network calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
The app configuration from the recipe. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error messages (empty if valid). |
Source code in napt/discovery/web_scrape.py
napt.discovery.api_github
GitHub releases discovery strategy.
Queries the GitHub releases API for the latest tag and the download URL
of a matching asset. The version comes from the release tag (parsed
with a regex); the download URL comes from the first asset whose
filename matches asset_pattern.
Recipe Example
The recipe reference defines each field.
Note
The request goes to the latest-release endpoint, which never returns a
pre-release or a draft. If no asset matches, discovery raises an error
rather than walking back through history. ${VAR} in token is
replaced with that environment variable, provided defaults/org.yaml
declares it under secrets and binds it to api.github.com (see
napt.secrets); an undeclared or unset variable stops discovery.
ApiGithubStrategy
Discovery strategy for GitHub releases.
Source code in napt/discovery/api_github.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
discover
Discovers the latest GitHub release version and asset download URL.
Queries the GitHub releases API for the latest release of the
configured repository. Extracts the version from the release tag
(via version_pattern) and the download URL from the first
asset matching asset_pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged and validated recipe configuration dict
containing |
required |
Returns:
| Type | Description |
|---|---|
RemoteVersion
|
Latest version, the matched asset's download URL, and |
RemoteVersion
|
|
Raises:
| Type | Description |
|---|---|
ConfigError
|
On a token secret org.yaml does not declare, binds to another host, or that is not set, or when patterns do not match the release. |
NetworkError
|
On API failure, missing assets, or a tag or asset name too long to match a pattern on. |
Source code in napt/discovery/api_github.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
validate_config
Validate api_github strategy configuration.
Checks for required fields and correct types without making network calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
The app configuration from the recipe. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error messages (empty if valid). |
Source code in napt/discovery/api_github.py
napt.discovery.api_json
JSON API discovery strategy.
Queries a JSON API endpoint for the latest version and download URL. Both fields are read from the response with dotted paths.
Recipe Example
discovery:
strategy: api_json
api_url: "https://vendor.example.com/api/latest" # required
version_path: "version" # required, dotted path
download_url_path: "builds[0].url" # required, dotted path
version_pattern: "v?([0-9.]+)" # optional, regex
headers: # optional
Authorization: "Bearer ${API_TOKEN}" # declared in org.yaml
Accept: "application/json"
The recipe reference defines each field.
Note
A path is keys separated by dots, with [n] for a list index:
data.version, builds[0].url. ${VAR} anywhere in a header
value is replaced with that environment variable, provided
defaults/org.yaml declares it under secrets and binds it to the
API host; see napt.secrets. An undeclared or unset variable stops
discovery before the request is sent.
ApiJsonStrategy
Discovery strategy for JSON API endpoints.
Source code in napt/discovery/api_json.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
discover
Discovers version and download URL from a JSON API endpoint.
Sends a GET request to the configured api_url and reads the
version and download URL at the configured paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
Merged and validated recipe configuration dict
containing |
required |
Returns:
| Type | Description |
|---|---|
RemoteVersion
|
Discovered version, download URL, and |
RemoteVersion
|
the source identifier. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
On a header secret that org.yaml does not allow for
the API host or that is not set, when a path does not match
the response or finds the wrong kind of value, or when
|
NetworkError
|
On API request failure, a redirect that would carry a secret off its bound hosts, or a version value too long to match a pattern on. |
Source code in napt/discovery/api_json.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
validate_config
Validate api_json strategy configuration.
Checks for required fields and correct types without making network calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_config
|
dict[str, Any]
|
The app configuration from the recipe. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error messages (empty if valid). |