NAH 1.0.6
Native Application Host - Library API Reference
Loading...
Searching...
No Matches
host_profile.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "nah/types.hpp"
4
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9namespace nah {
10
11// ============================================================================
12// Host Profile (per SPEC L499-L500, L580-L795)
13// ============================================================================
14
16 std::string schema; // MUST be "nah.host.profile.v1"
17
18 // [nak] section (per SPEC L637-L652)
19 struct {
21 std::vector<std::string> allow_versions; // prefix patterns ending in *
22 std::vector<std::string> deny_versions; // prefix patterns ending in *
23 std::unordered_map<std::string, std::string> map; // selection_key -> record_ref
24 } nak;
25
26 // [environment] section
27 std::unordered_map<std::string, std::string> environment;
28
29 // [paths] section
30 struct {
31 std::vector<std::string> library_prepend;
32 std::vector<std::string> library_append;
34
35 // [warnings] section - maps warning key to action
36 std::unordered_map<std::string, WarningAction> warnings;
37
38 // [capabilities] section - maps capability key to enforcement ID
39 std::unordered_map<std::string, std::string> capabilities;
40
41 // [overrides] section
42 struct {
44 std::vector<std::string> allow_keys;
46
47 // Source path for trace
48 std::string source_path;
49};
50
51// Built-in empty profile (per SPEC L614-L628)
53
54// ============================================================================
55// Host Profile Parsing Result
56// ============================================================================
57
59 bool ok = false;
60 std::string error;
62 std::vector<std::string> warnings;
63};
64
65// Parse a Host Profile from TOML string
67 const std::string& source_path = "");
68
69// ============================================================================
70// Warning Policy Application
71// ============================================================================
72
73// Get the effective action for a warning key given a profile
74// Returns "warn" if the key is not present (per SPEC Default Warning Action)
76WarningAction get_warning_action(const HostProfile& profile, const std::string& warning_key);
77
78// ============================================================================
79// NAK Version Allow/Deny Matching (per SPEC L695)
80// ============================================================================
81
82// Check if a version matches a pattern (prefix with optional *)
83bool version_matches_pattern(const std::string& version, const std::string& pattern);
84
85// Check if a version is allowed by profile rules
86// Deny rules take precedence over allow rules
87bool version_allowed_by_profile(const std::string& version, const HostProfile& profile);
88
89// ============================================================================
90// Override Policy (per SPEC L701-L717)
91// ============================================================================
92
93// Check if an override target is permitted by profile policy
94// Returns true if permitted, false if denied
95bool is_override_permitted(const std::string& target, const HostProfile& profile);
96
97// Legacy API for backward compatibility
99 std::string schema;
100 std::string binding_mode;
101};
102
104 bool ok;
105 std::string error;
106};
107
109
110} // namespace nah
Result type for fallible operations.
Definition nahhost.hpp:109
WarningAction
Definition types.hpp:73
BindingMode
Definition types.hpp:266
HostProfile get_builtin_empty_profile()
bool version_matches_pattern(const std::string &version, const std::string &pattern)
OverrideMode
Definition types.hpp:245
Warning
Definition types.hpp:14
bool version_allowed_by_profile(const std::string &version, const HostProfile &profile)
HostProfileParseResult parse_host_profile_full(const std::string &toml_str, const std::string &source_path="")
bool is_override_permitted(const std::string &target, const HostProfile &profile)
HostProfileValidation parse_host_profile(const std::string &toml, HostProfileRecord &out)
WarningAction get_warning_action(const HostProfile &profile, Warning warning)
std::vector< std::string > warnings
std::unordered_map< std::string, std::string > map
std::string schema
std::unordered_map< std::string, std::string > environment
std::vector< std::string > library_prepend
struct nah::HostProfile::@0 nak
struct nah::HostProfile::@1 paths
std::string source_path
std::unordered_map< std::string, std::string > capabilities
std::vector< std::string > allow_versions
std::unordered_map< std::string, WarningAction > warnings
BindingMode binding_mode
OverrideMode mode
struct nah::HostProfile::@2 overrides
std::vector< std::string > allow_keys
std::vector< std::string > library_append
std::vector< std::string > deny_versions