Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package com.normation.plugins.changevalidation | ||
|
||
import java.util.Properties | ||
|
||
import bootstrap.liftweb.RudderConfig | ||
import bootstrap.liftweb.UserDetailList | ||
import com.normation.plugins.changevalidation.TwoValidationStepsWorkflowServiceImpl.Deployment | ||
import com.normation.plugins.changevalidation.TwoValidationStepsWorkflowServiceImpl.Validation | ||
import com.normation.rudder.AuthorizationType | ||
import com.normation.rudder.domain.workflows.WorkflowNode | ||
import javax.mail.Session | ||
import javax.mail._ | ||
import javax.mail.internet.InternetAddress | ||
import javax.mail.internet.MimeMessage | ||
|
||
import scala.io.Source | ||
|
||
case class Email(value: String) | ||
|
||
case class Username(value: String) | ||
|
||
case class SMTPConf( | ||
smtpHostServer : String | ||
, port : Int | ||
, email : Email | ||
, login : Option[Username] | ||
, password : Option[String] | ||
) | ||
|
||
case class EmailInfo( | ||
state: WorkflowNode | ||
, to: Set[Email] | ||
, replyTo: Set[Email] | ||
, cc: Set[Email] | ||
, bcc: Set[Email] | ||
, subject: String | ||
, template: Option[String] | ||
This comment has been minimized.
Sorry, something went wrong. |
||
) | ||
|
||
object NotificationService { | ||
This comment has been minimized.
Sorry, something went wrong.
VinceMacBuche
|
||
|
||
val path = "/vagrant/email.conf" | ||
val config = getSMTPConf(path) | ||
val (validationEmail, deploymentEmail) = getMailParameter(path) | ||
|
||
//TO-DO : handle errors with ZIO, exceptions, Task ? | ||
def sendEmail(text: String, state: WorkflowNode) = { | ||
val prop = new Properties(); | ||
prop.put("mail.smtp.host", config.smtpHostServer); | ||
prop.put("mail.smtp.port", config.port); | ||
prop.put("mail.smtp.auth", "true"); | ||
prop.put("mail.smtp.starttls.enable", "true"); | ||
val session = (config.login, config.password) match { | ||
case (Some(l), Some(p)) => | ||
val auth = new Authenticator() { | ||
override protected def getPasswordAuthentication = new PasswordAuthentication(l.value, p) | ||
} | ||
Session.getInstance(prop, auth) | ||
case (Some(_), None) => | ||
println("------ DEBUG : MISSING PASSWORD") | ||
Session.getInstance(prop, null) | ||
case (None, Some(_)) => | ||
println("------ DEBUG : MISSING LOGIN") | ||
Session.getInstance(prop, null) | ||
} | ||
val message = new MimeMessage(session); | ||
message.setFrom(new InternetAddress(config.email.value)) | ||
state match { | ||
case Validation => | ||
message.setRecipients( | ||
Message.RecipientType.TO, | ||
validationEmail.to.map(_.value).mkString(",") | ||
) | ||
message.setSubject(validationEmail.subject); | ||
case Deployment => | ||
message.setRecipients( | ||
Message.RecipientType.TO, | ||
deploymentEmail.to.map(_.value).mkString(",") | ||
) | ||
message.setSubject(deploymentEmail.subject); | ||
} | ||
message.setText(text); | ||
Transport.send(message); | ||
|
||
Some("toto") | ||
} | ||
|
||
// hostServer=smtp.gmail.com | ||
// port=587 | ||
// auth=true | ||
// email=elaad.f@gmail.com | ||
// login=elaad.f@gmail.com | ||
// password=toto | ||
def getConfParameter(path: String) = { | ||
Source.fromFile(path).getLines().toList.map { | ||
This comment has been minimized.
Sorry, something went wrong.
fanf
|
||
line => { | ||
val parameters = line.split("=") | ||
(parameters.head, parameters.tail.head) | ||
} | ||
}.toMap | ||
} | ||
|
||
//TO-DO have to deal with the case where a parameter is not set (logger) | ||
def getSMTPConf(path: String): SMTPConf = { | ||
val config = getConfParameter(path) | ||
SMTPConf( | ||
config("hostServer") | ||
, config("port").toInt | ||
, Email(config("email")) | ||
, if (config.contains("login")) Some(Username(config("login"))) else None | ||
, if (config.contains("password")) Some(config("password")) else None | ||
) | ||
} | ||
|
||
def getMailParameter(path: String) = { | ||
val config = getConfParameter(path) | ||
val validationInfo = | ||
EmailInfo( | ||
Validation | ||
, config("validation-to").split(",").map(Email).toSet | ||
, config("validation-reply-to").split(",").map(Email).toSet | ||
, config("validation-cc").split(",").map(Email).toSet | ||
, config("validation-bcc").split(",").map(Email).toSet | ||
, config("validation-subject") | ||
, if (config.contains("validation-template")) Some(config("validation-template")) else None | ||
) | ||
|
||
val deploymentInfo = | ||
EmailInfo( | ||
Validation | ||
, config("deployment-to").split(",").map(Email).toSet | ||
, config("deployment-reply-to").split(",").map(Email).toSet | ||
, config("deployment-cc").split(",").map(Email).toSet | ||
, config("deployment-bcc").split(",").map(Email).toSet | ||
, config("deployment-subject") | ||
, if (config.contains("deployment-template")) Some(config("deployment-template")) else None | ||
) | ||
(validationInfo, deploymentInfo) | ||
} | ||
|
||
// def readEmails(path: String): Map[Username, Email] = { | ||
// Source.fromFile(path).getLines().toList.map { | ||
// line => { | ||
// val parameters = line.split("=") | ||
// (Username(parameters.head), Email(parameters.tail.head)) | ||
// } | ||
// }.toMap | ||
// | ||
// } | ||
|
||
// def getValidators(allMailing: Map[Username, Email]): Map[Username, Email] = { | ||
// | ||
// val userDetails: UserDetailList = RudderConfig.rudderUserListProvider.authConfig | ||
// val usersInFile = userDetails.users.keySet | ||
// val usersWithRegisterEmails = allMailing.keySet.map(_.value) | ||
// val existingUser = allMailing.filter { | ||
// v => | ||
// usersInFile.intersect(usersWithRegisterEmails).contains(v._1.value) | ||
// } | ||
// val canValidate = existingUser.filter { x => | ||
// userDetails.users(x._1.value).authz.authorizationTypes.contains(AuthorizationType.Deployer.Write) || | ||
// userDetails.users(x._1.value).authz.authorizationTypes.contains(AuthorizationType.Validator.Write) | ||
// } | ||
// canValidate | ||
// } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ import org.joda.time.DateTime | |
|
||
import scala.xml._ | ||
import com.normation.box._ | ||
import com.normation.rudder.domain.nodes.GenericPropertyUtils | ||
|
||
object ChangeRequestChangesForm { | ||
def form = ChooseTemplate( | ||
|
@@ -653,9 +654,9 @@ class ChangeRequestChangesForm( | |
private[this] def displayGlobalParameter(param: GlobalParameter) = ( | ||
"#paramName" #> createGlobalParameterLink(param.name) & | ||
"#name" #> param.name.value & | ||
"#value" #> param.value & | ||
"#description" #> param.description & | ||
"#overridable" #> param.overridable | ||
"#value" #> GenericPropertyUtils.serializeValue(param.value) & | ||
"#description" #> param.description | ||
// "#overridable" #> param.overridable | ||
)(globalParameterXML) | ||
This comment has been minimized.
Sorry, something went wrong.
fanf
|
||
|
||
private[this] def displayGlobalParameterDiff ( | ||
|
@@ -664,9 +665,9 @@ class ChangeRequestChangesForm( | |
) = { | ||
( "#paramName" #> createGlobalParameterLink(param.name) & | ||
"#name" #> param.name.value & | ||
"#value" #> displaySimpleDiff(diff.modValue,"value",Text(param.value)) & | ||
"#description" #> displaySimpleDiff(diff.modDescription,"description",Text(param.description)) & | ||
"#overridable" #> displaySimpleDiff(diff.modOverridable,"overridable",Text(param.overridable.toString)) | ||
"#value" #> displaySimpleDiff(diff.modValue,"value",Text( GenericPropertyUtils.serializeValue(param.value))) & | ||
"#description" #> displaySimpleDiff(diff.modDescription,"description",Text(param.description)) | ||
// "#overridable" #> displaySimpleDiff(diff.modOverridable,"overridable",Text(param.overridable.toString)) | ||
) (globalParameterXML) | ||
} | ||
|
||
|
I think that it should be mandatory. Well, actually: either you have a common section for email info and two templates (one for validation, one for deployement). In that case,
EmailInfo
doesn't, contain any template info.Or you have one full set of email info for each step, and in that case template is mandatory