Skip to content

Commit

Permalink
Fixes #18302: Make possible to give a revision for directives in rule…
Browse files Browse the repository at this point in the history
… and get correct technique files
  • Loading branch information
fanf committed Jul 23, 2021
1 parent 59024c3 commit 873354b
Show file tree
Hide file tree
Showing 252 changed files with 12,858 additions and 4,732 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class FusionReportUnmarshaller(
case None => // can update the manufacturer
report = report.copy(machine = report.machine.copy(manufacturer = Some(x)))
case Some(existingManufacturer) => //cannot update it
InventoryProcessingLogger.logEffect.warn(s"Duplicate Machine Manufacturer definition in the inventory: s{existingManufacturer} is the current value, skipping the other value ${x}")
InventoryProcessingLogger.logEffect.warn(s"Duplicate Machine Manufacturer definition in the inventory: s{existingManufacturer} is the current value, skipping the other value ${x.name}")
}
}
systemSerialNumber.foreach{ x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class UseExistingMachineIdFinder(
con <- ldap
entry <- con.searchSub(rootDN, AND(IS(OC_MACHINE),EQ(A_MACHINE_UUID, entity.id.value)), "1.1").map(_.headOption).notOptional(s"No machine entry found for id '${entity.id.value}'") //TODO: error if more than one !! #555
dit <- inventoryDitService.getDit(entry.dn) match {
case None => s"No DIT found for machine DN ${entry.dn}".fail
case None => s"No DIT found for machine DN ${entry.dn.toString}".fail
case Some(x) => x.succeed
}
} yield {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ attributetype ( InventoryAttributes:1.5
DESC 'Unique identifier for the policy server of a node'
SUP uuid )

# Revision identifier is not used in these objects, but they will be at
# some point, so definition is here
attributetype ( InventoryAttributes:1.6
NAME 'revision'
DESC '(git) revision identifier of the object'
SUP uuid )

#######################################################################

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class FullInventoryRepositoryImpl(

// Get into Nodes subtree
nodeTree <- tree.flatMap(_.children.get(dit.NODES.rdn)) match {
case None => LDAPRudderError.Consistancy(s"Could not find node inventories in ${dit.BASE_DN}").fail
case None => LDAPRudderError.Consistancy(s"Could not find node inventories in ${dit.BASE_DN.toString}").fail
case Some(tree) => tree.succeed
}
// we don't want that one error somewhere breaks everything
Expand All @@ -301,7 +301,7 @@ class FullInventoryRepositoryImpl(

// Get into Machines subtree
machineTree <- tree.flatMap(_.children.get(dit.MACHINES.rdn)) match {
case None => LDAPRudderError.Consistancy(s"Could not find machine inventories in ${dit.BASE_DN}").fail
case None => LDAPRudderError.Consistancy(s"Could not find machine inventories in ${dit.BASE_DN.toString}").fail
case Some(tree) => tree.succeed
}
machines <- ZIO.foreach(machineTree.children.values){ tree =>
Expand Down Expand Up @@ -403,7 +403,7 @@ class FullInventoryRepositoryImpl(
res
}).foldM(
e => {
InventoryProcessingLogger.warn(s"Error when trying to delete machine for server with id '${id.value}' and inventory status '${inventoryStatus}'. Message was: ${e.msg}") *>
InventoryProcessingLogger.warn(s"Error when trying to delete machine for server with id '${id.value}' and inventory status '${inventoryStatus.name}'. Message was: ${e.msg}") *>
Seq().succeed
}, _.succeed
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ final case class InventoryDit(val BASE_DN:DN, val SOFTWARE_BASE_DN:DN, val name:
} else {
Left(MalformedDN("Unexpected RDN for a software ID"))
}
} else Left(MalformedDN(s"DN ${dn} does not belong to software inventories DN ${software.dn}"))
} else Left(MalformedDN(s"DN ${dn.toString} does not belong to software inventories DN ${software.dn.toString}"))
}
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ final case class InventoryDit(val BASE_DN:DN, val SOFTWARE_BASE_DN:DN, val name:
} else {
Left(InventoryMappingRudderError.MalformedDN("Unexpected RDN for a node ID"))
}
} else Left(InventoryMappingRudderError.MalformedDN(s"DN '${dn}' does not belong to server inventories DN '${servers.dn}'"))
} else Left(InventoryMappingRudderError.MalformedDN(s"DN '${dn.toString}' does not belong to server inventories DN '${servers.dn.toString}'"))
}
}

