-
Notifications
You must be signed in to change notification settings - Fork 73
/
AppConfig.scala
1815 lines (1656 loc) · 75.8 KB
/
AppConfig.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*************************************************************************************
* Copyright 2011 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
*
* Rudder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In accordance with the terms of section 7 (7. Additional Terms.) of
* the GNU General Public License version 3, the copyright holders add
* the following Additional permissions:
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
* Public License version 3, when you create a Related Module, this
* Related Module is not considered as a part of the work and may be
* distributed under the license agreement of your choice.
* A "Related Module" means a set of sources files including their
* documentation that, without modification of the Source Code, enables
* supplementary functions or services in addition to those offered by
* the Software.
*
* Rudder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rudder. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************************************
*/
package bootstrap.liftweb
import com.normation.inventory.domain._
import com.normation.inventory.services.core._
import com.normation.inventory.ldap.core._
import com.normation.inventory.services._
import com.normation.rudder.batch._
import com.normation.rudder.services.nodes._
import com.normation.rudder.repository._
import com.normation.rudder.services.queries._
import com.normation.rudder.services.servers._
import com.normation.rudder.services.system._
import com.normation.rudder.services.policies._
import com.normation.rudder.services.reports._
import com.normation.rudder.domain.queries._
import bootstrap.liftweb.checks._
import com.normation.cfclerk.services._
import org.springframework.context.annotation.Lazy
import org.springframework.context.annotation.{ Bean, Configuration, Import, ImportResource }
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.{ ApplicationContext, ApplicationContextAware }
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import com.normation.spring.ScalaApplicationContext
import com.normation.ldap.sdk._
import com.normation.rudder.domain._
import com.normation.rudder.web.services._
import com.normation.rudder.web.model._
import com.normation.utils.StringUuidGenerator
import com.normation.utils.StringUuidGeneratorImpl
import com.normation.rudder.repository.ldap._
import java.io.File
import org.joda.time.DateTime
import com.normation.rudder.services.eventlog._
import com.normation.cfclerk.xmlparsers._
import com.normation.cfclerk.services.impl._
import scala.collection.JavaConversions._
import com.normation.rudder.repository.ldap._
import com.normation.rudder.repository.xml._
import com.normation.rudder.repository.jdbc._
import com.normation.rudder.repository._
import net.liftweb.common.Loggable
import com.normation.rudder.services.eventlog.HistorizationServiceImpl
import com.normation.rudder.services.policies.DeployOnTechniqueCallback
import com.normation.rudder.services.marshalling._
import com.normation.utils.ScalaLock
import com.normation.rudder.web.rest._
import com.normation.rudder.services.user.TrivialPersonIdentService
import com.normation.rudder.services.eventlog.EventLogFactoryImpl
import com.normation.rudder.web.services.UserPropertyService
import java.lang.IllegalArgumentException
import com.normation.rudder.domain.logger.ApplicationLogger
import logger.MigrationLogger
import com.normation.rudder.migration.DefaultXmlEventLogMigration
import net.liftweb.common._
import com.normation.rudder.repository.jdbc.SquerylConnectionProvider
import com.normation.rudder.repository.squeryl._
import com.normation.rudder.repository._
import com.normation.rudder.services.modification.ModificationService
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import scala.util.Try
import com.normation.rudder.repository.inmemory.InMemoryChangeRequestRepository
import com.normation.cfclerk.xmlwriters.SectionSpecWriter
import com.normation.cfclerk.xmlwriters.SectionSpecWriterImpl
import com.normation.rudder.services.modification.DiffServiceImpl
import com.normation.rudder.services.modification.DiffService
import com.normation.rudder.services.user.PersonIdentService
import com.normation.rudder.services.workflows._
import com.normation.rudder.web.rest.RestExtractorService
import com.normation.rudder.web.rest.rule._
import com.normation.rudder.web.rest.directive._
import com.normation.rudder.web.rest.group._
import com.normation.rudder.web.rest.node._
import com.normation.rudder.api.ApiAccount
import com.normation.rudder.api.RoLDAPApiAccountRepository
import com.normation.rudder.api.WoApiAccountRepository
import com.normation.rudder.api.RoApiAccountRepository
import com.normation.rudder.api.WoLDAPApiAccountRepository
import com.normation.rudder.api.TokenGeneratorImpl
import com.normation.rudder.migration._
import com.normation.rudder.web.rest.parameter._
import com.normation.rudder.web.rest.changeRequest._
import com.normation.rudder.reports.execution._
import com.normation.rudder.reports.statusUpdate._
import com.normation.rudder.domain.policies.RuleId
import com.normation.rudder.appconfig._
import com.normation.rudder.rule.category._
import com.normation.rudder.rule.category.GitRuleCategoryArchiverImpl
import com.normation.rudder.services.policies.nodeconfig._
import com.normation.rudder.reports.ComplianceModeService
import com.normation.rudder.reports.ComplianceModeServiceImpl
import com.normation.rudder.reports.AgentRunIntervalService
import com.normation.rudder.reports.AgentRunIntervalServiceImpl
import com.normation.rudder.web.rest.compliance.ComplianceAPI7
import com.normation.rudder.web.rest.compliance.ComplianceAPIService
import com.normation.rudder.services.policies.write.Cf3PromisesFileWriterServiceImpl
import com.normation.rudder.services.policies.write.PathComputerImpl
import com.normation.rudder.services.policies.write.PrepareTemplateVariablesImpl
import com.typesafe.config.ConfigException
import org.apache.commons.io.FileUtils
import com.normation.templates.FillTemplatesService
import com.normation.rudder.web.rest.technique._
import com.normation.rudder.services.quicksearch.FullQuickSearchService
/**
* Define a resource for configuration.
* For now, config properties can only be loaded from either
* a file in the classpath, or a file in the file system.
*/
sealed trait ConfigResource
final case class ClassPathResource(name: String) extends ConfigResource
final case class FileSystemResource(file: File) extends ConfigResource
final case class AuthenticationMethods(name: String) {
val path = s"applicationContext-security-auth-${name}.xml"
val configFile = s"classpath:${path}"
val springBean = s"${name}AuthenticationProvider"
}
/**
* User defined configuration variable
* (from properties file or alike)
*/
object RudderProperties {
val JVM_CONFIG_FILE_KEY = "rudder.configFile"
val DEFAULT_CONFIG_FILE_NAME = "configuration.properties"
/**
* Where to go to look for properties
*/
val configResource = System.getProperty(JVM_CONFIG_FILE_KEY) match {
case null | "" => //use default location in classpath
ApplicationLogger.info("JVM property -D%s is not defined, use configuration file in classpath".format(JVM_CONFIG_FILE_KEY))
ClassPathResource(DEFAULT_CONFIG_FILE_NAME)
case x => //so, it should be a full path, check it
val config = new File(x)
if(config.exists && config.canRead) {
ApplicationLogger.info("Use configuration file defined by JVM property -D%s : %s".format(JVM_CONFIG_FILE_KEY, config.getPath))
FileSystemResource(config)
} else {
ApplicationLogger.error("Can not find configuration file specified by JVM property %s: %s ; abort".format(JVM_CONFIG_FILE_KEY, config.getPath))
throw new javax.servlet.UnavailableException("Configuration file not found: %s".format(config.getPath))
}
}
val config : Config = {
configResource match {
case ClassPathResource(name) => ConfigFactory.load(name)
case FileSystemResource(file) => ConfigFactory.load(ConfigFactory.parseFile(file))
}
}
//some logic for the authentication providers
val authenticationMethods: Seq[AuthenticationMethods] = {
val names = try {
//config.getString can't be null by contract
config.getString("rudder.auth.provider").split(",").toSeq.map( _.trim).collect { case s if(s.size > 0) => s}
} catch {
//if the property is missing, use the default "file" value
//it can be a migration.
case ex: ConfigException.Missing => Seq("file")
}
//always add "rootAdmin" has the first method
//and de-duplicate methods
val auths = ("rootAdmin" +: names).distinct.map(AuthenticationMethods(_))
//for each methods, check that the provider file is present, or log an error and
//disable that provider
auths.flatMap { a =>
if(a.name == "rootAdmin") {
Some(a)
} else {
//try to instantiate
val cpr = new org.springframework.core.io.ClassPathResource(a.path)
if(cpr.exists) {
Some(a)
} else {
ApplicationLogger.error(s"The authentication provider '${a.name}' will not be loaded because the spring ressource file '${a.configFile}' was not found")
None
}
}
}
}
}
/**
* Static initialization of Rudder services.
* This is not a cake-pattern, more an ad-hoc replacement
* for Spring AppConfig, which is so slow.
*/
object RudderConfig extends Loggable {
import RudderProperties.config
//
// Public properties
// Here, we define static nouns for all theses properties
//
private[this] val filteredPasswords = scala.collection.mutable.Buffer[String]()
//the LDAP password used for authentication is not used here, but should not appear nonetheless
filteredPasswords += "rudder.auth.ldap.connection.bind.password"
//other values
val LDAP_HOST = config.getString("ldap.host")
val LDAP_PORT = config.getInt("ldap.port")
val LDAP_AUTHDN = config.getString("ldap.authdn")
val LDAP_AUTHPW = config.getString("ldap.authpw") ; filteredPasswords += "ldap.authpw"
val LDAP_INVENTORIES_ACCEPTED_BASEDN = config.getString("ldap.inventories.accepted.basedn")
val LDAP_INVENTORIES_PENDING_BASEDN = config.getString("ldap.inventories.pending.basedn")
val LDAP_INVENTORIES_REMOVED_BASEDN = config.getString("ldap.inventories.removed.basedn")
val LDAP_INVENTORIES_SOFTWARE_BASEDN = config.getString("ldap.inventories.software.basedn")
val LDAP_RUDDER_BASE = config.getString("ldap.rudder.base")
val LDAP_NODE_BASE = config.getString("ldap.node.base")
val RUDDER_DIR_BACKUP = config.getString("rudder.dir.backup")
val RUDDER_DIR_DEPENDENCIES = config.getString("rudder.dir.dependencies")
val RUDDER_DIR_UPLOADED_FILE_SHARING = config.getString("rudder.dir.uploaded.file.sharing")
val RUDDER_DIR_LOCK = config.getString("rudder.dir.lock") //TODO no more used ?
val RUDDER_DIR_SHARED_FILES_FOLDER = config.getString("rudder.dir.shared.files.folder")
val RUDDER_DIR_LICENSESFOLDER = config.getString("rudder.dir.licensesFolder")
val RUDDER_ENDPOINT_CMDB = config.getString("rudder.endpoint.cmdb")
val RUDDER_WEBDAV_USER = config.getString("rudder.webdav.user")
val RUDDER_WEBDAV_PASSWORD = config.getString("rudder.webdav.password") ; filteredPasswords += "rudder.webdav.password"
val RUDDER_COMMUNITY_PORT = config.getInt("rudder.community.port")
val RUDDER_COMMUNITY_CHECKPROMISES_COMMAND = config.getString("rudder.community.checkpromises.command")
val RUDDER_NOVA_CHECKPROMISES_COMMAND = config.getString("rudder.nova.checkpromises.command")
val RUDDER_CFENGINE_RELOAD_SERVER_COMMAND = config.getString("rudder.cfengine.reload.server.command")
val RUDDER_JDBC_DRIVER = config.getString("rudder.jdbc.driver")
val RUDDER_JDBC_URL = config.getString("rudder.jdbc.url")
val RUDDER_JDBC_USERNAME = config.getString("rudder.jdbc.username")
val RUDDER_JDBC_PASSWORD = config.getString("rudder.jdbc.password") ; filteredPasswords += "rudder.jdbc.password"
val RUDDER_JDBC_MAX_POOL_SIZE = config.getInt("rudder.jdbc.maxPoolSize")
val RUDDER_DIR_GITROOT = config.getString("rudder.dir.gitRoot")
val RUDDER_DIR_TECHNIQUES = config.getString("rudder.dir.techniques")
val RUDDER_BATCH_DYNGROUP_UPDATEINTERVAL = config.getInt("rudder.batch.dyngroup.updateInterval") //60 //one hour
val RUDDER_BATCH_TECHNIQUELIBRARY_UPDATEINTERVAL = config.getInt("rudder.batch.techniqueLibrary.updateInterval") //60 * 5 //five minutes
val RUDDER_BATCH_REPORTSCLEANER_ARCHIVE_TTL = config.getInt("rudder.batch.reportscleaner.archive.TTL") //AutomaticReportsCleaning.defaultArchiveTTL
val RUDDER_BATCH_REPORTSCLEANER_DELETE_TTL = config.getInt("rudder.batch.reportscleaner.delete.TTL") //AutomaticReportsCleaning.defaultDeleteTTL
val RUDDER_BATCH_REPORTSCLEANER_FREQUENCY = config.getString("rudder.batch.reportscleaner.frequency") //AutomaticReportsCleaning.defaultDay
val RUDDER_BATCH_DATABASECLEANER_RUNTIME_HOUR = config.getInt("rudder.batch.databasecleaner.runtime.hour") //AutomaticReportsCleaning.defaultHour
val RUDDER_BATCH_DATABASECLEANER_RUNTIME_MINUTE = config.getInt("rudder.batch.databasecleaner.runtime.minute") //AutomaticReportsCleaning.defaultMinute
val RUDDER_BATCH_DATABASECLEANER_RUNTIME_DAY = config.getString("rudder.batch.databasecleaner.runtime.day") //"sunday"
val RUDDER_BATCH_REPORTS_LOGINTERVAL = config.getInt("rudder.batch.reports.logInterval") //1 //one minute
val RUDDER_TECHNIQUELIBRARY_GIT_REFS_PATH = config.getString("rudder.techniqueLibrary.git.refs.path")
val RUDDER_AUTOARCHIVEITEMS = config.getBoolean("rudder.autoArchiveItems") //true
val RUDDER_SYSLOG_PORT = config.getInt("rudder.syslog.port") //514
val RUDDER_REPORTS_EXECUTION_MAX_DAYS = config.getInt("rudder.batch.storeAgentRunTimes.maxDays") // In days : 5
val RUDDER_REPORTS_EXECUTION_INTERVAL = config.getInt("rudder.batch.storeAgentRunTimes.updateInterval") // In seconds : 5
val BIN_EMERGENCY_STOP = config.getString("bin.emergency.stop")
val HISTORY_INVENTORIES_ROOTDIR = config.getString("history.inventories.rootdir")
val UPLOAD_ROOT_DIRECTORY = config.getString("upload.root.directory")
//used in spring security "applicationContext-security.xml", be careful if you change its name
val RUDDER_REST_ALLOWNONAUTHENTICATEDUSER = config.getBoolean("rudder.rest.allowNonAuthenticatedUser")
val RUDDER_DEBUG_NODE_CONFIGURATION_PATH = config.getString("rudder.debug.nodeconfiguration.path")
// Roles definitions
val RUDDER_SERVER_ROLES = Seq(
//each time, it's (role name, key in the config file)
RudderServerRole("rudder-ldap", config.getString("rudder.server-roles.ldap"))
, RudderServerRole("rudder-inventory-endpoint", config.getString("rudder.server-roles.inventory-endpoint"))
, RudderServerRole("rudder-db", config.getString("rudder.server-roles.db"))
, RudderServerRole("rudder-relay-top", config.getString("rudder.server-roles.relay-top"))
, RudderServerRole("rudder-web", config.getString("rudder.server-roles.web"))
, RudderServerRole("rudder-relay-promises-only", config.getString("rudder.server-roles.relay-promises-only"))
, RudderServerRole("rudder-cfengine-mission-portal", config.getString("rudder.server-roles.cfengine-mission-portal"))
)
val licensesConfiguration = "licenses.xml"
val logentries = "logentries.xml"
val prettyPrinter = new RudderPrettyPrinter(Int.MaxValue, 2)
val userLibraryDirectoryName = "directives"
val groupLibraryDirectoryName = "groups"
val rulesDirectoryName = "rules"
val ruleCategoriesDirectoryName = "ruleCategories"
val parametersDirectoryName = "parameters"
//deprecated
val BASE_URL = Try(config.getString("base.url")).getOrElse("")
//
// Theses services can be called from the outer worl/
// They must be typed with there abstract interface, as
// such service must not expose implementation details
//
val pendingNodesDit: InventoryDit = pendingNodesDitImpl
val acceptedNodesDit: InventoryDit = acceptedNodesDitImpl
val nodeDit: NodeDit = nodeDitImpl
val rudderDit: RudderDit = rudderDitImpl
val roLDAPConnectionProvider: LDAPConnectionProvider[RoLDAPConnection] = roLdap
val roRuleRepository: RoRuleRepository = roLdapRuleRepository
val woRuleRepository: WoRuleRepository = woLdapRuleRepository
val woNodeRepository: WoNodeRepository = woLdapNodeRepository
val roNodeGroupRepository: RoNodeGroupRepository = roLdapNodeGroupRepository
val woNodeGroupRepository: WoNodeGroupRepository = woLdapNodeGroupRepository
val techniqueRepository: TechniqueRepository = techniqueRepositoryImpl
val updateTechniqueLibrary: UpdateTechniqueLibrary = techniqueRepositoryImpl
val roDirectiveRepository: RoDirectiveRepository = roLdapDirectiveRepository
val woDirectiveRepository: WoDirectiveRepository = woLdapDirectiveRepository
val readOnlySoftwareDAO: ReadOnlySoftwareDAO = softwareInventoryDAO
val eventLogRepository: EventLogRepository = logRepository
val eventLogDetailsService: EventLogDetailsService = eventLogDetailsServiceImpl
val reportingService: ReportingService = reportingServiceImpl
lazy val asyncComplianceService : AsyncComplianceService = new AsyncComplianceService(reportingService)
val stringUuidGenerator: StringUuidGenerator = uuidGen
val cmdbQueryParser: CmdbQueryParser = queryParser
val getBaseUrlService: GetBaseUrlService = baseUrlService
val fileManager: FileManager = fileManagerImpl
val startStopOrchestrator: StartStopOrchestrator = startStopOrchestratorImpl
val inventoryHistoryLogRepository: InventoryHistoryLogRepository = diffRepos
val inventoryEventLogService: InventoryEventLogService = inventoryLogEventServiceImpl
val ruleApplicationStatus: RuleApplicationStatusService = ruleApplicationStatusImpl
val newNodeManager: NewNodeManager = newNodeManagerImpl
val nodeGrid: NodeGrid = nodeGridImpl
val nodeSummaryService: NodeSummaryService = nodeSummaryServiceImpl
val jsTreeUtilService: JsTreeUtilService = jsTreeUtilServiceImpl
val directiveEditorService: DirectiveEditorService = directiveEditorServiceImpl
val userPropertyService: UserPropertyService = userPropertyServiceImpl
val eventListDisplayer: EventListDisplayer = eventListDisplayerImpl
val asyncDeploymentAgent: AsyncDeploymentAgent = asyncDeploymentAgentImpl
val policyServerManagementService: PolicyServerManagementService = psMngtService
val updateDynamicGroups: UpdateDynamicGroups = dyngroupUpdaterBatch
val databaseManager: DatabaseManager = databaseManagerImpl
val automaticReportsCleaning: AutomaticReportsCleaning = dbCleaner
val checkTechniqueLibrary: CheckTechniqueLibrary = techniqueLibraryUpdater
val automaticReportLogger: AutomaticReportLogger = autoReportLogger
val nodeConfigurationService: NodeConfigurationService = nodeConfigurationServiceImpl
val removeNodeService: RemoveNodeService = removeNodeServiceImpl
val nodeInfoService: NodeInfoService = nodeInfoServiceImpl
val reportDisplayer: ReportDisplayer = reportDisplayerImpl
val dependencyAndDeletionService: DependencyAndDeletionService = dependencyAndDeletionServiceImpl
val itemArchiveManager: ItemArchiveManager = itemArchiveManagerImpl
val personIdentService: PersonIdentService = personIdentServiceImpl
val gitRevisionProvider: GitRevisionProvider = gitRevisionProviderImpl
val logDisplayer: LogDisplayer = logDisplayerImpl
val fullInventoryRepository: LDAPFullInventoryRepository = ldapFullInventoryRepository
val acceptedNodeQueryProcessor: QueryProcessor = queryProcessor
val categoryHierarchyDisplayer: CategoryHierarchyDisplayer = categoryHierarchyDisplayerImpl
val dynGroupService: DynGroupService = dynGroupServiceImpl
val ditQueryData: DitQueryData = ditQueryDataImpl
val reportsRepository : ReportsRepository = reportsRepositoryImpl
val eventLogDeploymentService: EventLogDeploymentService = eventLogDeploymentServiceImpl
val allBootstrapChecks : BootstrapChecks = allChecks
lazy val srvGrid = new SrvGrid(roAgentRunsRepository, asyncComplianceService, configService)
val findExpectedReportRepository : FindExpectedReportRepository = findExpectedRepo
val historizationRepository : HistorizationRepository = historizationJdbcRepository
val roApiAccountRepository : RoApiAccountRepository = roLDAPApiAccountRepository
val woApiAccountRepository : WoApiAccountRepository = woLDAPApiAccountRepository
val roWorkflowRepository : RoWorkflowRepository = new RoWorkflowJdbcRepository(jdbcTemplate)
val woWorkflowRepository : WoWorkflowRepository = new WoWorkflowJdbcRepository(jdbcTemplate, roWorkflowRepository)
lazy val roAgentRunsRepository : RoReportsExecutionRepository = cachedAgentRunRepository
lazy val woAgentRunsRepository : WoReportsExecutionRepository = cachedAgentRunRepository
//all cache that need to be cleared are stored here
lazy val clearableCache: Seq[CachedRepository] = Seq(
cachedAgentRunRepository
, recentChangesService
, reportingServiceImpl
, nodeInfoServiceImpl
)
val inMemoryChangeRequestRepository : InMemoryChangeRequestRepository = new InMemoryChangeRequestRepository
val ldapInventoryMapper = inventoryMapper
val roChangeRequestRepository : RoChangeRequestRepository = {
//a runtime checking of the workflow to use
new EitherRoChangeRequestRepository(
configService.rudder_workflow_enabled
, new RoChangeRequestJdbcRepository(
jdbcTemplate
, new ChangeRequestsMapper(changeRequestChangesUnserialisation)
)
, inMemoryChangeRequestRepository
)
}
val woChangeRequestRepository : WoChangeRequestRepository = {
//a runtime checking of the workflow to use
new EitherWoChangeRequestRepository(
configService.rudder_workflow_enabled
, new WoChangeRequestJdbcRepository(
jdbcTemplate
, changeRequestChangesSerialisation
, roChangeRequestRepository
)
, inMemoryChangeRequestRepository
)
}
val roRuleCategoryRepository : RoRuleCategoryRepository = roLDAPRuleCategoryRepository
val ruleCategoryService : RuleCategoryService = new RuleCategoryService()
val woRuleCategoryRepository : WoRuleCategoryRepository = woLDAPRuleCategoryRepository
val changeRequestEventLogService : ChangeRequestEventLogService = new ChangeRequestEventLogServiceImpl(eventLogRepository)
val xmlSerializer = XmlSerializerImpl(
ruleSerialisation
, directiveSerialisation
, nodeGroupSerialisation
, globalParameterSerialisation
,ruleCategorySerialisation
)
val xmlUnserializer = XmlUnserializerImpl(
ruleUnserialisation
, directiveUnserialisation
, nodeGroupUnserialisation
, globalParameterUnserialisation
, ruleCategoryUnserialisation
)
val workflowEventLogService = new WorkflowEventLogServiceImpl(eventLogRepository,uuidGen)
val diffService: DiffService = new DiffServiceImpl()
val commitAndDeployChangeRequest : CommitAndDeployChangeRequestService =
new CommitAndDeployChangeRequestServiceImpl(
uuidGen
, roChangeRequestRepository
, woChangeRequestRepository
, roDirectiveRepository
, woDirectiveRepository
, roNodeGroupRepository
, woNodeGroupRepository
, roRuleRepository
, woRuleRepository
, roLDAPParameterRepository
, woLDAPParameterRepository
, asyncDeploymentAgent
, dependencyAndDeletionService
, configService.rudder_workflow_enabled
, xmlSerializer
, xmlUnserializer
, sectionSpecParser
)
val asyncWorkflowInfo = new AsyncWorkflowInfo
val workflowService: WorkflowService = {
new EitherWorkflowService(
configService.rudder_workflow_enabled
, new TwoValidationStepsWorkflowServiceImpl(
workflowEventLogService
, commitAndDeployChangeRequest
, roWorkflowRepository
, woWorkflowRepository
, asyncWorkflowInfo
, configService.rudder_workflow_self_validation
, configService.rudder_workflow_self_deployment
)
, new NoWorkflowServiceImpl(
commitAndDeployChangeRequest
, inMemoryChangeRequestRepository
)
)
}
val changeRequestService: ChangeRequestService = new ChangeRequestServiceImpl (
roChangeRequestRepository
, woChangeRequestRepository
, changeRequestEventLogService
, uuidGen
, configService.rudder_workflow_enabled
)
val roParameterService : RoParameterService = roParameterServiceImpl
val woParameterService : WoParameterService = woParameterServiceImpl
//////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// REST ///////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
val restExtractorService =
RestExtractorService (
roRuleRepository
, roDirectiveRepository
, roNodeGroupRepository
, techniqueRepository
, queryParser
, userPropertyService
, workflowService
)
val tokenGenerator = new TokenGeneratorImpl(32)
val restDeploy = new RestDeploy(asyncDeploymentAgentImpl, uuidGen)
val restDyngroupReload = new RestDyngroupReload(dyngroupUpdaterBatch)
val restTechniqueReload = new RestTechniqueReload(techniqueRepositoryImpl, uuidGen)
val restArchiving = new RestArchiving(itemArchiveManagerImpl,personIdentServiceImpl, uuidGen)
val restGetGitCommitAsZip = new RestGetGitCommitAsZip(gitRepo)
val restApiAccounts = new RestApiAccounts(roApiAccountRepository,woApiAccountRepository,restExtractorService,tokenGenerator, uuidGen)
val restDataSerializer = RestDataSerializerImpl(techniqueRepository,diffService, configService.api_compatibility_mode)
val restQuicksearch = new RestQuicksearch(new FullQuickSearchService()(roLDAPConnectionProvider, nodeDit, acceptedNodesDit, rudderDit, roDirectiveRepository))
val ruleApiService2 =
new RuleApiService2(
roRuleRepository
, woRuleRepository
, uuidGen
, asyncDeploymentAgent
, changeRequestService
, workflowService
, restExtractorService
, configService.rudder_workflow_enabled
, restDataSerializer
)
val ruleApi2 =
new RuleAPI2 (
roRuleRepository
, restExtractorService
, ruleApiService2
)
val ruleApiService6 =
new RuleApiService6 (
roRuleCategoryRepository
, roRuleRepository
, woRuleCategoryRepository
, ruleCategoryService
, restDataSerializer
)
val ruleApi6 =
new RuleAPI6 (
ruleApiService6
, ruleApi2
, restExtractorService
, uuidGen
)
val directiveApiService2 =
new DirectiveAPIService2 (
roDirectiveRepository
, woDirectiveRepository
, uuidGen
, asyncDeploymentAgent
, changeRequestService
, workflowService
, restExtractorService
, configService.rudder_workflow_enabled
, directiveEditorService
, restDataSerializer
, techniqueRepositoryImpl
)
val directiveApi2 =
new DirectiveAPI2 (
roDirectiveRepository
, restExtractorService
, directiveApiService2
, stringUuidGenerator
)
val TechniqueApiService6 =
new TechniqueAPIService6 (
roDirectiveRepository
, restDataSerializer
, techniqueRepositoryImpl
)
val techniqueApi6 =
new TechniqueAPI6 (
restExtractorService
, TechniqueApiService6
)
val groupApiService2 =
new GroupApiService2 (
roNodeGroupRepository
, woNodeGroupRepository
, uuidGen
, asyncDeploymentAgent
, changeRequestService
, workflowService
, restExtractorService
, queryProcessor
, configService.rudder_workflow_enabled
, restDataSerializer
)
val groupApiService5 = new GroupApiService5 (groupApiService2)
val groupApi2 =
new GroupAPI2 (
roNodeGroupRepository
, restExtractorService
, groupApiService2
)
val groupApi5 =
new GroupAPI5 (
restExtractorService
, groupApi2
, groupApiService5
)
val groupApiService6 =
new GroupApiService6 (
roNodeGroupRepository
, woNodeGroupRepository
, restDataSerializer
)
val groupApi6 =
new GroupAPI6 (
groupApiService6
, groupApi5
, restExtractorService
, uuidGen
)
val nodeApiService2 =
NodeApiService2 (
newNodeManager
, nodeInfoService
, removeNodeService
, uuidGen
, restExtractorService
, restDataSerializer
, false
)
val nodeApi2 =
NodeAPI2 (
nodeApiService2
, restExtractorService
)
val nodeApi4 = {
val fixedApiService2 = nodeApiService2.copy(fixedTag = true)
val fixedApi2 = nodeApi2.copy(apiV2 = fixedApiService2)
new NodeAPI4 (
fixedApi2
, new NodeApiService4 (
fullInventoryRepository
, nodeInfoService
, softwareInventoryDAO
, uuidGen
, restExtractorService
, restDataSerializer
)
, restExtractorService
)
}
val nodeApi5 = {
new NodeAPI5 (
nodeApi4
, new NodeApiService5(
woNodeRepository
, nodeInfoService
, uuidGen
, restExtractorService
, asyncDeploymentAgent
)
, restExtractorService
)
}
val nodeApi6 = {
new NodeAPI6 (
nodeApi5
, new NodeApiService6(
nodeInfoService
, fullInventoryRepository
, softwareInventoryDAO
, restExtractorService
, restDataSerializer
, queryProcessor
)
, restExtractorService
)
}
val nodeApi8 = {
new NodeAPI8 (
nodeApi6
, new NodeApiService8(
woNodeRepository
, nodeInfoService
, uuidGen
, asyncDeploymentAgent
)
, restExtractorService
, restDataSerializer
)
}
val parameterApiService2 =
new ParameterApiService2 (
roLDAPParameterRepository
, woLDAPParameterRepository
, uuidGen
, changeRequestService
, workflowService
, restExtractorService
, configService.rudder_workflow_enabled
, restDataSerializer
)
val parameterApi2 =
new ParameterAPI2 (
restExtractorService
, parameterApiService2
)
val changeRequestApiService3 =
new ChangeRequestAPIService3 (
roChangeRequestRepository
, woChangeRequestRepository
, roWorkflowRepository
, woWorkflowRepository
, techniqueRepository
, changeRequestService
, workflowService
, commitAndDeployChangeRequest
, restExtractorService
, restDataSerializer
, configService.rudder_workflow_enabled
)
val changeRequestApi3 =
new ChangeRequestAPI3 (
restExtractorService
, changeRequestApiService3
)
private[this] val complianceAPIService = new ComplianceAPIService(
roRuleRepository
, nodeInfoService
, roNodeGroupRepository
, reportingService
, roDirectiveRepository
, globalComplianceModeService.getGlobalComplianceMode _
)
val complianceApi6 = new ComplianceAPI7(restExtractorService, complianceAPIService, v6compatibility = true)
val complianceApi7 = new ComplianceAPI7(restExtractorService, complianceAPIService)
val settingsApi8 = new SettingsAPI8(restExtractorService, configService)
// First working version with support for rules, directives, nodes and global parameters
val apiV2 : List[RestAPI] = ruleApi2 :: directiveApi2 :: groupApi2 :: nodeApi2 :: parameterApi2 :: Nil
// Add change request support
val apiV3 : List[RestAPI] = changeRequestApi3 :: apiV2
// Add inventory support on nodes
val apiV4 : List[RestAPI] = nodeApi4 :: apiV3.filter( _ != nodeApi2)
// Allow empty query for groups, add key-values support on nodes
val apiV5 : List[RestAPI] = nodeApi5 :: groupApi5 :: apiV4.filter( _ != nodeApi4).filter( _ != groupApi2)
// Add compliance and technique endpoint and filtering off node/rule/group results
val apiV6 : List[RestAPI] = techniqueApi6 ::complianceApi6 :: nodeApi6 :: ruleApi6 :: groupApi6 :: apiV5.filter( _ != nodeApi5).filter( _ != ruleApi2).filter( _ != groupApi5)
// apiv7 just add compatible changes on compliances, adding "level" option and "compliance mode" attribute in response
val apiV7 = complianceApi7 :: apiV6.filter( _ != complianceApi6)
// apiv8 add policy mode in node API and settings API
val apiV8 = nodeApi8 :: settingsApi8 :: apiV7.filter( _ != nodeApi6)
val apis = {
Map (
//Rudder 2.7
( ApiVersion(2,true) -> apiV2 )
//Rudder 2.8
, ( ApiVersion(3,true) -> apiV3 )
//Rudder 2.10
, ( ApiVersion(4,true) -> apiV4 )
//Rudder 3.0
, ( ApiVersion(5,false) -> apiV5 )
//Rudder 3.1
, ( ApiVersion(6,false) -> apiV6 )
//Rudder 3.2
, ( ApiVersion(7,false) -> apiV7 )
//Rudder 4.0
, ( ApiVersion(8,false) -> apiV8 )
)
}
val apiDispatcher = APIDispatcher(apis, restExtractorService)
lazy val configService: ReadConfigService with UpdateConfigService =
new LDAPBasedConfigService(
config
, new LdapConfigRepository(rudderDit, rwLdap, ldapEntityMapper, eventLogRepository, stringUuidGenerator)
, asyncWorkflowInfo
)
lazy val recentChangesService = new CachedNodeChangesServiceImpl(new NodeChangesServiceImpl(reportsRepository))
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////
/**
* A method to call to force initialisation of all object and services.
* This is a good place to check boottime things, and throws
* "application broken - can not start" exception
*
* Important: if that method is not called, RudderConfig will be
* lazy and will only be initialised on the first call to one
* of its (public) methods.
*/
def init() : Unit = {
import scala.collection.JavaConverters._
val config = RudderProperties.config
if(ApplicationLogger.isInfoEnabled) {
//sort properties by key name
val properties = config.entrySet.asScala.toSeq.sortBy( _.getKey ).map{ x =>
//the log line: registered property: property_name=property_value
s"registered property: ${x.getKey}=${if(filteredPasswords.contains(x.getKey)) "**********" else x.getValue.render}"
}
ApplicationLogger.info("List of registered properties:")
properties.foreach { p =>
ApplicationLogger.info(p)
}
}
}
//
// Concrete implementation.
// They are private to that object, and they can refer to other
// private implementation as long as they conform to interface.
//
private[this] lazy val roLDAPApiAccountRepository = new RoLDAPApiAccountRepository(
rudderDitImpl
, roLdap
, ldapEntityMapper
)
private[this] lazy val woLDAPApiAccountRepository = new WoLDAPApiAccountRepository(
rudderDitImpl
, rwLdap
, ldapEntityMapper
, ldapDiffMapper
, logRepository
, personIdentServiceImpl
)
private[this] lazy val ruleApplicationStatusImpl: RuleApplicationStatusService = new RuleApplicationStatusServiceImpl()
private[this] lazy val acceptedNodesDitImpl: InventoryDit = new InventoryDit(LDAP_INVENTORIES_ACCEPTED_BASEDN, LDAP_INVENTORIES_SOFTWARE_BASEDN, "Accepted inventories")
private[this] lazy val pendingNodesDitImpl: InventoryDit = new InventoryDit(LDAP_INVENTORIES_PENDING_BASEDN, LDAP_INVENTORIES_SOFTWARE_BASEDN, "Pending inventories")
private[this] lazy val removedNodesDitImpl = new InventoryDit(LDAP_INVENTORIES_REMOVED_BASEDN,LDAP_INVENTORIES_SOFTWARE_BASEDN,"Removed Servers")
private[this] lazy val rudderDitImpl: RudderDit = new RudderDit(LDAP_RUDDER_BASE)
private[this] lazy val nodeDitImpl: NodeDit = new NodeDit(LDAP_NODE_BASE)
private[this] lazy val inventoryDitService: InventoryDitService = new InventoryDitServiceImpl(pendingNodesDitImpl, acceptedNodesDitImpl,removedNodesDitImpl)
private[this] lazy val uuidGen: StringUuidGenerator = new StringUuidGeneratorImpl
private[this] lazy val systemVariableSpecService = new SystemVariableSpecServiceImpl()
private[this] lazy val variableBuilderService: VariableBuilderService = new VariableBuilderServiceImpl()
private[this] lazy val ldapEntityMapper = new LDAPEntityMapper(rudderDitImpl, nodeDitImpl, acceptedNodesDitImpl, queryParser, inventoryMapper)
///// items serializer - service that transforms items to XML /////
private[this] lazy val ruleSerialisation: RuleSerialisation = new RuleSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val ruleCategorySerialisation: RuleCategorySerialisation = new RuleCategorySerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val rootSectionSerialisation : SectionSpecWriter = new SectionSpecWriterImpl()
private[this] lazy val activeTechniqueCategorySerialisation: ActiveTechniqueCategorySerialisation =
new ActiveTechniqueCategorySerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val activeTechniqueSerialisation: ActiveTechniqueSerialisation =
new ActiveTechniqueSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val directiveSerialisation: DirectiveSerialisation =
new DirectiveSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val nodeGroupCategorySerialisation: NodeGroupCategorySerialisation =
new NodeGroupCategorySerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val nodeGroupSerialisation: NodeGroupSerialisation =
new NodeGroupSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val deploymentStatusSerialisation : DeploymentStatusSerialisation =
new DeploymentStatusSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val globalParameterSerialisation: GlobalParameterSerialisation =
new GlobalParameterSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val apiAccountSerialisation: APIAccountSerialisation =
new APIAccountSerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val propertySerialization: GlobalPropertySerialisation =
new GlobalPropertySerialisationImpl(Constants.XML_CURRENT_FILE_FORMAT.toString)
private[this] lazy val changeRequestChangesSerialisation : ChangeRequestChangesSerialisation =
new ChangeRequestChangesSerialisationImpl(
Constants.XML_CURRENT_FILE_FORMAT.toString
, nodeGroupSerialisation
, directiveSerialisation
, ruleSerialisation
, globalParameterSerialisation
, techniqueRepositoryImpl
, rootSectionSerialisation
)
private[this] lazy val eventLogFactory = new EventLogFactoryImpl(
ruleSerialisation
, directiveSerialisation
, nodeGroupSerialisation
, activeTechniqueSerialisation
, globalParameterSerialisation
, apiAccountSerialisation
, propertySerialization
)
private[this] lazy val pathComputer = new PathComputerImpl(
Constants.NODE_PROMISES_PARENT_DIR_BASE
, Constants.NODE_PROMISES_PARENT_DIR
, RUDDER_DIR_BACKUP
, Constants.CFENGINE_COMMUNITY_PROMISES_PATH
, Constants.CFENGINE_NOVA_PROMISES_PATH
)
private[this] lazy val baseUrlService: GetBaseUrlService = new DefaultBaseUrlService(BASE_URL)
/*
* For now, we don't want to query server other
* than the accepted ones.
*/
private[this] lazy val ditQueryDataImpl = new DitQueryData(acceptedNodesDitImpl, nodeDit)
private[this] lazy val queryParser = new CmdbQueryParser with DefaultStringQueryParser with JsonQueryLexer {
override val criterionObjects = Map[String, ObjectCriterion]() ++ ditQueryDataImpl.criteriaMap
}
private[this] lazy val inventoryMapper: InventoryMapper = new InventoryMapper(inventoryDitService, pendingNodesDitImpl, acceptedNodesDitImpl, removedNodesDitImpl)
private[this] lazy val fullInventoryFromLdapEntries: FullInventoryFromLdapEntries = new FullInventoryFromLdapEntriesImpl(inventoryDitService, inventoryMapper)
private[this] lazy val ldapDiffMapper = new LDAPDiffMapper(ldapEntityMapper, queryParser)
private[this] lazy val activeTechniqueCategoryUnserialisation = new ActiveTechniqueCategoryUnserialisationImpl
private[this] lazy val activeTechniqueUnserialisation = new ActiveTechniqueUnserialisationImpl
private[this] lazy val directiveUnserialisation = new DirectiveUnserialisationImpl
private[this] lazy val nodeGroupCategoryUnserialisation = new NodeGroupCategoryUnserialisationImpl
private[this] lazy val nodeGroupUnserialisation = new NodeGroupUnserialisationImpl(queryParser)
private[this] lazy val ruleUnserialisation = new RuleUnserialisationImpl
private[this] lazy val ruleCategoryUnserialisation = new RuleCategoryUnserialisationImpl
private[this] lazy val globalParameterUnserialisation = new GlobalParameterUnserialisationImpl
private[this] lazy val changeRequestChangesUnserialisation = new ChangeRequestChangesUnserialisationImpl(
nodeGroupUnserialisation
, directiveUnserialisation
, ruleUnserialisation
, globalParameterUnserialisation
, techniqueRepository
, sectionSpecParser
)
private[this] lazy val deploymentStatusUnserialisation = new DeploymentStatusUnserialisationImpl
private[this] lazy val entityMigration = DefaultXmlEventLogMigration
private[this] lazy val eventLogDetailsServiceImpl = new EventLogDetailsServiceImpl(
queryParser
, new DirectiveUnserialisationImpl
, new NodeGroupUnserialisationImpl(queryParser)
, new RuleUnserialisationImpl
, new ActiveTechniqueUnserialisationImpl
, new DeploymentStatusUnserialisationImpl
, new GlobalParameterUnserialisationImpl
, new ApiAccountUnserialisationImpl
)
//////////////////////////////////////////////////////////
// non pure services that could perhaps be
//////////////////////////////////////////////////////////
// => rwLdap is only used to repair an error, that could be repaired elsewhere.
// => because of systemVariableSpecService
// metadata.xml parser
private[this] lazy val variableSpecParser = new VariableSpecParser
private[this] lazy val sectionSpecParser = new SectionSpecParser(variableSpecParser)
private[this] lazy val techniqueParser = {
new TechniqueParser(variableSpecParser,sectionSpecParser,systemVariableSpecService)
}
private[this] lazy val userPropertyServiceImpl = new StatelessUserPropertyService(