Skip to content

Commit

Permalink
Fixes #24175: Prepare migration to Scala 3 - Version 8.1 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaechler authored and VinceMacBuche committed Feb 8, 2024
1 parent 0818f07 commit 6aeb3b2
Show file tree
Hide file tree
Showing 426 changed files with 3,971 additions and 3,508 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,40 @@ sealed trait AgentType {
object AgentType {

final case object CfeEnterprise extends AgentType {
override def id = "cfengine-nova"
override def oldShortName = "nova"
override def displayName = "CFEngine Enterprise"
override def toRulesPath = "/cfengine-nova"
override def inventoryAgentNames = Set("cfengine-nova", "nova")
override val inventorySoftwareName = "cfengine nova"
override def toAgentVersionName(softwareVersionName: String) = s"cfe-${softwareVersionName}"
override val defaultPolicyExtension = ".cf"
override def id = "cfengine-nova"
override def oldShortName = "nova"
override def displayName = "CFEngine Enterprise"
override def toRulesPath = "/cfengine-nova"
override def inventoryAgentNames: Set[String] = Set("cfengine-nova", "nova")
override val inventorySoftwareName = "cfengine nova"
override def toAgentVersionName(softwareVersionName: String): String = s"cfe-${softwareVersionName}"
override val defaultPolicyExtension = ".cf"
}

final case object CfeCommunity extends AgentType {
override def id = "cfengine-community"
override def oldShortName = "community"
override def displayName = "Rudder"
override def toRulesPath = "/cfengine-community"
override def inventoryAgentNames = Set("cfengine-community", "community")
override def id = "cfengine-community"
override def oldShortName = "community"
override def displayName = "Rudder"
override def toRulesPath = "/cfengine-community"
override def inventoryAgentNames: Set[String] = Set("cfengine-community", "community")
override val inventorySoftwareName = "rudder-agent"
override def toAgentVersionName(softwareVersionName: String) = softwareVersionName
override val defaultPolicyExtension = ".cf"
}

final case object Dsc extends AgentType {
override def id = "dsc"
override def oldShortName = "dsc"
override def displayName = "Rudder Windows"
override def toRulesPath = "/dsc"
override def inventoryAgentNames = Set("dsc")
override def id = "dsc"
override def oldShortName = "dsc"
override def displayName = "Rudder Windows"
override def toRulesPath = "/dsc"
override def inventoryAgentNames: Set[String] = Set("dsc")
override val inventorySoftwareName = "Rudder agent (DSC)"
override def toAgentVersionName(softwareVersionName: String) = softwareVersionName
override val defaultPolicyExtension =
"" // no extension - .ps1 extension is already in the template name (more by convention than anything else)
}

def allValues = ca.mrvisser.sealerate.values[AgentType]
def allValues: Set[AgentType] = ca.mrvisser.sealerate.values[AgentType]

def fromValue(value: String): Either[InventoryError.AgentType, AgentType] = {
// Check if the value is correct compared to the agent tag name (fusion > 2.3) or its toString value (added by CFEngine)
Expand Down Expand Up @@ -168,7 +168,7 @@ object AgentInfoSerialisation {

implicit class ToJson(val agent: AgentInfo) extends AnyVal {

def toJsonString = {
def toJsonString: String = {
compactRender(
("agentType" -> agent.agentType.id)
~ ("version" -> agent.version.map(_.value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sealed trait SecurityToken {
}

object SecurityToken {
def kind(token: SecurityToken) = {
def kind(token: SecurityToken): String = {
token match {
case _: PublicKey => PublicKey.kind
case _: Certificate => Certificate.kind
Expand Down Expand Up @@ -145,7 +145,7 @@ object Certificate {
final case class PublicKey(value: String) extends SecurityToken {

// Value of the key may be stored (with old fusion inventory version) as one line and without rsa header and footer, we should add them if missing and format the key
val key = {
val key: String = {
if (value.startsWith("-----BEGIN RSA PUBLIC KEY-----")) {
value
} else {
Expand All @@ -170,7 +170,7 @@ final case class PublicKey(value: String) extends SecurityToken {
final case class Certificate(value: String) extends SecurityToken {

// Value of the key may be stored (with old fusion inventory version) as one line and without rsa header and footer, we should add them if missing and format the key
val key = {
val key: String = {
if (value.startsWith("-----BEGIN CERTIFICATE-----")) {
value
} else {
Expand Down Expand Up @@ -207,7 +207,7 @@ final case class Certificate(value: String) extends SecurityToken {
* Comparison are really important in Version
*/
final class Version(val value: String) extends AnyVal {
override def toString() = "[%s]".format(value)
override def toString(): String = "[%s]".format(value)
}
object Version {
implicit val ord: Ordering[Version] = _.value compareTo _.value
Expand All @@ -228,7 +228,7 @@ object InventoryError {

final case class Crypto(msg: String) extends InventoryError
final case class CryptoEx(hint: String, ex: Throwable) extends InventoryError {
def msg = hint + "; root exception was: " + ex.getMessage()
def msg: String = hint + "; root exception was: " + ex.getMessage()
}
final case class AgentType(msg: String) extends InventoryError
final case class SecurityToken(msg: String) extends InventoryError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ package com.normation.inventory.domain
import com.normation.errors.Inconsistency
import com.normation.errors.IOResult
import java.security.MessageDigest
import scala.util.matching.Regex
import zio.syntax.ToZio

trait Uuid extends Any {
Expand All @@ -54,7 +55,7 @@ final case class MachineUuid(val value: String) extends AnyVal with Uuid
final case class SoftwareUuid(val value: String) extends AnyVal with Uuid

object SoftwareUuid {
val pattern = "softwareId=(.*),ou=Software,.*".r
val pattern: Regex = "softwareId=(.*),ou=Software,.*".r

def SoftwareUuidFromDnString(dnString: String): IOResult[SoftwareUuid] = {
dnString match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package com.normation.inventory.domain
sealed abstract class InventoryStatus(val name: String)

object InventoryStatus {
def apply(name: String) = name.toLowerCase match {
def apply(name: String): Option[InventoryStatus] = name.toLowerCase match {
case "accepted" => Some(AcceptedInventory)
case "pending" => Some(PendingInventory)
case "removed" => Some(RemovedInventory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
package com.normation.inventory.domain

import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormatter
import org.joda.time.format.ISODateTimeFormat
import zio.json._

Expand All @@ -63,8 +64,8 @@ object JsonSerializers {
object implicits extends InventoryJsonEncoders with InventoryJsonDecoders

// the update date is normalized in RFC3339, UTC, no millis
val softwareUpdateDateTimeFormat = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC()
def parseSoftwareUpdateDateTime(d: String) = {
val softwareUpdateDateTimeFormat: DateTimeFormatter = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC()
def parseSoftwareUpdateDateTime(d: String): Either[String, DateTime] = {
try {
Right(JsonSerializers.softwareUpdateDateTimeFormat.parseDateTime(d))
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ object VmType {
case object OpenVZ extends VmType("openvz")
case object LXC extends VmType("lxc")

def all = ca.mrvisser.sealerate.values[VmType]
def parse(s: String) = all.find(_.name == s.toLowerCase).getOrElse(UnknownVmType)
def all: Set[VmType] = ca.mrvisser.sealerate.values[VmType]
def parse(s: String): VmType = all.find(_.name == s.toLowerCase).getOrElse(UnknownVmType)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ package com.normation.inventory.domain
* 244 Mo, 23 kB, etc
*/
final case class MemorySize(size: Long) extends AnyVal {
override def toString() = "%s B".format(size)
override def toString(): String = "%s B".format(size)

def toStringMo = {
def toStringMo: String = {
val (value, unit) = MemorySize.prettyMo(this)
value + " " + unit
}
Expand Down Expand Up @@ -108,7 +108,7 @@ object MemorySize {
}
}

def apply(s: String) = {
def apply(s: String): MemorySize = {
new MemorySize(parse(s).getOrElse(-1))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ sealed abstract class WindowsType extends OsType {
override val kernelName = "Windows"
}
object WindowsType {
val allKnownTypes = (
val allKnownTypes: List[WindowsType] = (
WindowsXP
:: WindowsVista
:: WindowsSeven
Expand Down Expand Up @@ -185,7 +185,7 @@ sealed abstract class LinuxType extends OsType {
override val kernelName = "Linux"
}
object LinuxType {
val allKnownTypes = (
val allKnownTypes: List[LinuxType] = (
Debian
:: Ubuntu
:: Kali
Expand Down Expand Up @@ -244,7 +244,7 @@ sealed abstract class BsdType extends OsType {
}

object BsdType {
val allKnownTypes = (
val allKnownTypes: List[BsdType] = (
FreeBSD
:: UnknownBsdType
:: Nil
Expand Down Expand Up @@ -480,9 +480,9 @@ object SoftwareUpdateKind {
final case object Enhancement extends SoftwareUpdateKind { val name = "enhancement" }
final case class Other(value: String) extends SoftwareUpdateKind { val name = "other" }

def all = ca.mrvisser.sealerate.collect[SoftwareUpdateKind]
def all: Set[SoftwareUpdateKind] = ca.mrvisser.sealerate.collect[SoftwareUpdateKind]

def parse(value: String) = all.find(_.name == value.toLowerCase()).getOrElse(Other(value))
def parse(value: String): SoftwareUpdateKind = all.find(_.name == value.toLowerCase()).getOrElse(Other(value))
}
sealed trait SoftwareUpdateSeverity {
def name: String
Expand All @@ -495,9 +495,9 @@ object SoftwareUpdateSeverity {
case object Critical extends SoftwareUpdateSeverity { val name = "critical" }
case class Other(value: String) extends SoftwareUpdateSeverity { val name = "other" }

def all = ca.mrvisser.sealerate.collect[SoftwareUpdateSeverity]
def all: Set[SoftwareUpdateSeverity] = ca.mrvisser.sealerate.collect[SoftwareUpdateSeverity]

def parse(value: String) = all.find(_.name == value.toLowerCase()).getOrElse(Other(value))
def parse(value: String): SoftwareUpdateSeverity = all.find(_.name == value.toLowerCase()).getOrElse(Other(value))
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ trait PipelinedInventorySaver[R] extends InventorySaver[R] with Loggable {
val basePostPipeline: Seq[PostCommit[R]]
private[this] val postCommitPipeline: Ref[Seq[PostCommit[R]]] = Ref.make(basePostPipeline).runNow

def registerPostCommitHook(hook: PostCommit[R]) = postCommitPipeline.update(hook +: _)
def registerPostCommitHook(hook: PostCommit[R]): UIO[Unit] = postCommitPipeline.update(hook +: _)

/**
* Here comes the logic to actually save change in the Directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ class AgentTypesTest extends Specification {
val key =
"-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAtDTtbfw2ic1pcUludrs1I+HGGdRL0r5dKjMzLhUGahCrVaH7H3ND\n/py+XPZKY/Iolttgf1RriQAazEVbFEWXozistMTXtWJu/5IxV47QNqbS82KrhQNp\ns4abfqraGOlYbYS5BXCaHYrKI2VzvAwwvCsE7vmhnO1Br4AueagrFU+itjr/0gMd\nu58xYDiAADXqGDzES75NIxCZelv5vefMfpEMlBmztKmgY+iT+Q8lhf42WUsZ9OBl\nRDRfQ9VCW+8336C1JEpcHAcSElF4mn4D0GN7RvxNOSGpuLjxAvp5qFVbp4Xtd+4q\n8DaGe+w8MplwMVCFTyEMS3E1pS4DdctdLwIDAQAB\n-----END RSA PUBLIC KEY-----"

val json43 = s"""
val json43: String = s"""
{
"agentType":"cfengine-community"
,"version" :"4.3.2"
,"securityToken": { "value":"$key","type":"publicKey"}
}"""

val json41 = s"""
val json41: String = s"""
{
"agentType":"Community"
,"version" :"4.1.13"
}"""

val json61 = s"""
val json61: String = s"""
{
"agentType":"cfengine-community"
,"version" :"6.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ class FusionInventoryParser(

import OptText.optText

val userLoginDateTimeFormat = DateTimeFormat.forPattern(lastLoggedUserDatetimeFormat).withLocale(Locale.ENGLISH)
val biosDateTimeFormat = DateTimeFormat.forPattern(biosDateFormat).withLocale(Locale.ENGLISH)
val userLoginDateTimeFormat: DateTimeFormatter =
DateTimeFormat.forPattern(lastLoggedUserDatetimeFormat).withLocale(Locale.ENGLISH)
val biosDateTimeFormat: DateTimeFormatter = DateTimeFormat.forPattern(biosDateFormat).withLocale(Locale.ENGLISH)

// extremely specialized convert used for optional field only, that
// log the error in place of using a box
Expand Down Expand Up @@ -103,7 +104,7 @@ class FusionInventoryParser(
text
}

def parseDate(n: NodeSeq, fmt: DateTimeFormatter) = {
def parseDate(n: NodeSeq, fmt: DateTimeFormatter): Option[DateTime] = {
val date = optText(n).getOrElse("Unknown")
try {
Some(DateTime.parse(date, fmt))
Expand Down Expand Up @@ -1368,7 +1369,7 @@ object OptText {
* - remove leading/trailing spaces ;
* - remove multiple space
*/
def optText(n: NodeSeq) = n.text match {
def optText(n: NodeSeq): Option[String] = n.text match {
case null | "" => None
case s =>
s.trim().replaceAll("""[\p{Blank}]+""", " ") match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.normation.inventory.domain.InventoryError
import com.normation.inventory.services.provisioning._
import com.normation.utils.NodeIdRegex
import scala.xml.Elem
import scala.xml.Node
import scala.xml.NodeSeq
import zio._
import zio.syntax._
Expand All @@ -52,7 +53,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {
override val name = "post_process_inventory:check_consistency"

implicit class ToInconsistency(msg: String) {
def inconsistency = InventoryError.Inconsistency(msg).fail
def inconsistency: IO[InventoryError.Inconsistency, Nothing] = InventoryError.Inconsistency(msg).fail
}

/**
Expand Down Expand Up @@ -236,7 +237,7 @@ class PreInventoryParserCheckConsistency extends PreInventoryParser {

// for check kernel version
private[this] class AddChildrenTo(label: String, newChild: scala.xml.Node) extends scala.xml.transform.RewriteRule {
override def transform(n: scala.xml.Node) = n match {
override def transform(n: scala.xml.Node): scala.collection.Seq[Node] = n match {
case Elem(prefix, "OPERATINGSYSTEM", attribs, scope, child @ _*) =>
Elem(prefix, label, attribs, scope, false, child ++ newChild: _*)
case other => other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import java.util.regex.Pattern

class PrintedKeyNormalizer {

val start = Pattern.compile("""-----begin[ a-z]*-----""", Pattern.CASE_INSENSITIVE)
val end = Pattern.compile("""-----end[ a-z]*-----""", Pattern.CASE_INSENSITIVE)
def apply(s: String) = {
val start: Pattern = Pattern.compile("""-----begin[ a-z]*-----""", Pattern.CASE_INSENSITIVE)
val end: Pattern = Pattern.compile("""-----end[ a-z]*-----""", Pattern.CASE_INSENSITIVE)
def apply(s: String): String = {
var res = s
res = start.matcher(s).replaceAll("")
res = end.matcher(res).replaceAll("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class TestInventoryParsing extends Specification with Loggable {
}
}

val parser = new FusionInventoryParser(new StringUuidGeneratorImpl)
def parseRun(inventory: String) = ZioRuntime.unsafeRun(parser.parse(inventory))
def parseRunEither(inventory: String) = ZioRuntime.unsafeRun(parser.parse(inventory).either)
val parser = new FusionInventoryParser(new StringUuidGeneratorImpl)
def parseRun(inventory: String): Inventory = ZioRuntime.unsafeRun(parser.parse(inventory))
def parseRunEither(inventory: String): Either[RudderError, Inventory] = ZioRuntime.unsafeRun(parser.parse(inventory).either)

// we are testing some error etc, so make the standard output cleaner:
org.slf4j.LoggerFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class TestSignatureService extends Specification with Loggable {
ZIO.acquireReleaseWith(getInputStream(path))(is => effectUioUnit(is.close))(TestInventoryDigestServiceV1.parse)
}

val boxedSignature = parseSignature("fusion-inventories/signed_inventory.ocs.sign")
val boxedSignature: IOResult[InventoryDigest] = parseSignature("fusion-inventories/signed_inventory.ocs.sign")

"Signature file" should {
"contain use sha512 algorithm" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ import com.normation.inventory.ldap.core.LDAPConstants._
import com.normation.inventory.services.provisioning._
import com.normation.ldap.sdk._
import com.normation.ldap.sdk.BuildFilter._
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import zio._

object NameAndVersionIdFinder {
val logger = LoggerFactory.getLogger(classOf[NameAndVersionIdFinder])
val logger: Logger = LoggerFactory.getLogger(classOf[NameAndVersionIdFinder])
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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.toLDIFString()}"
def msg: String = 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 @@ -478,7 +478,7 @@ class InventoryMapper(
}
}

def machineTypeFromObjectClasses(objectClassNames: Set[String]) = {
def machineTypeFromObjectClasses(objectClassNames: Set[String]): Option[MachineType] = {
def objectClass2MachineType(oc: LDAPObjectClass): Option[MachineType] = {
oc match {
case LDAPObjectClass(OC_VM, _, _, _) => Some(VirtualMachineType(UnknownVmType))
Expand Down
Loading

0 comments on commit 6aeb3b2

Please sign in to comment.