Commit 161ae18
authored
Gate rule type engine construction on provider_traits (#6702)
* Gate rule type engine construction on provider_traits
Reject rule types at construction time when the provider does not
implement all traits listed in the rule type's provider_traits, the
same way entity-type mismatches are already handled up front rather
than via a runtime ErrEvaluationSkipped.
The trait check is declared as a package-local interface in rtengine
rather than added to interfaces.Provider: that package cannot import
minderv1 without creating an import cycle (minderv1 transitively
imports pkg/datasources/v1, which imports pkg/engine/v1/interfaces).
Every concrete provider already implements CanImplement with this
exact signature, so they satisfy the interface structurally with no
provider-side changes.
* Add tests for provider_traits gating in rtengine
Extend TestKit with a configurable CanImplement (via WithCanImplement),
defaulting to true so existing callers are unaffected, and add cases
to engine_test.go covering: no provider_traits (unaffected), all
required traits satisfied (succeeds), and a missing trait (fails with
a clear error).
* Skip (not abort) rule types with unsatisfied provider_traits
* Move DataSourceDriver constants to minderv1 to break import cycle
* Widen interfaces.Provider with CanImplement, simplify provider_traits loop
* Add provider_traits coverage to mindev integration tests
* Replace provider_traits sentinel error with SupportedByProvider
RuleTypeEngine now computes whether the provider satisfies the rule
type's provider_traits once at construction time and exposes it via
SupportedByProvider(), instead of NewRuleTypeEngine returning a
wrapped sentinel error that callers had to unwrap with errors.Is.
The rule engine cache no longer excludes unsatisfied rule types from
its population loop, so every rule type in the hierarchy is cached
regardless of applicability. The executor checks
SupportedByProvider() before evaluating a rule and, if false, returns
early ahead of createOrUpdateEvalStatus so no eval status row is
written for a rule type that isn't applicable to the entity's
provider.
An unrecognized trait name (e.g. a typo, or a rule type stored before
provider_traits validation existed) is treated as unsupported and
logs a warning, distinguishing it from a provider that simply doesn't
implement a valid trait.
* Change provider_traits to a list of strings in the proto
RuleType.Definition.provider_traits was `repeated ProviderType`,
requiring the numeric enum value in JSON/YAML rule type definitions.
Change it to `repeated string`, using the same short trait names
("github", "git", "rest", "oci", "repo-lister", "image-lister")
already used elsewhere for provider class definitions.
Field 8 (the old enum field) is reserved rather than reused, since
the two field types have different wire encodings and reusing the
number would let old serialized data misparse instead of failing
loudly. The new field is 9. proto/buf.yaml gains a narrowly scoped
buf breaking exception: WIRE_JSON requires the field *name* to also
be reserved on deletion, which conflicts with intentionally reusing
"provider_traits" for the new field. This is called out as a
deliberate, sanctioned break, since the field has never been
documented or used.
ProviderTypeFromString, backed by the same (name) option lookup
ToString already uses, converts a trait string to its ProviderType.
Rule type validation now rejects unknown trait strings at
creation/update time, naming the valid values in the error - this is
the only safeguard against a typo silently making a rule type never
evaluate.
* Use a positive provider trait list in the ruletest harness
Rename eval()'s provider_missing_traits argument to
provider_traits_present and invert its semantics: it now lists the
traits the test provider does implement, rather than the ones it
doesn't. The default when the argument is omitted is unchanged - all
traits are present.
parseProviderTraitsList now accepts the same short trait names used
in rule type YAML (e.g. "github") via ProviderTypeFromString, instead
of full enum names like "PROVIDER_TYPE_GITHUB", and its error on an
unrecognized value lists the valid trait names.
eval() now checks the rule type engine's SupportedByProvider() before
evaluating and reports a "skip" result if the provider doesn't
implement a required trait, mirroring - but distinct from - the
production executor's zero-footprint no-op for the same case: a test
still needs eval() to return something a test author can assert on.
* Build provider trait name lookup as a map at init
Replaces per-call descriptor iteration in ProviderTypeFromString and the
duplicated valid-name lists in ruletypes and ruletest.
* Report unknown provider_traits entries as an evaluation error
An unrecognized trait name is a rule type authoring problem the user can
fix, so it now surfaces as an eval status error naming every offending
trait. A known trait the provider doesn't implement still produces no
eval status row at all.
* Document ProviderType names as a stable interface
Also removes the pkg/datasources/v1 driver constants outright rather than
leaving deprecated aliases, and notes the buf exception is removable once
this merges.
* Regenerate GitHub provider mocks for CanImplement
* Simplify ProviderTypeFromString to return a bare ProviderType
PROVIDER_TYPE_UNSPECIFIED is the zero value and absent from the lookup
table, so it already signals a miss and the bool was redundant.
* Add a gitlab provider trait
Lets a rule type declare [rest, gitlab] for the GitLab API, the
counterpart to [rest, github]. The GitLab provider client implements it;
there is deliberately no matching provider_type database enum value,
since trait gating happens through CanImplement rather than the
providers table.1 parent e5901e1 commit 161ae18
29 files changed
Lines changed: 1088 additions & 285 deletions
File tree
- docs/docs/ref
- internal
- datasources/service
- engine
- rtengine
- providers
- github/mock
- gitlab
- pkg
- api
- openapi/minder/v1
- protobuf/go/minder/v1
- datasources/v1
- engine/v1
- interfaces
- rtengine
- providers/v1
- mock
- ruletest
- testdata
- ruletypes
- testkit/v1
- proto
- minder/v1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
| 49 | + | |
51 | 50 | | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
55 | | - | |
| 54 | + | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
| |||
100 | 99 | | |
101 | 100 | | |
102 | 101 | | |
103 | | - | |
| 102 | + | |
104 | 103 | | |
105 | 104 | | |
106 | 105 | | |
107 | | - | |
| 106 | + | |
108 | 107 | | |
109 | 108 | | |
110 | | - | |
| 109 | + | |
111 | 110 | | |
112 | 111 | | |
113 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
| 541 | + | |
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
| |||
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
558 | | - | |
| 558 | + | |
559 | 559 | | |
560 | 560 | | |
561 | 561 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
96 | | - | |
| 95 | + | |
97 | 96 | | |
98 | 97 | | |
99 | 98 | | |
| |||
230 | 229 | | |
231 | 230 | | |
232 | 231 | | |
233 | | - | |
| 232 | + | |
234 | 233 | | |
235 | 234 | | |
236 | 235 | | |
| |||
348 | 347 | | |
349 | 348 | | |
350 | 349 | | |
351 | | - | |
| 350 | + | |
352 | 351 | | |
353 | 352 | | |
354 | 353 | | |
| |||
628 | 627 | | |
629 | 628 | | |
630 | 629 | | |
631 | | - | |
| 630 | + | |
632 | 631 | | |
633 | 632 | | |
634 | 633 | | |
| |||
1147 | 1146 | | |
1148 | 1147 | | |
1149 | 1148 | | |
1150 | | - | |
| 1149 | + | |
1151 | 1150 | | |
1152 | 1151 | | |
1153 | 1152 | | |
| |||
1221 | 1220 | | |
1222 | 1221 | | |
1223 | 1222 | | |
1224 | | - | |
| 1223 | + | |
1225 | 1224 | | |
1226 | 1225 | | |
1227 | 1226 | | |
| |||
1357 | 1356 | | |
1358 | 1357 | | |
1359 | 1358 | | |
1360 | | - | |
| 1359 | + | |
1361 | 1360 | | |
1362 | 1361 | | |
1363 | 1362 | | |
| |||
1402 | 1401 | | |
1403 | 1402 | | |
1404 | 1403 | | |
1405 | | - | |
| 1404 | + | |
1406 | 1405 | | |
1407 | 1406 | | |
1408 | 1407 | | |
| |||
1496 | 1495 | | |
1497 | 1496 | | |
1498 | 1497 | | |
1499 | | - | |
| 1498 | + | |
1500 | 1499 | | |
1501 | 1500 | | |
1502 | 1501 | | |
| |||
1624 | 1623 | | |
1625 | 1624 | | |
1626 | 1625 | | |
1627 | | - | |
| 1626 | + | |
1628 | 1627 | | |
1629 | 1628 | | |
1630 | 1629 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
182 | 198 | | |
183 | 199 | | |
184 | 200 | | |
| |||
192 | 208 | | |
193 | 209 | | |
194 | 210 | | |
195 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
196 | 217 | | |
197 | | - | |
| 218 | + | |
198 | 219 | | |
199 | 220 | | |
200 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
251 | 304 | | |
252 | 305 | | |
253 | 306 | | |
| |||
305 | 358 | | |
306 | 359 | | |
307 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
0 commit comments