From ad0dd44130b0bdba0fc6983dc4c5e7ce1ef15fb2 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 6 May 2025 03:36:01 -0400 Subject: [PATCH] engine: Don't force validation for hidden resources I think this is what I want in most scenarios, is there a reason to do otherwise? This is because we may wish to export incomplete resources, where the remaining necessary fields for validation happens on collect. --- engine/metaparams.go | 3 ++- engine/resources.go | 6 ++++++ .../TestAstFunc2/validate-hidden1.txtar | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 lang/interpret_test/TestAstFunc2/validate-hidden1.txtar diff --git a/engine/metaparams.go b/engine/metaparams.go index a2c4b069..944a4890 100644 --- a/engine/metaparams.go +++ b/engine/metaparams.go @@ -154,7 +154,8 @@ type MetaParams struct { // named resources. It can even be used as part of an edge or via a // send/recv receiver. It can NOT be a sending vertex. These properties // differentiate the use of this instead of simply wrapping a resource - // in an "if" statement. + // in an "if" statement. If it is hidden, then it does not need to pass + // the resource Validate method step. Hidden bool `yaml:"hidden"` // Export is a list of hostnames (and/or the special "*" entry) which if diff --git a/engine/resources.go b/engine/resources.go index 4a1c2e2d..0eb04a11 100644 --- a/engine/resources.go +++ b/engine/resources.go @@ -312,6 +312,12 @@ func Validate(res Res) error { return fmt.Errorf("the Res name starts with a $") } + // Don't need to validate normally if hidden. + // XXX: Check if it's also Exported too? len(res.MetaParams.Export) > 0 + if res.MetaParams().Hidden { + return nil + } + return res.Validate() } diff --git a/lang/interpret_test/TestAstFunc2/validate-hidden1.txtar b/lang/interpret_test/TestAstFunc2/validate-hidden1.txtar new file mode 100644 index 00000000..97f368d8 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/validate-hidden1.txtar @@ -0,0 +1,11 @@ +-- main.mcl -- +line "whatever" { + #file => "", # specified on collect + #state => "", # specified on collect + content => "hello", + + Meta:hidden => true, # should Validate even though fields are missing. + #Meta:export => ["*",], +} +-- OUTPUT -- +Vertex: line[whatever]