upload
napt.upload
Intune upload operations for NAPT.
This module provides the complete upload pipeline for deploying Win32 LOB apps to Microsoft Intune via the Graph API. Authentication comes from napt.auth and the Graph calls from napt.graph.
Modules:
| Name | Description |
|---|---|
manager |
Upload orchestration (load config, auth, upload flow). |
intunewin |
.intunewin ZIP parser (reads Detection.xml encryption metadata). |
napt.upload.manager
Upload orchestrator for NAPT Intune deployment.
Coordinates the full upload pipeline: loading recipe config, locating the package of the recorded release, verifying it, authenticating, parsing the .intunewin file, building app metadata, and executing the Graph API upload flow.
The package is found through deployment state and the build manifest,
never by guessing: the version comes from the recorded release (pending,
else published), the manifest names the .intunewin file and the scripts,
and the .intunewin is re-hashed against what napt package recorded
before anything is sent.
UploadResult
dataclass
Result from uploading a .intunewin package to Microsoft Intune.
Attributes:
| Name | Type | Description |
|---|---|---|
app_id |
str
|
Unique application identifier (from recipe). |
app_name |
str
|
Application display name. |
version |
str
|
Application version uploaded. |
intune_app_id |
str | None
|
Graph API object ID of the install app entry. None when build_types is "update_only". |
intune_update_app_id |
str | None
|
Graph API object ID of the update app entry. None when build_types is "app_only". |
package_path |
Path
|
Path to the uploaded .intunewin file. |
Source code in napt/upload/manager.py
upload_package
upload_package(
recipe_path: Path,
force: bool = False,
*,
state_dir: Path | None = None,
packages_dir: Path | None = None
) -> UploadResult
Upload a packaged app to Microsoft Intune via the Graph API.
Loads the recipe config, locates the package of the release deployment state records, verifies it, authenticates using the available Azure credential, parses encryption metadata from the package, and executes the full Graph API upload flow.
When intune.build_types is "both" (the default), two Intune app entries are created: an install entry (detection script only) and an update entry (detection + requirements scripts). Each entry is created, uploaded, and committed in sequence before moving to the next. The recipe's build_types must be the one the package was built with.
The package directory is packages/{app.id}/{version}/ for the recorded release (pending, else published), or the only package when none is recorded. Run 'napt package' before calling this function.
Authentication needs no configuration file:
- Developers: run 'napt auth login' once
- CI/CD: set AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, or use OIDC federation
Before any Graph call, the .intunewin is re-hashed against what 'napt package' recorded, and the package's installer hash (from the build manifest) is verified against the pending release recorded in the app's deployment state, so what was recorded at discovery is byte-for-byte what ships. A hash mismatch aborts the upload. A package matching the published release (a re-run after writeback, or a --force refresh) passes too. When it matches neither, the upload proceeds with a warning, or fails when deployment.require_pending is enabled. On success, the deployment state records the published version, hash, and Intune app IDs, and a matching pending slot is cleared.
Re-running an upload is safe: existing NAPT-stamped apps matching this publish instance (recipe id, entry type, installer hash) are adopted instead of duplicated; one whose content was never committed is deleted and recreated, so it gets a new app ID. Adoption keeps the app as it is; it does not re-send metadata or content. Pass force=True to update matched apps' metadata and upload a fresh content version (e.g., after changing PSADT commands or detection settings without a new installer release).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe YAML file. |
required |
force
|
bool
|
When True, matched stamped apps are re-uploaded (metadata and content) instead of adopted as-is. Never creates duplicates. |
False
|
state_dir
|
Path | None
|
State root whose deployment/ folder records the release. If None, reads from config directories.state. |
None
|
packages_dir
|
Path | None
|
Directory holding the packages. If None, reads from config directories.package. |
None
|
Returns:
| Type | Description |
|---|---|
UploadResult
|
Upload result including the Intune app ID(s), app name, version, and package path. intune_app_id is None when build_types is "update_only"; intune_update_app_id is None when build_types is "app_only". |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the package of the recorded release is not found, several packages exist with none recorded, the manifest is unusable, the recipe's build_types differs from the package's, or a script the manifest names is missing. Run 'napt package' to create or recreate the package. |
AuthError
|
If all Azure credential methods fail. |
NetworkError
|
If Graph API or Azure Blob Storage calls fail. |
PackagingError
|
If the .intunewin file is malformed or no longer matches the hash 'napt package' recorded, the package's installer hash does not match the pending release in deployment state, or it matches neither pending nor published while deployment.require_pending is enabled. |
StateError
|
On a corrupted deployment state file. |
Example
Upload and print the resulting Intune app IDs:
Source code in napt/upload/manager.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | |
napt.upload.intunewin
Parses .intunewin package files for NAPT upload operations.
A .intunewin file is a ZIP archive created by IntuneWinAppUtil with the following structure:
IntuneWinPackage/
Contents/
IntunePackage.intunewin <- encrypted payload
Metadata/
Detection.xml <- encryption metadata
This module extracts the encryption metadata from Detection.xml and provides utilities for extracting the encrypted payload for upload to Azure Blob Storage.
IntunewinMetadata
dataclass
Encryption metadata extracted from a .intunewin package.
All fields are sourced from Detection.xml inside the .intunewin ZIP archive. This metadata is required by the Graph API file commit endpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
encrypted_file_name |
str
|
Filename of the encrypted payload inside the Contents/ directory (always "IntunePackage.intunewin"). |
unencrypted_content_size |
int
|
Original size in bytes before encryption. |
file_digest |
str
|
Base64-encoded SHA-256 hash of the encrypted payload. |
file_digest_algorithm |
str
|
Hash algorithm used (always "SHA256"). |
encryption_key |
str
|
Base64-encoded AES-256 encryption key. |
mac_key |
str
|
Base64-encoded HMAC key for MAC verification. |
init_vector |
str
|
Base64-encoded AES initialization vector. |
mac |
str
|
Base64-encoded MAC value for integrity verification. |
profile_identifier |
str
|
Encryption profile version (always "ProfileVersion1"). |
encrypted_file_size |
int
|
Byte size of the encrypted payload file. |
Source code in napt/upload/intunewin.py
parse_intunewin
Parse a .intunewin package and extract encryption metadata.
Reads IntuneWinPackage/Metadata/Detection.xml from inside the .intunewin ZIP and returns all encryption fields required for the Graph API upload flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intunewin_path
|
Path
|
Path to the .intunewin file to parse. |
required |
Returns:
| Type | Description |
|---|---|
IntunewinMetadata
|
Parsed encryption metadata from Detection.xml. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the file is not a valid ZIP, Detection.xml is missing, or required XML fields are absent or malformed. |
Example
Parse an existing package:
Source code in napt/upload/intunewin.py
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 | |
extract_encrypted_payload
Extract the encrypted payload from a .intunewin package.
Extracts IntuneWinPackage/Contents/IntunePackage.intunewin to the destination directory for upload to Azure Blob Storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intunewin_path
|
Path
|
Path to the .intunewin file. |
required |
dest_dir
|
Path
|
Directory to extract the payload into. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the extracted encrypted payload file. |
Raises:
| Type | Description |
|---|---|
PackagingError
|
If the file is not a valid ZIP or the payload is missing. |