Method WithGuardrailFiles
- Namespace
- IntentSharp.Guardrails
- Assembly
- IntentSharp.Guardrails.dll
WithGuardrailFiles(IntentClientBuilder, IDocumentStore, params string[])
Makes the client check the rule files store holds, applying sets when a check
names none. See WithGuardrailFiles(IntentClientBuilder, IDocumentStore, Action<GuardrailSourceOptions>, params string[]).
public static IntentClientBuilder WithGuardrailFiles(this IntentClientBuilder builder, IDocumentStore store, params string[] sets)
Parameters
builderIntentClientBuilderThe builder.
storeIDocumentStoreThe store that holds the manifest and the rule files; pass the same store to WithDocumentStore(IDocumentStore).
setsstring[]The default sets; each must be loaded when the client is built.
Returns
Remarks
The client does not dispose the DocumentGuardrailSource this creates, and it needs no disposing: it holds no callback on the store and reads the store only when a check uses it, so nothing is left behind when the client is disposed or a build fails.
Exceptions
- ArgumentNullException
builder,storeorsetsis null.- InvalidOperationException
Guardrails were already set on this builder.
WithGuardrailFiles(IntentClientBuilder, IDocumentStore, Action<GuardrailSourceOptions>, params string[])
Makes the client check the rule files store holds: a DocumentGuardrailSource with
the options configure sets becomes the client's guardrail source, with sets
as the default sets, the kinds, subjects and settings the options declare, and their
CodeSettings as the client's code layer
(CodeSettings); the built-in schema kind, the YAML format and the
RuleDocumentValidator are added to the client. The validator compares a raised client.* limit
that no running version sets with this builder's IntentClientOptions value when the code settings do
not set it, as the client applies it, a value set after this call included. Like
WithGuardrails(GuardrailOptions), it is called once per builder, and
Build() throws when a default set is not loaded.
public static IntentClientBuilder WithGuardrailFiles(this IntentClientBuilder builder, IDocumentStore store, Action<GuardrailSourceOptions> configure, params string[] sets)
Parameters
builderIntentClientBuilderThe builder.
storeIDocumentStoreThe store that holds the manifest and the rule files; pass the same store to WithDocumentStore(IDocumentStore).
configureAction<GuardrailSourceOptions>Sets the source's options, such as the manifest's path, pinned hashes, and custom kinds, subjects and settings; runs once, now.
setsstring[]The default sets; each must be loaded when the client is built.
Returns
Remarks
The source and the validator also know the settings and subjects declared on the builder with
AddSetting(SettingDescriptor) and AddSubject(SubjectDescriptor), such as those a
package's builder extension declares, whether those calls come before or after this one: they receive them when the
client is built (OnBuild). So a rule file's settings: block may set such a
setting, and its rules may name such a subject, with nothing declared again here. A descriptor declared both here
and on the builder is one declaration when it is the same descriptor (the same object, or one equal in every property); two different descriptors with one name stop the
client from building. A code setting in CodeSettings still names a setting
declared here or in the core, since it is checked on this call.
The client does not dispose the source this creates, and it needs no disposing: it holds no callback on the store and reads the store only when a check uses it, so nothing is left behind when the client is disposed or a build fails.
No rules written as intent compile on this call alone: call WithRuleCompilation(IntentClientBuilder, IDocumentStore, Action<RuleCompileOptions>?)
as well (experimental, INTENTSHARP001). Without it, a rule file that lists compile: loads with its
authored rules only.
The source logs nothing on this path; to log its problems, create a DocumentGuardrailSource with a logger and pass it to WithGuardrails(IGuardrailSource, params string[]), with the format and the validator added yourself; such a source knows only the declarations of its own options. Its Problems are reachable through the client's Guardrails either way.
Exceptions
- ArgumentNullException
builder,store,configureorsetsis null.- ArgumentException
A code setting the options hold is not a declared setting, or holds a value the setting cannot take.
- InvalidOperationException
Guardrails were already set on this builder.