Expand All @@ -220,7 +220,7 @@ final case class InventoryDit(val BASE_DN:DN, val SOFTWARE_BASE_DN:DN, val name:
} else {
Left(InventoryMappingRudderError.MalformedDN("Unexpected RDN for a machine ID"))
}
} else Left(InventoryMappingRudderError.MalformedDN(s"DN '${dn}' does not belong to machine inventories DN '${machines.dn}'"))
} else Left(InventoryMappingRudderError.MalformedDN(s"DN '${dn.toString}' does not belong to machine inventories DN '${machines.dn.toString}'"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import zio.syntax._
sealed trait InventoryMappingRudderError extends RudderError
object InventoryMappingRudderError {
final case class MissingMandatoryAttribute(attribute: String, entry: LDAPEntry) extends InventoryMappingRudderError {
def msg = s"Missing required attribute '${attribute}' in entry: ${entry}"
def msg = s"Missing required attribute '${attribute}' in entry: ${entry.toLDIFString()}"
}
final case class MalformedDN(msg: String) extends InventoryMappingRudderError
final case class MissingMandatory(msg: String) extends InventoryMappingRudderError
Expand Down Expand Up @@ -932,7 +932,7 @@ class InventoryMapper(
def nodeFromEntry(entry:LDAPEntry) : IOResult[NodeInventory] = {

for {
dit <- ditService.getDit(entry.dn).notOptional(s"DIT not found for entry ${entry.dn}")
dit <- ditService.getDit(entry.dn).notOptional(s"DIT not found for entry ${entry.dn.toString}")
inventoryStatus = ditService.getInventoryStatus(dit)
id <- dit.NODES.NODE.idFromDN(entry.dn).toIO
keyStatus <- ZIO.fromEither(entry(A_KEY_STATUS).map(KeyStatus(_)).getOrElse(Right(UndefinedKey)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ object LDAPConstants {
val A_PKEYS = "publicKey"
val A_AGENTS_NAME = "agentName"
val A_DESCRIPTION = "description"
val A_REV_ID = "revision"
val A_MODEL = "model"
val A_FIRMWARE = "firmware"
val A_SERIAL_NUMBER = "componentSerialNumber"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ReadOnlySoftwareDAOImpl(
for {
entries <- con.searchOne(inventoryDitService.getSoftwareBaseDN, OR(ids map {x:SoftwareUuid => EQ(A_SOFTWARE_UUID,x.value) }:_*)).map(_.toVector)
soft <- ZIO.foreach(entries) { entry =>
ZIO.fromEither(mapper.softwareFromEntry(entry)).chainError(s"Error when mapping LDAP entry '${entry.dn}' to a software. Entry details: ${entry}")
ZIO.fromEither(mapper.softwareFromEntry(entry)).chainError(s"Error when mapping LDAP entry '${entry.dn.toString}' to a software. Entry details: ${entry.toLDIFString()}")
}
} yield {
soft
Expand Down Expand Up @@ -124,7 +124,7 @@ class ReadOnlySoftwareDAOImpl(
ids <- ZIO.foreach(softwareEntry) { entry =>
entry(A_SOFTWARE_UUID) match {
case Some(value) => value.succeed
case _ => Inconsistency(s"Missing attribute ${A_SOFTWARE_UUID} for entry ${entry.dn} ${entry.toString()}").fail
case _ => Inconsistency(s"Missing attribute ${A_SOFTWARE_UUID} for entry ${entry.dn.toString} ${entry.toString()}").fail
}
}
softIds = ids.map(id => SoftwareUuid(id)).toSet
Expand Down
11 changes: 9 additions & 2 deletions webapp/sources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ limitations under the License.
<artifactId>silencer-plugin_${scala-version}</artifactId>
<version>${silencer-lib-version}</version>
</compilerPlugin>
</compilerPlugins>
<compilerPlugin>
<groupId>org.wartremover</groupId>
<artifactId>wartremover_2.13</artifactId>
<version>2.4.10</version>
</compilerPlugin>
</compilerPlugins>
<args>
<!-- require java8, cf http://www.rudder-project.org/redmine/issues/9917 -->
<arg>-target:jvm-1.8</arg>
Expand Down Expand Up @@ -187,6 +192,8 @@ limitations under the License.
<arg>-Ycache-plugin-class-loader:last-modified</arg> <!-- Enables caching of classloaders for compiler plugins -->
<arg>-Ycache-macro-class-loader:last-modified</arg> <!-- and macro definitions. This can lead to performance improvements. -->
<arg>-P:silencer:checkUnused</arg>
<!-- <arg>-P:wartremover:only-warn-traverser:org.wartremover.warts.StringPlusAny</arg>-->
<!-- <arg>-P:wartremover:only-warn-traverser:org.wartremover.warts.ToString</arg>-->
</args>
<jvmArgs>
<jvmArg>-Xmx${jvmArg-Xmx}</jvmArg>
Expand Down Expand Up @@ -373,7 +380,7 @@ limitations under the License.
<commons-fileupload>1.4</commons-fileupload>
<spring-version>5.2.15.RELEASE</spring-version>
<spring-security-version>5.3.10.RELEASE</spring-security-version>
<jgit-version>5.9.0.202009080501-r</jgit-version>
<jgit-version>5.12.0.202106070339-r</jgit-version>
<cglib-version>3.3.0</cglib-version>
<asm-version>5.2</asm-version>
<bcpkix-jdk15on-version>1.68</bcpkix-jdk15on-version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ objectclass ( RudderObjectClasses:11
STRUCTURAL
MUST ( nodeGroupId $
cn $ isDynamic )
MAY ( nodeId $ description $ jsonNodeGroupQuery $
MAY ( nodeId $ description $ jsonNodeGroupQuery $ revision $
isEnabled $ isSystem $ serializedProperty ) )

objectclass ( RudderObjectClasses:12
Expand Down Expand Up @@ -486,7 +486,7 @@ objectclass ( RudderObjectClasses:23
SUP top
STRUCTURAL
MUST ( directiveId $ techniqueVersion )
MAY ( cn $ description $ longDescription $ isEnabled $ isSystem $
MAY ( cn $ description $ longDescription $ isEnabled $ isSystem $ revision $
directivePriority $ directiveVariable $ policyMode $ serializedTags) )

### rules ###
Expand All @@ -498,7 +498,7 @@ objectclass ( RudderObjectClasses:30
STRUCTURAL
MUST ( ruleId )
MAY ( cn $ description $ longDescription $
isEnabled $ isSystem $
isEnabled $ isSystem $ revision $
ruleTarget $ serial $
directiveId $ tag $ serializedTags ) )

Expand Down Expand Up @@ -548,7 +548,7 @@ objectclass ( RudderObjectClasses:120
STRUCTURAL
MUST ( parameterName )
MAY ( parameterValue $ description $ propertyProvider $
overridable $ inheritMode ) )
overridable $ inheritMode $ revision ) )

#
# Application properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import com.normation.inventory.domain.AgentType
*
*/
final case class TechniqueName(value: String) extends AnyVal with Ordered[TechniqueName] {
override def toString = value

override def compare(that: TechniqueName) = this.value.compare(that.value)
}

Expand All @@ -59,7 +57,11 @@ final case class TechniqueName(value: String) extends AnyVal with Ordered[Techni
* among all policies, and a version for that policy.
*/
final case class TechniqueId(name: TechniqueName, version: TechniqueVersion) extends Ordered[TechniqueId] {
override def toString() = name.toString + "/" + version.toString
// intented for debug/log, not serialization
def debugString = serialize
// a technique
def serialize = name.value + "/" + version.serialize
def withDefaultRev = TechniqueId(name, version.withDefaultRev)

override def compare(that: TechniqueId): Int = {
val c = this.name.compare(that.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

package com.normation.cfclerk.domain

import com.normation.GitVersion.Revision


/**
* Representation of a technique resource id.
Expand All @@ -62,7 +64,7 @@ sealed trait TechniqueResourceId {
* The name must not contain the extension.
*/
final case class TechniqueResourceIdByName(techniqueId: TechniqueId, name: String) extends TechniqueResourceId {
def displayPath: String = techniqueId.toString() + "/" + name
def displayPath: String = techniqueId.serialize + "/" + name
}

/**
Expand All @@ -72,7 +74,7 @@ final case class TechniqueResourceIdByName(techniqueId: TechniqueId, name: Strin
* For example, an empty list means that the template is in configuration-repository directory.
* Name is an unix compliant file name, without the ".st" extension.
*/
final case class TechniqueResourceIdByPath(parentDirectories: List[String], name: String) extends TechniqueResourceId {
final case class TechniqueResourceIdByPath(parentDirectories: List[String], rev: Revision, name: String) extends TechniqueResourceId {
def displayPath: String = parentDirectories.mkString("", "/", "/") + name
}

Expand Down
Loading

0 comments on commit 873354b

Please sign in to comment.