Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceMacBuche committed Nov 30, 2021
1 parent 710b8a6 commit cf4489b
Show file tree
Hide file tree
Showing 12 changed files with 607 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ final case class ByRuleRuleCompliance(
, compliance : ComplianceLevel
, mode : ComplianceModeName
, directives : Seq[ByRuleDirectiveCompliance]
)
) {
val nodes = ByRuleByNodeCompliance.fromDirective(directives).toSeq
}

final case class ByRuleDirectiveCompliance(
id : DirectiveId
Expand All @@ -92,6 +94,7 @@ final case class ByRuleDirectiveCompliance(
, components: Seq[ByRuleComponentCompliance]
)


sealed trait ByRuleComponentCompliance {
def name : String
def compliance : ComplianceLevel
Expand All @@ -112,9 +115,84 @@ final case class ByRuleValueCompliance(
final case class ByRuleNodeCompliance(
id : NodeId
, name : String
, compliance: ComplianceLevel
, values: Seq[ComponentValueStatusReport]
)

final case class ByRuleByNodeCompliance(
id : NodeId
, name : String
, compliance: ComplianceLevel
, directives: Seq[ByRuleByNodeByDirectiveCompliance]
)

final case class ByRuleByNodeByDirectiveCompliance(
id : DirectiveId
, name : String
, compliance: ComplianceLevel
, components: Seq[ByRuleByNodeByDirectiveByComponentCompliance]
)

sealed trait ByRuleByNodeByDirectiveByComponentCompliance {
def name : String
def compliance : ComplianceLevel
}

final case class ByRuleByNodeByDirectiveByBlockCompliance(
name : String
, compliance: ComplianceLevel
, subComponents : Seq[ByRuleByNodeByDirectiveByComponentCompliance]
) extends ByRuleByNodeByDirectiveByComponentCompliance

final case class ByRuleByNodeByDirectiveByValueCompliance(
name : String
, compliance: ComplianceLevel
, values : Seq[ComponentValueStatusReport]
) extends ByRuleByNodeByDirectiveByComponentCompliance

object ByRuleByNodeCompliance {
def fromDirective(directives : Seq[ByRuleDirectiveCompliance]) = {
final case class TmpStruct (directiveId: DirectiveId, blocks: List[String], component: String, node : ByRuleNodeCompliance)
def recurseComponent( byRuleComponentCompliance: ByRuleComponentCompliance): Seq[(NodeId,ByRuleByNodeByDirectiveByComponentCompliance)] = {
byRuleComponentCompliance match {
case b : ByRuleBlockCompliance =>
b.subComponents.flatMap(s =>
for {
(nodeId, s) <- recurseComponent(s).groupBy(_._1)
} yield {
val subs = s.map(_._2)
(nodeId,ByRuleByNodeByDirectiveByBlockCompliance(b.name, ComplianceLevel.sum(subs.map(_.compliance)), subs))
}
)

case v : ByRuleValueCompliance =>
(for {
(nodeId, data) <- v.nodes.groupBy(_.id)
} yield {
(nodeId, ByRuleByNodeByDirectiveByValueCompliance(v.name, ComplianceLevel.sum(data.map(_.compliance)),data.flatMap(_.values)))
}).toSeq
}
}
for {
(nodeId, data) <- directives.flatMap { d =>
d.components.flatMap(s =>
for {
(nodeId, s) <- recurseComponent(s).groupBy(_._1)
} yield {
val subs = s.map(_._2)
(nodeId,ByRuleByNodeByDirectiveCompliance(d.id,d.name, ComplianceLevel.sum(subs.map(_.compliance)), subs))
}
)
}.groupBy(_._1)

} yield {
val subs = data.map(_._2)
ByRuleByNodeCompliance(nodeId, nodeId.value, ComplianceLevel.sum(subs.map(_.compliance)), subs)
}
}


}
/**
* Compliance for a node.
* It lists:
Expand Down Expand Up @@ -209,6 +287,7 @@ object JsonCompliance {
~ ("mode" -> rule.mode.name)
~ ("complianceDetails" -> percents(rule.compliance))
~ ("directives" -> directives(rule.directives, level) )
~ ("nodes" -> byNodes(rule.nodes, level) )
)

private[this] def directives(directives: Seq[ByRuleDirectiveCompliance], level: Int): Option[JsonAST.JValue] = {
Expand All @@ -223,7 +302,31 @@ object JsonCompliance {
)
})
}
private[this] def byNodes(nodes: Seq[ByRuleByNodeCompliance], level: Int): Option[JsonAST.JValue] = {
if(level < 2) None
else Some( nodes.map { node =>
(
("id" -> node.id.value)
~ ("name" -> node.name)
~ ("compliance" -> node.compliance.complianceWithoutPending)
~ ("complianceDetails" -> percents(node.compliance))
~ ("components" -> byNodesByDirectives(node.directives, level))
)
})
}

private[this] def byNodesByDirectives(directives: Seq[ByRuleByNodeByDirectiveCompliance], level: Int): Option[JsonAST.JValue] = {
if(level < 3) None
else Some( directives.map { directive =>
(
("id" -> directive.id.serialize)
~ ("name" -> directive.name)
~ ("compliance" -> directive.compliance.complianceWithoutPending)
~ ("complianceDetails" -> percents(directive.compliance))
~ ("components" -> byNodeByDirectiveByComponents(directive.components, level))
)
})
}
private[this] def components(comps: Seq[ByRuleComponentCompliance], level: Int): Option[JsonAST.JValue] = {
if(level < 3) None
else Some(comps.map { component =>
Expand All @@ -241,25 +344,49 @@ object JsonCompliance {
})
}

private[this] def byNodeByDirectiveByComponents(comps: Seq[ByRuleByNodeByDirectiveByComponentCompliance], level: Int): Option[JsonAST.JValue] = {
if(level < 4) None
else Some(comps.map { component =>
(
("name" -> component.name)
~ ("compliance" -> component.compliance.complianceWithoutPending)
~ ("complianceDetails" -> percents(component.compliance))
~ (component match {
case component : ByRuleByNodeByDirectiveByBlockCompliance =>
("components" -> byNodeByDirectiveByComponents(component.subComponents, level))
case component: ByRuleByNodeByDirectiveByValueCompliance =>
("values" -> values(component.values, level))
})
)
})
}

def values(values : Seq[ComponentValueStatusReport], level : Int): Option[JsonAST.JValue] = {
if(level < 5) None
else Some(values.map { value =>
(
("value" -> value.componentValue)
~ ("reports" -> value.messages.map { report =>
(
("status" -> statusDisplayName(report.reportType))
~ ("message" -> report.message)
)
})
)
})
}
private[this] def nodes(nodes: Seq[ByRuleNodeCompliance], level: Int): Option[JsonAST.JValue] = {
if(level < 4) None
else Some(nodes.map { node =>
(
("id" -> node.id.value)
~ ("name" -> node.name)
~ ("values" -> node.values.map { value =>
(
("value" -> value.componentValue)
~ ("reports" -> value.messages.map { report =>
(
("status" -> statusDisplayName(report.reportType))
~ ("message" -> report.message)
)
})
)
})
~ ("compliance" -> node.compliance.complianceWithoutPending)
~ ("complianceDetails" -> percents(node.compliance))
~ ("values" -> values(node.values, level))
)
})

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class ComplianceAPIService(
ByRuleNodeCompliance(
nodeId
, nodeInfos.get(nodeId).map(_.hostname).getOrElse("Unknown node")
, ComplianceLevel.sum(uniqueComponents.find(_._1 == nodeId).map(_._2.compliance).toList)
, uniqueComponents.toSeq.sortBy(_._2.componentName).flatMap(_._2.componentValues.values)
)
}.toSeq
Expand Down
20 changes: 10 additions & 10 deletions webapp/sources/rudder/rudder-web/src/main/elm/rules/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/random": "1.0.0",
"elm/url": "1.0.0",
"elm-community/dict-extra": "2.4.0",
"elm-community/list-extra": "8.1.0",
"elm-community/maybe-extra": "5.2.0",
"mcordova47/elm-natural-ordering": "1.0.5"
"elm-community/list-extra": "8.5.1",
"elm-community/maybe-extra": "5.2.1",
"mcordova47/elm-natural-ordering": "1.0.5",
"toastal/either": "3.6.3",
"webbhuset/elm-json-decode": "1.1.0"
},
"indirect": {
"TSFoster/elm-bytes-extra": "1.3.0",
"TSFoster/elm-md5": "2.0.0",
"TSFoster/elm-md5": "2.0.1",
"TSFoster/elm-sha1": "2.1.1",
"danfishgold/base64-bytes": "1.1.0",
"elm/bytes": "1.0.8",
"elm/file": "1.0.5",
"elm/regex": "1.0.0",
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.2",
"kuon/elm-string-normalize": "1.0.2",
"rtfeldman/elm-hex": "1.0.0",
"zwilias/elm-utf-tools": "2.0.1"
"rtfeldman/elm-hex": "1.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {
"elm/file": "1.0.5"
}
"indirect": {}
}
}
Loading

0 comments on commit cf4489b

Please sign in to comment.