载入中...
搜索中...
未找到
FactStore.cpp
浏览该文件的文档.
30bool exactFields(const eve::Value::Object& object, std::initializer_list<std::string_view> allowed) {
64 eve::DiagnosticCode::InvalidArgument, "unknown condition reason code", "reason", {}, "emergence.fact"));
71 eve::DiagnosticCode::InvalidArgument, "policy result must be an object", {}, {}, "emergence.fact"));
74 eve::DiagnosticCode::InvalidArgument, "policy result contains an unknown field", {}, {}, "emergence.fact"));
79 eve::DiagnosticCode::InvalidArgument, "policy passed must be a boolean", "passed", {}, "emergence.fact"));
82 eve::DiagnosticCode::InvalidArgument, "policy reason must be a string", "reason", {}, "emergence.fact"));
117 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, message, "key", {}, "emergence.fact"));
142 return eve::Result<std::pair<FactDomain, std::string>>::success(std::make_pair(domain, std::string(name)));
240std::optional<condition::ConditionResult> FactStore::policy(std::string_view name, const eve::Value& arguments) const {
241 if (auto authority = condition::resolveAuthorityAllow(name, arguments, [this](std::string_view scope) {
286 eve::DiagnosticCode::InvalidArgument, "fact snapshot must be an object", {}, {}, "emergence.fact"));
287 if (!exactFields(*object, {"schema", "version", "values", "tags", "attributes", "resources", "states",
290 eve::DiagnosticCode::InvalidArgument, "fact snapshot contains an unknown field", {}, {}, "emergence.fact"));
295 eve::DiagnosticCode::InvalidArgument, "unexpected fact snapshot schema", "schema", {}, "emergence.fact"));
298 eve::DiagnosticCode::UnknownVersion, "unsupported fact snapshot version", "version", {}, "emergence.fact"));
307 eve::DiagnosticCode::InvalidArgument, "fact field must be an object", fieldName, {}, "emergence.fact"));
Canonical Compare key prefixes and PolicyCall names for thin conditions.
Stable, structured diagnostics shared by engine modules.
Authoritative, rule-visible world facts implementing EvaluationContext.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:187
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
Explain one condition evaluation in a UI- and log-friendly form.
Definition Condition.h:137
static ConditionResult success(Value evidence={}, Value details=Value::Object{})
Construct a passed result with optional evidence and details.
Definition Condition.cpp:131
static ConditionResult failed(ConditionReasonCode reason, Value evidence={}, Value details=Value::Object{})
Construct a rejected result with a stable reason and explanation.
Definition Condition.cpp:135
Mutable fact bag that doubles as a read-only Condition evaluation context.
Definition FactStore.h:60
std::string snapshotJson() const
Export deterministic compact JSON for runtime snapshots.
Definition FactStore.cpp:251
eve::Result< void > restoreJson(std::string_view json)
Transactionally restore facts from a snapshot produced by snapshotJson().
Definition FactStore.cpp:280
std::optional< condition::ConditionResult > policy(std::string_view name, const eve::Value &arguments) const override
Evaluate a named read-only policy with owned arguments.
Definition FactStore.cpp:240
FactChange setValue(std::string key, eve::Value value)
Set a compare/value fact.
Definition FactStore.cpp:167
FactChange setTag(std::string tag, bool present)
Set tag membership; present=true means the tag exists.
Definition FactStore.cpp:172
FactChange setState(std::string key, eve::Value value)
Set a state value.
Definition FactStore.cpp:187
FactChange setAttribute(std::string key, eve::Value value)
Set an attribute value.
Definition FactStore.cpp:177
FactChange setPolicy(std::string name, condition::ConditionResult result)
Register or replace a read-only policy result.
Definition FactStore.cpp:197
FactChange setAuthority(std::string scope, bool granted)
Set authority for a scope.
Definition FactStore.cpp:192
FactChange setResource(std::string key, eve::Value value)
Set a resource value.
Definition FactStore.cpp:182
std::optional< eve::Value > value(std::string_view key) const override
Query a named scalar or structured value for Compare nodes.
Definition FactStore.cpp:219
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
ConditionReasonCode
Stable machine-readable explanation code for a condition outcome.
Definition Condition.h:82
constexpr std::string_view kResourcePrefix
Prefix for resource values (resource:<name>).
Definition ConditionKeys.h:25
constexpr std::string_view kStatePrefix
Prefix for state values (state:<name>).
Definition ConditionKeys.h:27
const char * conditionReasonCodeName(ConditionReasonCode code) noexcept
Return the stable lowercase spelling of a condition reason code. @ownership Borrowed process-static t...
Definition Condition.cpp:84
constexpr std::string_view kTagPrefix
Prefix for tag membership booleans (tag:<name>).
Definition ConditionKeys.h:21
std::optional< ConditionResult > resolveAuthorityAllow(std::string_view name, const Value &arguments, AuthorityQuery &&authorityQuery)
Resolve the built-in authority.allow policy when name matches.
Definition ConditionKeys.h:158
std::optional< std::string_view > stripPrefix(std::string_view key, std::string_view prefix)
Strip a known domain prefix from a key.
Definition ConditionKeys.h:89
constexpr std::string_view kAttrPrefix
Prefix for attribute values (attr:<name>).
Definition ConditionKeys.h:23
Definition ConditionCodec.cpp:13
@ Unchanged
@ Changed
@ Authority
@ Resource
@ Attribute
eve::Result< std::pair< FactDomain, std::string > > parseFactKey(std::string_view key)
Parse a canonical watch key into domain and leaf name.
Definition FactStore.cpp:114
std::string makeFactKey(FactDomain domain, std::string_view name)
Build the canonical watch key for one fact domain.
Definition FactStore.cpp:107
@ InvalidArgument
@ UnknownVersion
@ Applied