Skip to content

Commit

Permalink
Fixes #25579: System variable can be empty early on the generation pr…
Browse files Browse the repository at this point in the history
…ocess
  • Loading branch information
fanf committed Sep 30, 2024
1 parent 6bb26f0 commit 57e77df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,10 @@ final case class BoundPolicyDraft(
)
}
// check if there is mandatory variable with missing/blank values
// NOTE : it's OK that system variables are not filled here yet
(
variable.spec.constraint.mayBeEmpty,
variable.values.exists(v => v == null || v.isEmpty)
variable.spec.constraint.mayBeEmpty || variable.spec.isSystem,
variable.values.isEmpty || variable.values.exists(v => v == null || v.isEmpty)
) match {
// simple case: it's optional, we don't care if empty or not.
case (true, _) => Right((cid, variable))
Expand Down Expand Up @@ -651,7 +652,8 @@ final case class BoundPolicyDraft(
// add missing if possible
added <- missing.accumulatePure {
case (_, (cid, spec)) =>
(spec.constraint.mayBeEmpty, spec.constraint.default) match {
// if mayBeEmpty or if it's a system variable, just add it - empty.
(spec.constraint.mayBeEmpty || spec.isSystem, spec.constraint.default) match {
case (true, _) => Right((cid, spec.toVariable()))
case (false, Some(d)) => Right((cid, spec.toVariable(Seq(d))))
case (false, None) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,8 @@ class PrepareTemplateVariablesImpl(
systemVars: Map[String, Variable]
): IOResult[Seq[STVariable]] = {

// we want to check that all technique variables are correctly provided.
// we can't do it when we built node configuration because some (system variable at least (note: but only? If so, we could just check
// them here, not everything).

ZIO.foreach(policy.trackerVariable :: (systemVars.values ++ policy.expandedVars.values).toList)(v =>
// here, we want to be sure to get the system variable that were late defined in priority.
ZIO.foreach(policy.trackerVariable :: (policy.expandedVars ++ systemVars).values.toList)(v =>
stVariableFromVariable(v, agentVariableHandler, agentNodeProps.nodeId, policy.technique.id)
)
}
Expand Down

0 comments on commit 57e77df

Please sign in to comment.