Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceMacBuche committed Aug 23, 2016
1 parent 11a3a35 commit 46580ed
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import com.unboundid.ldap.sdk.Filter
import net.liftweb.common.Box
import net.liftweb.common.Full


/**
* This file contains the differents possible implementation of
* quick search backends.
Expand All @@ -68,8 +67,6 @@ import net.liftweb.common.Full
* of everything else.
*/



object QSDirectiveBackend {
import com.normation.rudder.repository.FullActiveTechnique
import com.normation.rudder.domain.policies.Directive
Expand All @@ -83,7 +80,6 @@ object QSDirectiveBackend {
* the expected query
*/


/**
* Lookup directives
*/
Expand Down Expand Up @@ -122,7 +118,6 @@ object QSDirectiveBackend {
case TechniqueName => Some(Set(at.techniqueName.toString))
case TechniqueVersion => Some(Set(dir.techniqueVersion.toString))
case Description => Some(Set(dir.shortDescription, dir.longDescription))
case ShortDescription => Some(Set(dir.shortDescription))
case LongDescription => Some(Set(dir.longDescription))
case Name => Some(Set(dir.name))
case IsEnabled => None
Expand Down Expand Up @@ -162,7 +157,6 @@ object QSDirectiveBackend {

}


/**
* The whole LDAP backend logic: look for Nodes, NodeGroups, Parameters, Rules,
* but not Directives.
Expand Down Expand Up @@ -207,16 +201,13 @@ object QSLdapBackend {
}
}



/**
* Mapping between attribute and their ldap name
*/
private[this] val attributeNameMapping: Map[QSAttribute, String] = {
val m: Map[QSAttribute, String] = Map(
Name -> A_NAME
, Description -> A_DESCRIPTION
, ShortDescription -> A_DESCRIPTION
, LongDescription -> A_LONG_DESCRIPTION
, IsEnabled -> A_IS_ENABLED
, NodeId -> A_NODE_UUID
Expand Down Expand Up @@ -270,7 +261,6 @@ object QSLdapBackend {
a match {
case Name => sub
case Description => sub
case ShortDescription => sub
case LongDescription => sub
case IsEnabled => sub
case NodeId => sub
Expand Down Expand Up @@ -309,6 +299,7 @@ object QSLdapBackend {
final implicit class QSObjectLDAPFilter(obj: QSObject)(implicit inventoryDit: InventoryDit, nodeDit: NodeDit, rudderDit: RudderDit) {

def filter() = obj match {
case Common => Nil
case Node => ( AND(IS(OC_NODE) , Filter.create(s"entryDN:dnOneLevelMatch:=${ inventoryDit.NODES.dn.toString }"))
:: AND(IS(OC_RUDDER_NODE) , Filter.create(s"entryDN:dnOneLevelMatch:=${ nodeDit. NODES.dn.toString }")) :: Nil )
case Group => AND(IS(OC_RUDDER_NODE_GROUP), Filter.create(s"entryDN:dnSubtreeMatch:=${ rudderDit. GROUP.dn.toString }")) :: Nil
Expand All @@ -318,8 +309,6 @@ object QSLdapBackend {
}
}



/**
* correctly transform entry to a result, putting what is needed in type and description
*/
Expand Down Expand Up @@ -359,7 +348,3 @@ object QSLdapBackend {
}
}
}




Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ package com.normation.rudder.services.quicksearch

import ca.mrvisser.sealerate


/**
* This file contains domains objects for the quick search service.
*/
Expand Down Expand Up @@ -74,60 +73,62 @@ object QSBackend {
* This does not hold for directive, because we don't have a real variable
* parameter
*/
sealed trait QSAttribute { def name: String }
sealed trait QSAttribute {
def name : String
def display : String = name
}
object QSAttribute {

//common
final case object Name extends QSAttribute { override val name = "displayName" }
final case object Name extends QSAttribute { override val name = "name" }
final case object Description extends QSAttribute { override val name = "description" }
final case object ShortDescription extends QSAttribute { override val name = "shortDescription" }
final case object LongDescription extends QSAttribute { override val name = "longDescription" }
final case object IsEnabled extends QSAttribute { override val name = "isEnabled" }
final case object LongDescription extends QSAttribute { override val name = "long_description" }// Long description}
final case object IsEnabled extends QSAttribute { override val name = "enabled" }

//Nodes
final case object NodeId extends QSAttribute { override val name = "id" }
final case object Fqdn extends QSAttribute { override val name = "hostname" }
final case object OsType extends QSAttribute { override val name = "os.type" }
final case object OsName extends QSAttribute { override val name = "os.name" }
final case object OsVersion extends QSAttribute { override val name = "os.version" }
final case object OsFullName extends QSAttribute { override val name = "os.fullName" }
final case object OsKernelVersion extends QSAttribute { override val name = "os.kernelVersion" }
final case object OsServicePack extends QSAttribute { override val name = "os.servicePack" }
final case object Arch extends QSAttribute { override val name = "architectureDescription" }
final case object Ram extends QSAttribute { override val name = "ram" }
final case object IpAddresses extends QSAttribute { override val name = "ipAddresses" }
final case object NodeId extends QSAttribute { override val name = "id" }// ID}
final case object Fqdn extends QSAttribute { override val name = "hostname" }
final case object OsType extends QSAttribute { override val name = "os_type" }
final case object OsName extends QSAttribute { override val name = "os_name" }
final case object OsVersion extends QSAttribute { override val name = "os_version" }
final case object OsFullName extends QSAttribute { override val name = "os" }
final case object OsKernelVersion extends QSAttribute { override val name = "os_kernelVersion" }
final case object OsServicePack extends QSAttribute { override val name = "os_servicePack" }
final case object Arch extends QSAttribute { override val name = "architecture" }
final case object Ram extends QSAttribute { override val name = "ram" } // RAM }
final case object IpAddresses extends QSAttribute { override val name = "ips" }
// Mac address
final case object PolicyServerId extends QSAttribute { override val name = "policyServerId" }

final case object Properties extends QSAttribute { override val name = "properties" }
final case object RudderRoles extends QSAttribute { override val name = "rudderRoles" }
final case object RudderRoles extends QSAttribute { override val name = "rudder_roles" }
// MachineType e

//Groups
final case object GroupId extends QSAttribute { override val name = "id" }
final case object IsDynamic extends QSAttribute { override val name = "isDynamic" }
final case object IsDynamic extends QSAttribute { override val name = "dynamic" }

//Directives
final case object DirectiveId extends QSAttribute { override val name = "id" }
final case object DirectiveVarName extends QSAttribute { override val name = "var.name" }
final case object DirectiveVarValue extends QSAttribute { override val name = "var.value" }
final case object TechniqueName extends QSAttribute { override val name = "techniqueName" }
final case object TechniqueVersion extends QSAttribute { override val name = "techniqueVersion" }
final case object DirectiveVarName extends QSAttribute { override val name = "dir_param_name" }
final case object DirectiveVarValue extends QSAttribute { override val name = "dir_param_value" }
final case object TechniqueName extends QSAttribute { override val name = "technique_name" }
final case object TechniqueVersion extends QSAttribute { override val name = "technique_version" }

//Parameters
final case object ParameterName extends QSAttribute { override val name = "id" }
final case object ParameterValue extends QSAttribute { override val name = "value" }
final case object ParameterName extends QSAttribute { override val name = "param_name" }
final case object ParameterValue extends QSAttribute { override val name = "param_value" }

//Rules
final case object RuleId extends QSAttribute { override val name = "id" }
final case object DirectiveIds extends QSAttribute { override val name = "directiveIds" }
final case object Targets extends QSAttribute { override val name = "targets" }

final case object DirectiveIds extends QSAttribute { override val name = "directives" }
final case object Targets extends QSAttribute { override val name = "groups" }

////// all attributes /////
final val all: Set[QSAttribute] = sealerate.values[QSAttribute]

}



/*
* Objects on which we are able to perform
* quicksearch
Expand All @@ -136,37 +137,40 @@ sealed trait QSObject { def name: String; def attributes: Set[QSAttribute] }

object QSObject {
import QSAttribute._
private[this] val commons: Set[QSAttribute] = Set(Name, Description, ShortDescription, LongDescription, IsEnabled)

final case object Common extends QSObject { override val name = "common"
override val attributes : Set[QSAttribute] = Set(Name, Description, LongDescription, IsEnabled)
}

final case object Node extends QSObject { override val name = "node"
override val attributes = commons ++ Set(NodeId, Fqdn, OsType, OsName
override val attributes : Set[QSAttribute] = Set(NodeId, Fqdn, OsType, OsName
, OsVersion, OsFullName, OsKernelVersion, OsServicePack, Arch, Ram
, IpAddresses, PolicyServerId, Properties, RudderRoles)
}
final case object Group extends QSObject { override val name = "group"
override val attributes = commons ++ Set(GroupId, IsDynamic)
override val attributes : Set[QSAttribute] = Set(GroupId, IsDynamic)
}
final case object Directive extends QSObject { override val name = "directive"
override val attributes = commons ++ Set(DirectiveId, DirectiveVarName
override val attributes : Set[QSAttribute] = Set(DirectiveId, DirectiveVarName
, DirectiveVarValue, TechniqueName, TechniqueVersion)
}
final case object Parameter extends QSObject { override val name = "parameter"
override val attributes = commons ++ Set(ParameterName, ParameterValue)
override val attributes : Set[QSAttribute] = Set(ParameterName, ParameterValue)
}
final case object Rule extends QSObject { override val name = "rule"
override val attributes = commons ++ Set(RuleId, DirectiveIds, Targets)
override val attributes : Set[QSAttribute] = Set(RuleId, DirectiveIds, Targets)
}

final val all: Set[QSObject] = sealerate.values[QSObject]


// default sort for QuickSearchResult:
// - by type
// - then by name
def sortQSObject(a: QSObject, b:QSObject): Boolean = {

implicit class QSObjectOrder(o: QSObject) {
def order() = o match {
case Common => 0
case Node => 1
case Group => 2
case Directive => 3
Expand Down Expand Up @@ -198,36 +202,35 @@ final object QSMapping {
//set of names by attribute
val attributeNames = {
import QSAttribute._
val descriptions = Set(Description, LongDescription, ShortDescription).map( _.name ) ++ Set("descriptions")
val descriptions = Set(Description, LongDescription).map( _.name ) ++ Set("descriptions")

QSAttribute.all.map { a => a match {
case Name => (a, Set(Name.name, "name") )
case Description => (a, descriptions)
case ShortDescription => (a, descriptions)
case LongDescription => (a, descriptions)
case IsEnabled => (a, Set(IsEnabled.name, "enabled") )
case IsEnabled => (a, Set(IsEnabled.name ))
case NodeId => (a, Set(NodeId.name, "nodeid") )
case Fqdn => (a, Set(Fqdn.name, "fqdn") )
case OsType => (a, Set(OsType.name, "ostype", "os"))
case OsName => (a, Set(OsName.name, "osname", "os") ) //not also full name because osFullname contains osName, not the reverse
case OsVersion => (a, Set(OsVersion.name, "osversion", "os") )
case OsFullName => (a, Set(OsFullName.name, "osfullname", OsName.name, "osname", "os") )
case OsKernelVersion => (a, Set(OsKernelVersion.name, "oskernelversion", "oskernel", "kernel", "version", "os") )
case OsKernelVersion => (a, Set(OsKernelVersion.name, "oskernelversion", "oskernel", "kernel", "os") )
case OsServicePack => (a, Set(OsServicePack.name, "osservicepack", "ossp", "sp", "servicepack", "os") )
case Arch => (a, Set(Arch.name, "architecture", "arch") )
case Arch => (a, Set(Arch.name, "arch") )
case Ram => (a, Set(Ram.name, "memory") )
case IpAddresses => (a, Set(IpAddresses.name, "ip", "ips", "networkips") )
case PolicyServerId => (a, Set(PolicyServerId.name, "policyserver") )
case Properties => (a, Set(Properties.name, "node.props", "nodeprops", "node.properties", "nodeproperties") )
case Properties => (a, Set(Properties.name, "node.props", "nodeprops", "node_properties", "nodeproperties") )
case RudderRoles => (a, Set(RudderRoles.name, "serverrole", "serverroles", "role", "roles") )
case GroupId => (a, Set(GroupId.name, "groupid") )
case IsDynamic => (a, Set(IsDynamic.name, "isdynamic") )
case IsDynamic => (a, Set(IsDynamic.name) )
case DirectiveId => (a, Set(DirectiveId.name, "directiveid") )
case DirectiveVarName => (a, Set(DirectiveVarName.name, "directivevar", "parameter", "parameters", "variable", "variables") )
case DirectiveVarValue => (a, Set(DirectiveVarValue.name,"directivevalue", "parameter", "parameters", "variable", "variables") )
case DirectiveVarName => (a, Set(DirectiveVarName.name , "dir_param", "dir_parameter", "dir_parameters", "param", "parameter", "parameters") )
case DirectiveVarValue => (a, Set(DirectiveVarValue.name, "dir_param", "dir_parameter", "dir_parameters", "param", "parameter", "parameters", "dir_value") )
case TechniqueName => (a, Set(TechniqueName.name, "technique", "techniqueid") )
case TechniqueVersion => (a, Set(TechniqueVersion.name, "technique", "techniqueid", "version") )
case ParameterName => (a, Set(ParameterName.name, "parametername", "paramname", "name", "parameter", "param") )
case ParameterName => (a, Set(ParameterName.name, "parametername", "paramname", "name", "parameter", "param", "id") )
case ParameterValue => (a, Set(ParameterValue.name, "parametervalue", "paramvalue", "value", "parameter", "param") )
case RuleId => (a, Set(RuleId.name, "ruleid") )
case DirectiveIds => (a, Set(DirectiveIds.name, "directiveids", "id", "ids") )
Expand Down Expand Up @@ -265,12 +268,9 @@ object QuickSearchResultId {
final case class QRRuleId (value: String) extends QuickSearchResultId { override final val tpe = Rule }
}


final case class QuickSearchResult(
id : QuickSearchResultId // the uuid used to build url
, name : String // the user facing name
, attribute: Option[QSAttribute] // the part that matches the search
, value : String // the value that matches the search
)


Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

package com.normation.rudder.services.quicksearch


import org.junit.runner._
import org.specs2.mutable._
import org.specs2.runner._
Expand All @@ -48,7 +47,6 @@ import org.specs2.matcher.MatchResult
@RunWith(classOf[JUnitRunner])
class QSRegexQueryParserTest extends Specification {


import QSRegexQueryParser.parse
import com.normation.rudder.services.quicksearch.QSObject._
import com.normation.rudder.services.quicksearch.QSAttribute._
Expand Down Expand Up @@ -101,7 +99,6 @@ class QSRegexQueryParserTest extends Specification {
}
}


"Queries with filter" should {
"if only on object, give all attributes" in {
parse(" Is:Directives is:RuLes here, the query").mustFull(
Expand All @@ -122,7 +119,7 @@ class QSRegexQueryParserTest extends Specification {
}
"only at end works" in {
parse(" here, the query is:node in:descriptions").mustFull(
Query("here, the query", Set(Node), Set(Description, LongDescription, ShortDescription))
Query("here, the query", Set(Node), Set(Description, LongDescription))
)
}
"only at starts works" in {
Expand All @@ -137,5 +134,4 @@ class QSRegexQueryParserTest extends Specification {
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class LDAPBasedConfigService(configFile: Config, repos: ConfigRepository, workfl
display.changes.graph=true
api.compatibility.mode=false
rudder.featureSwitch.directiveScriptEngine=disabled
rudder.featureSwitch.quicksearchEverything=enabled
"""

val configWithFallback = configFile.withFallback(ConfigFactory.parseString(defaultConfig))
Expand Down Expand Up @@ -488,12 +489,10 @@ class LDAPBasedConfigService(configFile: Config, repos: ConfigRepository, workfl
def api_compatibility_mode(): Box[Boolean] = get("api_compatibility_mode")
def set_api_compatibility_mode(value : Boolean): Box[Unit] = save("api_compatibility_mode", value)


/////
///// Feature switches /////
/////


/**
* Should we evaluate scripts in the variables?
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ case class RestDataSerializerImpl (
)
Full(extendResponseCompatibility(base, extension))
} catch {
case e:Exception => e
case e:Exception =>
val errorMsg = "Error while trying to serialize Directive Diff. cause is: " + e.getMessage()
logger.error(errorMsg)
Failure(errorMsg)
Expand Down
Loading

0 comments on commit 46580ed

Please sign in to comment.