config
napt.config
Configuration loading and management for NAPT.
Loads and merges YAML configuration in five layers: code defaults, defaults/org.yaml, defaults/vendors/{Vendor}.yaml, the parent recipe, and the recipe.
The loader performs deep merging where dicts are merged recursively and lists/scalars are replaced (last wins). See the Path resolution section of loader for how relative paths resolve.
Modules:
| Name | Description |
|---|---|
loader |
The layered configuration loader (load_effective_config). |
defaults |
Built-in default configuration and the org.yaml template. |
napt.config.loader
Configuration loading and merging for NAPT.
This module implements a layered configuration system that allows NAPT to work out of the box while supporting full customization. Each layer wins over the previous one.
Configuration Layers
- Code defaults (napt/config/defaults.py)
- Built-in defaults that ship with NAPT
- Always present; ensures NAPT works without any config files
-
Provides sensible defaults for all settings
-
Organization defaults (defaults/org.yaml)
- Organization-wide settings
- Optional; only loaded if file exists
-
Customizes settings for your organization
-
Vendor defaults (defaults/vendors/{Vendor}.yaml)
- Vendor-specific settings (e.g., Google-specific settings)
- Optional; loaded when the vendor is detected and defaults/org.yaml exists
-
Wins over organization defaults
-
Parent recipe (the file named by the recipe's
parentfield) - Another recipe merged beneath this one
- Optional; a parent may not itself declare a parent
- Wins over vendor defaults
-
A parent under
upstream/is a pinned copy: it must match the hashupstream.yamlrecords, and only app-owned keys are merged (see napt.upstream.pinned) -
Recipe configuration (recipes/{Vendor}/{app}.yaml)
- App-specific configuration
- Always required; defines the app itself
- Wins over all other layers
Merge Behavior
The loader performs deep merging with "last wins" semantics:
- Dicts: Recursively merged (keys from overlay win over base)
- Lists: Completely replaced (NOT appended/extended)
- Scalars: Overwritten (strings, numbers, booleans)
- secrets: Taken from defaults/org.yaml alone; a vendor file, parent, or recipe that declares one fails validation
Path Resolution
Relative paths in two fields are resolved after merging:
- psadt.brand_pack.path resolves against defaults/ (the recipe directory when no defaults/org.yaml is found).
- intune.logo_path resolves against the recipe directory, then defaults/ if no file is there.
Dynamic Injection
Some fields are injected at load time, with the provenance layer
computed:
- psadt.app_vars.AppScriptDate: Today's date (YYYY-MM-DD)
- psadt.app_vars.RequireAdmin: true unless intune.run_as_account is user; a value set in any config layer wins
Error Handling
- ConfigError: A missing recipe or parent file, a YAML parse error, a file whose top level is not a mapping (in any layer), a parent chain, a pinned parent that is untracked or edited, or a pinned copy run directly
- All errors are chained with "from err" for better debugging
Note
- Code defaults are always applied first (NAPT works without config files)
- The loader walks upward from the recipe to find defaults/org.yaml
- Organization and vendor defaults are optional; vendor defaults need defaults/org.yaml to be found
- The vendor is the name of the recipe's directory (recipes/Google/)
LoadedParent
dataclass
A parent recipe as the loader hands it to the merge.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
The resolved parent file. |
data |
dict[str, Any]
|
Its parsed contents, filtered to the allowed keys when the parent is a pinned copy. |
dropped |
tuple[str, ...]
|
The dotted names of the keys the filter removed; empty for a local parent. |
Source code in napt/config/loader.py
load_parent
Loads the parent recipe a recipe declares, if any.
The parent field names another recipe file relative to the
declaring recipe's directory. The parent is merged beneath the
declaring recipe by
merge_config_layers.
A parent under upstream/ is a pinned copy: its bytes must match the hash
recorded in upstream.yaml, and only the keys in
ALLOWED_PARENT_KEYS are
kept. See napt.upstream.pinned for what makes a parent a pinned
copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe that may declare |
required |
recipe_obj
|
dict[str, Any]
|
The parsed recipe dictionary. |
required |
Returns:
| Type | Description |
|---|---|
LoadedParent | None
|
The parent, or None when the recipe declares no parent. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
When |
Source code in napt/config/loader.py
collect_recipe_paths
Collects recipe file paths from a file or directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipes
|
Path
|
A recipe YAML file, or a directory scanned recursively
for |
required |
Returns:
| Type | Description |
|---|---|
list[Path]
|
Sorted recipe file paths. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the path does not exist or contains no recipes. |
Source code in napt/config/loader.py
resolve_state_dir
Resolves the configured state directory for a run over recipes.
directories.state is org policy (consistent across a project),
so the first recipe's effective configuration determines it for a
fleet-wide run. The load is quiet: this reads one setting and reports
nothing about the recipe, so the command's own output (for example
napt status --format json) is not preceded by recipe diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipes
|
Path
|
A recipe YAML file, or a directory scanned recursively. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The configured state directory. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the recipes path is invalid or the first recipe cannot be loaded. |
Source code in napt/config/loader.py
register_recipe_id
Records which file declares a recipe id, reporting a second claimant.
napt validate and napt promote both scan a directory and must
agree on what a duplicate id is; this is the one place that decides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
dict[str, Path]
|
The ids seen so far, mapped to the file that declared each. A new id is recorded here. |
required |
app_id
|
str
|
The id the file declares. |
required |
path
|
Path
|
The file declaring it. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
None when the id is new; otherwise the error message, naming both files and the usual cause, with the first declaration kept. |
Source code in napt/config/loader.py
merge_effective_config
merge_effective_config(
recipe_path: Path, *, quiet: bool = False
) -> tuple[dict[str, Any], Path | None]
Merges the configuration layers for a recipe without validating them.
Reads the recipe and the parent it declares, then merges them with merge_config_layers. When a pinned parent set keys the allow list dropped, one always-visible line names them, because the effective configuration differs from what the pinned copy says.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe YAML file. |
required |
quiet
|
bool
|
Skip the dropped-keys line, for a caller that reads one setting and reports nothing about the recipe. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, Any], Path | None]
|
The merged configuration and the parent recipe's path (None when the recipe declares no parent). |
Raises:
| Type | Description |
|---|---|
ConfigError
|
On a missing recipe or parent file, a YAML parse error,
a layer whose top level is not a mapping, a parent chain, a
recipe that is itself a pinned copy under |
Source code in napt/config/loader.py
merge_config_layers
merge_config_layers(
recipe_path: Path,
recipe_obj: dict[str, Any],
parent: LoadedParent | None = None,
) -> dict[str, Any]
Merges the configuration layers for an already-parsed recipe.
The recipe and its parent arrive as objects, so a recipe that is not on disk yet can be merged exactly as it will be once written. Performs the following operations:
- Find defaults root by scanning upwards from the recipe's directory for defaults/org.yaml
- Load org defaults from defaults/org.yaml
- Load the vendor defaults named after the recipe's directory, if present
- Merge: org -> vendor -> parent -> recipe (dicts deep-merge, lists
replace); the
secretssection is taken from org.yaml alone - Resolve known relative paths (see Path resolution in the module docstring)
- Inject dynamic fields (AppScriptDate = today if absent)
The merged dict carries the recipe's parent field and a
_provenance entry naming the layer that set each value, so
validation can check both.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Where the recipe lives or will live; its directory names the vendor and anchors relative paths and the search for defaults/org.yaml. |
required |
recipe_obj
|
dict[str, Any]
|
The parsed recipe. |
required |
parent
|
LoadedParent | None
|
The parent as load_parent returns it, already filtered when pinned, or None when the recipe declares no parent. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The merged configuration. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
On a missing or unreadable org.yaml or vendor file, or one whose top level is not a mapping. |
Source code in napt/config/loader.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | |
load_effective_config
Loads, merges, and validates the effective configuration for a recipe.
Merges the layers with
merge_effective_config,
then validates the result: errors raise, warnings are logged. The
returned dict does not carry the parent field; the parent's contents
are already merged in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe YAML file. |
required |
quiet
|
bool
|
Skip the validation warnings and the dropped-keys line, for a caller that reads one setting and reports nothing about the recipe. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The merged configuration; code defaults are always included. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
On a missing recipe or parent file, a YAML parse error, a layer whose top level is not a mapping, a parent chain, a pinned parent that fails its hash check, or a configuration that fails validation. |
Source code in napt/config/loader.py
napt.config.defaults
Default configuration values for NAPT.
This module provides the baseline configuration that ships with NAPT. These defaults are always applied first, then overridden by organization defaults (org.yaml), vendor defaults, and finally recipe-specific settings.
The configuration hierarchy is
- Code defaults (this module) - always present
- Organization defaults (defaults/org.yaml) - optional
- Vendor defaults (defaults/vendors/{Vendor}.yaml) - optional
- Parent recipe (the file named by
parent) - optional - Recipe configuration - required, app-specific settings
This design ensures that NAPT works out of the box without requiring any configuration files, while still allowing full customization when needed.
Note
Authentication for 'napt upload' requires no config file. Developers run 'napt auth login' once; CI/CD pipelines set AZURE_CLIENT_ID, AZURE_TENANT_ID and AZURE_CLIENT_SECRET, or use OIDC federation.