forked from Normation/rudder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
449 additions
and
69 deletions.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
...core/src/main/scala/com/normation/rudder/services/policies/write/AgentSpecificLogic.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
************************************************************************************* | ||
* Copyright 2017 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 com.normation.rudder.services.policies.write | ||
|
||
import org.apache.commons.io.FileUtils | ||
import scala.io.Codec | ||
import java.io.File | ||
import net.liftweb.common.Box | ||
import net.liftweb.util.Helpers.tryo | ||
import com.normation.inventory.domain.AgentType | ||
import com.normation.inventory.domain.COMMUNITY_AGENT | ||
import com.normation.inventory.domain.NOVA_AGENT | ||
import com.normation.utils.Control.sequence | ||
import net.liftweb.common.Full | ||
import com.normation.inventory.domain.DSC_AGENT | ||
|
||
/* | ||
* This file contain agent-type specific logic used during the policy | ||
* writing process, mainly: | ||
* - specific files (like expected_reports.csv for CFEngine-based agent) | ||
* - specific format for "bundle" sequence. | ||
*/ | ||
|
||
//containser for agent specific file written during policy generation | ||
final case class AgentSpecificFile( | ||
path: String | ||
) | ||
|
||
// does that implementation knows something about the current agent type | ||
trait AgentSpecificGenerationHandle { | ||
def handle(agentType: AgentType): Boolean | ||
} | ||
|
||
|
||
// specific generic (i.e non bundle order linked) system variable | ||
// todo - need to plug in systemvariablespecservice | ||
// idem for the bundle seq | ||
|
||
//write what must be written for the given configuration | ||
trait WriteAgentSpecificFiles { | ||
def write(cfg: AgentNodeWritableConfiguration): Box[List[AgentSpecificFile]] | ||
} | ||
|
||
|
||
// the pipeline of processing for the specific writes | ||
object WriteAllAgentSpecificFiles extends WriteAgentSpecificFiles { | ||
|
||
/** | ||
* Ordered list of handlers | ||
*/ | ||
var pipeline: List[WriteAgentSpecificFiles with AgentSpecificGenerationHandle] = { | ||
CFEngineAgentSpecificGeneration :: DscAgentSpecificGeneration :: Nil | ||
} | ||
|
||
override def write(cfg: AgentNodeWritableConfiguration): Box[List[AgentSpecificFile]] = { | ||
(sequence(pipeline) { handler => | ||
if(handler.handle(cfg.agentType)) { | ||
handler.write(cfg) | ||
} else { | ||
Full(Nil) | ||
} | ||
}).map( _.flatten.toList) | ||
} | ||
|
||
} | ||
|
||
|
||
trait AgentSpecificGeneration extends WriteAgentSpecificFiles with AgentSpecificGenerationHandle | ||
|
||
object CFEngineAgentSpecificGeneration extends AgentSpecificGeneration { | ||
val GENEREATED_CSV_FILENAME = "rudder_expected_reports.csv" | ||
|
||
|
||
override def handle(agentType: AgentType): Boolean = agentType == COMMUNITY_AGENT || agentType == NOVA_AGENT | ||
|
||
override def write(cfg: AgentNodeWritableConfiguration): Box[List[AgentSpecificFile]] = { | ||
writeExpectedReportsCsv(cfg.paths, cfg.expectedReportsCsv, GENEREATED_CSV_FILENAME) | ||
} | ||
|
||
|
||
private[this] def writeExpectedReportsCsv(paths: NodePromisesPaths, csv: ExpectedReportsCsv, csvFilename: String): Box[List[AgentSpecificFile]] = { | ||
val path = new File(paths.newFolder, csvFilename) | ||
for { | ||
_ <- tryo { FileUtils.writeStringToFile(path, csv.lines.mkString("\n"), Codec.UTF8.charSet) } ?~! | ||
s"Can not write the expected reports CSV file at path '${path.getAbsolutePath}'" | ||
} yield { | ||
AgentSpecificFile(path.getAbsolutePath) :: Nil | ||
} | ||
} | ||
} | ||
|
||
/* | ||
* This will go in the plugin, and will be contributed somehow at config time. | ||
*/ | ||
object DscAgentSpecificGeneration extends AgentSpecificGeneration { | ||
|
||
override def handle(agentType: AgentType): Boolean = agentType == DSC_AGENT | ||
|
||
override def write(cfg: AgentNodeWritableConfiguration): Box[List[AgentSpecificFile]] = { | ||
writeSystemVarJson(cfg.paths) | ||
} | ||
|
||
// just write an empty file for now | ||
private[this] def writeSystemVarJson(paths: NodePromisesPaths) = { | ||
val path = new File(paths.newFolder, "rudder.json") | ||
for { | ||
_ <- tryo { FileUtils.writeStringToFile(path, """{ "comment":"for now, an empty file" } \n""", Codec.UTF8.charSet) } ?~! | ||
s"Can not write json parameter file at path '${path.getAbsolutePath}'" | ||
} yield { | ||
AgentSpecificFile(path.getAbsolutePath) :: Nil | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
rudder-core/src/test/resources/configuration-repository/techniques/dsc-agent/category.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!-- | ||
Copyright 2017 Normation SAS | ||
This program 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, Version 3. | ||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<xml> | ||
<name>DSC Specific system techniques</name> | ||
<description> | ||
This category contains internal Techniques (system) for | ||
DSC agent. | ||
These Techniques should not be used directly. | ||
</description> | ||
<system>true</system> | ||
</xml> |
51 changes: 51 additions & 0 deletions
51
...c/test/resources/configuration-repository/techniques/dsc-agent/dsc-agent/1.0/metadata.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!-- | ||
Copyright 2017 Normation SAS | ||
This program 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, Version 3. | ||
This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<TECHNIQUE name="DSC Agant"> | ||
<DESCRIPTION>System technique for the DSC Agent</DESCRIPTION> | ||
<SYSTEM>true</SYSTEM> | ||
|
||
<TMLS> | ||
<!-- There should be not TML in DSC agent --> | ||
<!-- <TML name="blabla"/> --> | ||
</TMLS> | ||
|
||
<FILES> | ||
<FILE name="rudder.ps1"> | ||
<OUTPATH>rudder.ps1</OUTPATH> | ||
<INCLUDED>false</INCLUDED> | ||
</FILE> | ||
<FILE name="some-resource.conf" /> | ||
</FILES> | ||
|
||
<BUNDLES> | ||
<!-- <NAME>main</NAME> --> | ||
</BUNDLES> | ||
|
||
<SYSTEMVARS> | ||
<!-- Perhaps we will have specific system vars? --> | ||
<!-- <NAME>SOME_DSC_SPECIFIC_SYSTEM_VAR</NAME> --> | ||
</SYSTEMVARS> | ||
|
||
<SECTIONS> | ||
<!-- This is just some examples --> | ||
<SECTION name="Update" component="true" /> | ||
<SECTION name="ncf Initialization" component="true" /> | ||
<SECTION name="Security parameters" component="true" /> | ||
<SECTION name="Log system for reports" component="true" /> | ||
</SECTIONS> | ||
|
||
</TECHNIQUE> |
8 changes: 8 additions & 0 deletions
8
...src/test/resources/configuration-repository/techniques/dsc-agent/dsc-agent/1.0/rudder.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory=$true)] | ||
[string] $action = "run", | ||
[string] $class = $null | ||
) | ||
|
||
Write-Error "Not an actual agent" |
3 changes: 3 additions & 0 deletions
3
.../resources/configuration-repository/techniques/dsc-agent/dsc-agent/1.0/some-resource.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Blabla bla bla some conf. | ||
|
||
Done. |
Oops, something went wrong.