Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #18317: Support source package in Rudder inventory #3251

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ final case class License(
)

final case class Software(
id:SoftwareUuid,
name :Option[String] = None,
description:Option[String] = None,
version : Option[Version] = None,
editor : Option[SoftwareEditor] = None,
releaseDate : Option[DateTime] = None,
license : Option[License] = None
id : SoftwareUuid
, name : Option[String] = None
, description : Option[String] = None
, version : Option[Version] = None
, editor : Option[SoftwareEditor] = None
, releaseDate : Option[DateTime] = None
, license : Option[License] = None
, sourceName : Option[String] = None
, sourceVersion : Option[Version] = None
)
Original file line number Diff line number Diff line change
Expand Up @@ -900,13 +900,17 @@ class FusionReportUnmarshaller(
}
}

def processSoftware(s : NodeSeq) : Software = Software(
id = SoftwareUuid(uuidGen.newUuid)
, name = optText(s\"NAME")
, version = optText(s\"VERSION").map(x => new Version(x) )
, description = optText(s\"COMMENTS")
, editor = optText(s\"PUBLISHER").map(e => new SoftwareEditor(e))
def processSoftware(s : NodeSeq) : Software = {
Software(
id = SoftwareUuid(uuidGen.newUuid)
, name = optText(s \ "NAME" )
, version = optText(s \ "VERSION" ).map(x => new Version(x))
, description = optText(s \ "COMMENTS" )
, editor = optText(s \ "PUBLISHER" ).map(e => new SoftwareEditor(e))
, sourceName = optText(s \ "SOURCE_NAME" )
, sourceVersion = optText(s \ "SOURCE_VERSION").map(x => new Version(x))
)
}

/**
* Process the bios, and return its, plus the system manufacturer and the system serial number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class NameAndVersionIdFinder(
} yield {
//now merge back
entities.foldLeft(MergedSoftware(Set(),Set())) { case(ms, s) =>
merged.find { x => x.name == s.name && x.version == s.version } match {
case None => ms.copy(newSoftware = ms.newSoftware+s)
merged.find { x => x.name == s.name && x.version == s.version && x.sourceName == s.sourceName && x.sourceVersion == s.sourceVersion } match {
case Some(x) => ms.copy(alreadySavedSoftware = ms.alreadySavedSoftware+x)
case None => ms.copy(newSoftware = ms.newSoftware+s)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,21 @@ attributetype ( InventoryAttributes:400.57
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )

attributetype ( InventoryAttributes:400.58
NAME 'sourceName'
DESC 'Name of the source package (used on debian like systems)'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )


attributetype ( InventoryAttributes:400.59
NAME 'sourceVersion'
DESC 'Version of the source package, used on debian like systems, for ex: v3.0.34-pre4'
EQUALITY caseIgnoreMatch
SUBSTR caseIgnoreSubstringsMatch
SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{256} )

#######################################################
################ Object Classes ######################
#######################################################
Expand Down Expand Up @@ -1078,7 +1093,7 @@ objectclass ( InventoryObjectClasses:21
STRUCTURAL
MUST ( softwareId )
MAY ( cn $ description $ releaseDate $ editor $ softwareVersion $
licenseExpirationDate $ licenseName $ licenseProductId $ licenseProductKey ) )
licenseExpirationDate $ licenseName $ licenseProductId $ licenseProductKey $ sourceName $ sourceVersion ) )
fanf marked this conversation as resolved.
Show resolved Hide resolved


objectclass ( InventoryObjectClasses:22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ class InventoryMapper(

def entryFromSoftware(soft:Software) : LDAPEntry = {
val e = acceptedDit.SOFTWARE.SOFT.model(soft.id)
e.setOpt(soft.name, A_NAME, {x:String => x})
e.setOpt(soft.description, A_DESCRIPTION, {x:String => x})
e.setOpt(soft.version, A_SOFT_VERSION, {x:Version => x.value})
e.setOpt(soft.editor, A_EDITOR, {x:SoftwareEditor => x.name})
e.setOpt(soft.releaseDate, A_RELEASE_DATE, {x:DateTime => GeneralizedTime(x).toString})
e.setOpt(soft.name, A_NAME, {x:String => x})
e.setOpt(soft.description, A_DESCRIPTION, {x:String => x})
e.setOpt(soft.version, A_SOFT_VERSION, {x:Version => x.value})
e.setOpt(soft.editor, A_EDITOR, {x:SoftwareEditor => x.name})
e.setOpt(soft.releaseDate, A_RELEASE_DATE, {x:DateTime => GeneralizedTime(x).toString})
e.setOpt(soft.sourceName, A_SOURCE_NAME, {x:String => x})
e.setOpt(soft.sourceVersion, A_SOURCE_VERSION, {x:Version => x.value})
soft.license.foreach { lic =>
e +=! (A_LICENSE_NAME,lic.name)
e.setOpt(lic.description, A_LICENSE_DESC, {x:String => x})
Expand All @@ -162,16 +164,20 @@ class InventoryMapper(
e.setOpt(lic.oem, A_LICENSE_OEM, {x:String => x})
}
e

}

def softwareFromEntry(e:LDAPEntry) : InventoryMappingPure[Software] = {
for {
id <- acceptedDit.SOFTWARE.SOFT.idFromDN(e.dn)
name = e(A_NAME)
desc = e(A_DESCRIPTION)
version = e(A_SOFT_VERSION).map(v => new Version(v))
releaseDate = e.getAsGTime(A_RELEASE_DATE) map { _.dateTime }
editor = e(A_EDITOR) map { x => new SoftwareEditor(x) }
name = e(A_NAME)
desc = e(A_DESCRIPTION)
version = e(A_SOFT_VERSION).map(v => new Version(v))
releaseDate = e.getAsGTime(A_RELEASE_DATE) map { _.dateTime }
editor = e(A_EDITOR) map { x => new SoftwareEditor(x) }
source_name = e(A_SOURCE_NAME)
source_version = e(A_SOURCE_VERSION).map(v => new Version(v))

//licence
lic = e(A_LICENSE_NAME) map { name =>
License(
Expand All @@ -184,7 +190,7 @@ class InventoryMapper(
)
}
} yield {
Software(id,name,desc,version,editor,releaseDate,lic)
Software(id,name,desc,version,editor,releaseDate,lic, source_name, source_version)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ object LDAPConstants {
val A_MEMORY_TYPE = "memoryType"
//software
val A_RELEASE_DATE = "releaseDate"
val A_SOURCE_NAME = "sourceName"
val A_SOURCE_VERSION = "sourceVersion"
val A_EDITOR = "editor"
val A_SOFT_VERSION = "softwareVersion"
val A_LICENSE_EXP = "licenseExpirationDate"
Expand Down Expand Up @@ -324,7 +326,7 @@ object LDAPConstants {
may = Set(A_SOFT_VERSION,A_EDITOR, A_RELEASE_DATE,
A_LICENSE_EXP,A_LICENSE_NAME,A_LICENSE_OEM,
A_LICENSE_DESC,A_LICENSE_PRODUCT_ID,
A_LICENSE_PRODUCT_KEY) )
A_LICENSE_PRODUCT_KEY, A_SOURCE_VERSION, A_SOURCE_NAME) )
OC +=(OC_CONTROLLER, OC(OC_PE),
must = Set(A_CONTROLLER_NAME)
)
Expand Down