Skip to content
Permalink
Browse files

Refactoring bundles to new Container Context API

  • Loading branch information
atooni committed Feb 15, 2020
1 parent 6aba8b1 commit d8d1190e2700ecba1f260305018f802906e5bca3
@@ -75,7 +75,7 @@ trait ContainerContext {
/**
* Access to the Container Identifier Service
*/
def identifierService() : ContainerIdentifierService
def identifierService : ContainerIdentifierService

/**
* Access to a blended resolver for config values
@@ -133,7 +133,7 @@ class ContainerPropertyResolver(ctContext : ContainerContext) {
)

private[this] val resolver : Map[String, Resolver] = Map(
ContainerIdentifierService.containerId -> (_ => ctContext.identifierService().uuid)
ContainerIdentifierService.containerId -> (_ => ctContext.identifierService.uuid)
)

private[this] def extractModifier(s : String) : Option[(Modifier, String)] = {
@@ -162,7 +162,7 @@ class ContainerPropertyResolver(ctContext : ContainerContext) {
case Some(m) => m
}

val props = Option(ctContext.identifierService().properties).getOrElse(Map.empty)
val props = Option(ctContext.identifierService.properties).getOrElse(Map.empty)

// First, we resolve the rule from the environment vars or System properties
// The resolution is mandatory
@@ -242,13 +242,13 @@ class ContainerPropertyResolver(ctContext : ContainerContext) {
context.registerFunction(m.getName(), m)
}

context.setRootObject(ctContext.identifierService())
context.setRootObject(ctContext.identifierService)

additionalProps.foreach {
case (k, v) =>
context.setVariable(k, v)
}
context.setVariable("idSvc", ctContext.identifierService())
context.setVariable("idSvc", ctContext.identifierService)

val exp = parseExpression(line).get

@@ -7,7 +7,7 @@ import akka.http.scaladsl.marshalling.Marshal
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.Unmarshal
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import blended.container.context.api.ContainerIdentifierService
import blended.container.context.api.ContainerContext
import blended.mgmt.agent.internal.MgmtReporter.MgmtReporterConfig
import blended.prickle.akka.http.PrickleSupport
import blended.updater.config._
@@ -46,7 +46,7 @@ trait MgmtReporter extends Actor with PrickleSupport {
////////////////////
// ABSTRACT
protected val config : Try[MgmtReporterConfig]
protected val idSvc : ContainerIdentifierService
protected val ctContext : ContainerContext
////////////////////

private case class MgmtReporterState(
@@ -93,8 +93,8 @@ trait MgmtReporter extends Actor with PrickleSupport {
config.foreach { cfg =>

val info = ContainerInfo(
containerId = idSvc.uuid,
properties = idSvc.properties,
containerId = ctContext.identifierService.uuid,
properties = ctContext.identifierService.properties,
serviceInfos = state.serviceInfos.values.toList,
profiles = state.lastProfileInfo.profiles,
timestampMsec = System.currentTimeMillis(),
@@ -2,7 +2,7 @@ package blended.mgmt.agent.internal

import akka.actor.Props
import blended.akka.{OSGIActor, OSGIActorConfig}
import blended.container.context.api.ContainerIdentifierService
import blended.container.context.api.ContainerContext
import blended.mgmt.agent.internal.MgmtReporter.MgmtReporterConfig
import blended.util.logging.Logger

@@ -43,7 +43,7 @@ class OsgiMgmtReporter(cfg : OSGIActorConfig) extends OSGIActor(cfg) with MgmtRe
x
}

override protected val idSvc : ContainerIdentifierService = cfg.idSvc
override protected val ctContext : ContainerContext = cfg.ctContext
}

object OsgiMgmtReporter {
@@ -1,6 +1,6 @@
package blended.security.ssl

import blended.container.context.api.ContainerIdentifierService
import blended.container.context.api.ContainerContext
import blended.security.ssl.internal.ConfigCommonNameProvider
import blended.util.config.Implicits._
import com.typesafe.config.Config
@@ -19,12 +19,12 @@ object SelfSignedConfig {
val sigAlgPath = "signatureAlgorithm"
val validDaysPath = "validDays"

def fromConfig(cfg : Config, idSvc : ContainerIdentifierService) : SelfSignedConfig = {
def fromConfig(cfg : Config, ctCtxt : ContainerContext) : SelfSignedConfig = {
val keyStrength = cfg.getInt("keyStrength", defaultKeyStrength)
val signatureAlgorithm = cfg.getString("signatureAlgorithm", "SHA256withRSA")
val validDays = cfg.getInt("validDays", 1)

SelfSignedConfig(new ConfigCommonNameProvider(cfg, idSvc), keyStrength, signatureAlgorithm, validDays)
SelfSignedConfig(new ConfigCommonNameProvider(cfg, ctCtxt), keyStrength, signatureAlgorithm, validDays)
}
}

@@ -1,6 +1,6 @@
package blended.security.ssl.internal

import blended.container.context.api.ContainerIdentifierService
import blended.container.context.api.ContainerContext
import blended.domino.TypesafeConfigWatching
import blended.security.ssl.{CertificateManager, CertificateProvider, SelfSignedCertificateProvider, SelfSignedConfig}
import blended.util.config.Implicits._
@@ -14,11 +14,11 @@ class CertificateActivator extends DominoActivator with TypesafeConfigWatching {

private[this] val log = Logger[CertificateActivator]

private[this] def setupSelfSignedProvider(cfg : Config, idSvc : ContainerIdentifierService) : Unit = {
private[this] def setupSelfSignedProvider(cfg : Config, ctCtxt : ContainerContext) : Unit = {
// Should we provide a CertifacteProvider with a self-signed certificate?
cfg.getConfigOption("selfsigned") match {
case Some(selfCfg) =>
val selfSignedProvider = new SelfSignedCertificateProvider(SelfSignedConfig.fromConfig(selfCfg, idSvc))
val selfSignedProvider = new SelfSignedCertificateProvider(SelfSignedConfig.fromConfig(selfCfg, ctCtxt))
selfSignedProvider.providesService[CertificateProvider](Map(
"provider" -> "default"
))
@@ -54,11 +54,11 @@ class CertificateActivator extends DominoActivator with TypesafeConfigWatching {

whenBundleActive {

whenTypesafeConfigAvailable { (cfg, idSvc) =>
whenTypesafeConfigAvailable { (cfg, ctCtxt) =>

val mgrConfig = CertificateManagerConfig.fromConfig(cfg, new PasswordHasher(idSvc.uuid), idSvc)
val mgrConfig = CertificateManagerConfig.fromConfig(cfg, new PasswordHasher(ctCtxt.identifierService.uuid), ctCtxt)

setupSelfSignedProvider(cfg, idSvc)
setupSelfSignedProvider(cfg, ctCtxt)
setupCertificateManager(mgrConfig)

whenAdvancedServicePresent[SSLContext]("(type=server)") { ctxt =>
@@ -1,6 +1,6 @@
package blended.security.ssl.internal

import blended.container.context.api.ContainerIdentifierService
import blended.container.context.api.ContainerContext
import blended.security.ssl.CommonNameProvider
import blended.util.config.Implicits._
import com.typesafe.config.Config
@@ -9,14 +9,14 @@ import scala.util.Try

object KeystoreConfig {

def fromConfig(cfg: Config, hasher: PasswordHasher, idSrv: ContainerIdentifierService): KeystoreConfig = {
def fromConfig(cfg: Config, hasher: PasswordHasher, ctCtxt: ContainerContext): KeystoreConfig = {
val keyStore = cfg.getString("keyStore", System.getProperty("javax.net.ssl.keyStore"))
val storePass: String = idSrv.resolvePropertyString(cfg
val storePass: String = ctCtxt.resolveString(cfg
.getStringOption("explicit.storePass")
.orElse(cfg.getStringOption("storePass").map(hasher.password))
.getOrElse(System.getProperty("javax.net.ssl.keyStorePassword")))
.get.asInstanceOf[String]
val keyPass: String = idSrv.resolvePropertyString(cfg
val keyPass: String = ctCtxt.resolveString(cfg
.getStringOption("explicit.keyPass")
.orElse(cfg.getStringOption("keyPass").map(hasher.password))
.getOrElse(System.getProperty("javax.net.ssl.keyPassword")))
@@ -56,7 +56,7 @@ object CertificateManagerConfig {
* Read a [[CertificateManagerConfig]] from a typesafe [[Config]],
* using the given [[PasswordHasher]] to hash the passwords (`keyPass` and `storePass`).
*/
def fromConfig(cfg : Config, hasher : PasswordHasher, idSvc : ContainerIdentifierService) : CertificateManagerConfig = {
def fromConfig(cfg : Config, hasher : PasswordHasher, ctCtxt : ContainerContext) : CertificateManagerConfig = {

val clientOnly: Boolean = cfg.getBoolean("clientOnly", false)

@@ -65,14 +65,14 @@ object CertificateManagerConfig {
val keystoreCfg: Option[KeystoreConfig] = if (clientOnly) {
None
} else {
Some(KeystoreConfig.fromConfig(cfg, hasher, idSvc))
Some(KeystoreConfig.fromConfig(cfg, hasher, ctCtxt))
}

val providers: List[String] = cfg.getStringList("providerList", List.empty)

val certConfigs = cfg.getConfigMap("certificates", Map.empty).map {
case (k, v) =>
CertificateConfig.fromConfig(k, v, idSvc)
CertificateConfig.fromConfig(k, v, ctCtxt)
}.toList

val refresherConfig = cfg.getConfigOption("refresher").map(c => RefresherConfig.fromConfig(c).get)
@@ -105,11 +105,11 @@ object CertificateConfig {

val defaultMinValidDays = 10

def fromConfig(alias : String, cfg : Config, idSvc : ContainerIdentifierService) : CertificateConfig = {
def fromConfig(alias : String, cfg : Config, ctCtxt : ContainerContext) : CertificateConfig = {
val provider = cfg.getString("provider", "default")
val minValidDays = cfg.getInt("minValidDays", defaultMinValidDays)

CertificateConfig(provider, alias, minValidDays, new ConfigCommonNameProvider(cfg, idSvc))
CertificateConfig(provider, alias, minValidDays, new ConfigCommonNameProvider(cfg, ctCtxt))
}
}

@@ -1,19 +1,19 @@
package blended.security.ssl.internal

import blended.container.context.api.ContainerIdentifierService
import blended.container.context.api.ContainerContext
import blended.security.ssl.CommonNameProvider
import blended.util.config.Implicits._
import com.typesafe.config.Config

import scala.util.Try

class ConfigCommonNameProvider(cfg : Config, idSvc : ContainerIdentifierService) extends CommonNameProvider {
class ConfigCommonNameProvider(cfg : Config, ctCtxt : ContainerContext) extends CommonNameProvider {

override def commonName() : Try[String] = idSvc.resolvePropertyString(cfg.getString("commonName")).map(_.toString())
override def commonName() : Try[String] = ctCtxt.resolveString(cfg.getString("commonName")).map(_.toString())

override def alternativeNames() : Try[List[String]] = Try {
cfg.getStringListOption("logicalHostnames").getOrElse(List.empty).map { s =>
idSvc.resolvePropertyString(s).map(_.toString()).get
ctCtxt.resolveString(s).map(_.toString()).get
}
}
}
@@ -1,6 +1,18 @@
## Container Context API migration


### Jms Utils

[ ] Remove blended evaluation from bundle config code

[ ] Add test case for config evaluation and activator to jms utils.
[ ] Add test case for config evaluation and activator

### MgmtReporter

[ ] Refactor setup bundle actor code

[ ] Add test case for started Mgmt Reporter

### Security SSL

[ ] Remove blendedevaluation from bundle config code

0 comments on commit d8d1190

Please sign in to comment.
You can’t perform that action at this time.