diff --git a/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineConfig.scala b/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineConfig.scala index af63a4323..07fdb7ff2 100644 --- a/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineConfig.scala +++ b/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineConfig.scala @@ -1,42 +1,37 @@ package net.shrine.wiring import com.typesafe.config.Config -import net.shrine.adapter.service.AdapterConfig import net.shrine.broadcaster.HubConfig import net.shrine.config.{ConfigExtensions, Keys} -import net.shrine.protocol.{ResultOutputTypes, HiveCredentials, ResultOutputType} +import net.shrine.protocol.HiveCredentials import net.shrine.qep.QepConfig /** * @author clint * @since Feb 6, 2013 */ final case class ShrineConfig( hubConfig: Option[HubConfig], queryEntryPointConfig: Option[QepConfig], - ontHiveCredentials: HiveCredentials, adapterStatusQuery: String - ) { - -} + ) object ShrineConfig { def apply(config: Config): ShrineConfig = { val configForShrine = config.getConfig("shrine") import Keys._ def getOptionConfiguredIf[T](key:String,constructor: Config => T):Option[T] = { if(configForShrine.getBoolean(s"$key.create")) configForShrine.getOptionConfigured(key,constructor) else None } ShrineConfig( hubConfig = getOptionConfiguredIf(hub, HubConfig(_)), queryEntryPointConfig = getOptionConfiguredIf(queryEntryPoint, QepConfig(_)), - ontHiveCredentials = configForShrine.getConfigured(hiveCredentials, HiveCredentials(_, HiveCredentials.ONT)), adapterStatusQuery = configForShrine.getString(networkStatusQuery) ) } } diff --git a/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala b/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala index dc8bffba7..876d90277 100644 --- a/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala +++ b/apps/shrine-app/src/main/scala/net/shrine/wiring/ShrineOrchestrator.scala @@ -1,356 +1,354 @@ package net.shrine.wiring import javax.sql.DataSource import com.typesafe.config.{Config, ConfigFactory} import net.shrine.adapter.dao.squeryl.tables.{Tables => AdapterTables} import net.shrine.adapter.dao.squeryl.{SquerylAdapterDao, SquerylI2b2AdminDao} import net.shrine.adapter.dao.{AdapterDao, I2b2AdminDao} import net.shrine.adapter.service.{AdapterConfig, AdapterRequestHandler, AdapterResource, AdapterService, I2b2AdminResource, I2b2AdminService} import net.shrine.adapter.translators.{ExpressionTranslator, QueryDefinitionTranslator} import net.shrine.adapter.{Adapter, AdapterMap, DeleteQueryAdapter, FlagQueryAdapter, ReadInstanceResultsAdapter, ReadPreviousQueriesAdapter, ReadQueryDefinitionAdapter, ReadQueryResultAdapter, ReadTranslatedQueryDefinitionAdapter, RenameQueryAdapter, RunQueryAdapter, UnFlagQueryAdapter} import net.shrine.authentication.Authenticator import net.shrine.authorization.QueryAuthorizationService import net.shrine.broadcaster.dao.HubDao import net.shrine.broadcaster.dao.squeryl.SquerylHubDao import net.shrine.broadcaster.service.{BroadcasterMultiplexerResource, BroadcasterMultiplexerService} import net.shrine.broadcaster.{AdapterClientBroadcaster, BroadcastAndAggregationService, BroadcasterClient, InJvmBroadcasterClient, NodeHandle, PosterBroadcasterClient, SigningBroadcastAndAggregationService} import net.shrine.client.{EndpointConfig, HttpClient, JerseyHttpClient, OntClient, Poster, PosterOntClient} import net.shrine.config.ConfigExtensions -import net.shrine.config.Keys._ import net.shrine.config.mappings.{AdapterMappings, AdapterMappingsSource, ClasspathFormatDetectingAdapterMappingsSource} import net.shrine.crypto.{DefaultSignerVerifier, KeyStoreCertCollection, KeyStoreDescriptorParser, TrustParam} import net.shrine.dao.squeryl.{DataSourceSquerylInitializer, SquerylDbAdapterSelecter, SquerylInitializer} import net.shrine.happy.{HappyShrineResource, HappyShrineService} import net.shrine.log.Loggable import net.shrine.ont.data.{OntClientOntologyMetadata, OntologyMetadata} import net.shrine.protocol.{HiveCredentials, ResultOutputTypes, NodeId, RequestType, ResultOutputType} import net.shrine.qep.dao.AuditDao import net.shrine.qep.dao.squeryl.SquerylAuditDao import net.shrine.qep.dao.squeryl.tables.{Tables => HubTables} import net.shrine.qep.{I2b2BroadcastResource, I2b2QepService, QepService, ShrineResource} import net.shrine.status.StatusJaxrs import org.squeryl.internals.DatabaseAdapter /** * @author clint * @since Jan 14, 2014 * * Application wiring for Shrine, in the base, non-HMS case. All vals are protecetd, so they may be accessed, * in subclasses without ballooning this class's public API, and lazy, to work around init-order surprises when * overriding vals declared inline. See * * https://stackoverflow.com/questions/15762650/scala-override-val-in-class-inheritance * * among other links mentioning val overrides, early initializers, etc. -Clint */ object ShrineOrchestrator extends ShrineJaxrsResources with Loggable { import NodeHandleSource.makeNodeHandles override def resources: Iterable[AnyRef] = { Seq(happyResource,statusJaxrs) ++ shrineResource ++ i2b2BroadcastResource ++ adapterResource ++ i2b2AdminResource ++ broadcasterMultiplexerResource } //Load config from file on the classpath called "shrine.conf" lazy val config: Config = ConfigFactory.load("shrine") protected lazy val shrineConfigurationBall: ShrineConfig = ShrineConfig(config) val shrineConfig = config.getConfig("shrine") protected lazy val nodeId: NodeId = NodeId(shrineConfig.getString("humanReadableNodeName")) //TODO: Don't assume keystore lives on the filesystem, could come from classpath, etc protected lazy val keyStoreDescriptor = shrineConfig.getConfigured("keystore",KeyStoreDescriptorParser(_)) protected lazy val shrineCertCollection: KeyStoreCertCollection = KeyStoreCertCollection.fromFile(keyStoreDescriptor) protected lazy val keystoreTrustParam: TrustParam = TrustParam.SomeKeyStore(shrineCertCollection) protected lazy val signerVerifier: DefaultSignerVerifier = new DefaultSignerVerifier(shrineCertCollection) protected lazy val dataSource: DataSource = Jndi("java:comp/env/jdbc/shrineDB").get protected lazy val squerylAdapter: DatabaseAdapter = SquerylDbAdapterSelecter.determineAdapter(shrineConfig.getString("shrineDatabaseType")) protected lazy val squerylInitializer: SquerylInitializer = new DataSourceSquerylInitializer(dataSource, squerylAdapter) private def makePoster = poster(shrineCertCollection) _ private lazy val pmEndpoint: EndpointConfig = shrineConfig.getConfigured("pmEndpoint", EndpointConfig(_)) protected lazy val pmPoster: Poster = makePoster(pmEndpoint) private lazy val ontEndpoint: EndpointConfig = shrineConfig.getConfigured("ontEndpoint", EndpointConfig(_)) protected lazy val ontPoster: Poster = makePoster(ontEndpoint) protected lazy val breakdownTypes: Set[ResultOutputType] = shrineConfig.getOptionConfigured("breakdownResultOutputTypes", ResultOutputTypes.fromConfig).getOrElse(Set.empty) protected lazy val hubDao: HubDao = new SquerylHubDao(squerylInitializer, new net.shrine.broadcaster.dao.squeryl.tables.Tables) - - lazy val crcHiveCredentials = shrineConfig.getConfigured(hiveCredentials, HiveCredentials(_, HiveCredentials.CRC)) + lazy val crcHiveCredentials = shrineConfig.getConfigured("hiveCredentials", HiveCredentials(_, HiveCredentials.CRC)) //todo move as much of this block as possible to the adapter project, and get rid of this multi-assignment of one thing protected lazy val ( adapterService: Option[AdapterService], i2b2AdminService: Option[I2b2AdminService], adapterDao: Option[AdapterDao], adapterMappings: Option[AdapterMappings] ) = adapterComponentsToTuple(shrineConfig.getOptionConfiguredIf("adapter", AdapterConfig(_)).map { adapterConfig => //todo unwind adapterConfig and just have an adapter val crcEndpoint: EndpointConfig = adapterConfig.crcEndpoint val crcPoster: Poster = makePoster(crcEndpoint) val squerylAdapterTables: AdapterTables = new AdapterTables val adapterDao: AdapterDao = new SquerylAdapterDao(squerylInitializer, squerylAdapterTables)(breakdownTypes) //NB: Is i2b2HiveCredentials.projectId the right project id to use? val i2b2AdminDao: I2b2AdminDao = new SquerylI2b2AdminDao(crcHiveCredentials.projectId, squerylInitializer, squerylAdapterTables) val adapterMappingsSource: AdapterMappingsSource = ClasspathFormatDetectingAdapterMappingsSource(adapterConfig.adapterMappingsFileName) //NB: Fail fast val adapterMappings: AdapterMappings = adapterMappingsSource.load.get val expressionTranslator: ExpressionTranslator = ExpressionTranslator(adapterMappings) val queryDefinitionTranslator: QueryDefinitionTranslator = new QueryDefinitionTranslator(expressionTranslator) val doObfuscation = adapterConfig.setSizeObfuscation val runQueryAdapter = new RunQueryAdapter( crcPoster, adapterDao, crcHiveCredentials, queryDefinitionTranslator, adapterConfig.adapterLockoutAttemptsThreshold, doObfuscation, adapterConfig.immediatelyRunIncomingQueries, breakdownTypes, collectAdapterAudit = adapterConfig.collectAdapterAudit ) val readInstanceResultsAdapter: Adapter = new ReadInstanceResultsAdapter( crcPoster, crcHiveCredentials, adapterDao, doObfuscation, breakdownTypes, collectAdapterAudit = adapterConfig.collectAdapterAudit ) val readQueryResultAdapter: Adapter = new ReadQueryResultAdapter( crcPoster, crcHiveCredentials, adapterDao, doObfuscation, breakdownTypes, collectAdapterAudit = adapterConfig.collectAdapterAudit ) val readPreviousQueriesAdapter: Adapter = new ReadPreviousQueriesAdapter(adapterDao) val deleteQueryAdapter: Adapter = new DeleteQueryAdapter(adapterDao) val renameQueryAdapter: Adapter = new RenameQueryAdapter(adapterDao) val readQueryDefinitionAdapter: Adapter = new ReadQueryDefinitionAdapter(adapterDao) val readTranslatedQueryDefinitionAdapter: Adapter = new ReadTranslatedQueryDefinitionAdapter(nodeId, queryDefinitionTranslator) val flagQueryAdapter: Adapter = new FlagQueryAdapter(adapterDao) val unFlagQueryAdapter: Adapter = new UnFlagQueryAdapter(adapterDao) val adapterMap = AdapterMap(Map( RequestType.QueryDefinitionRequest -> runQueryAdapter, RequestType.GetRequestXml -> readQueryDefinitionAdapter, RequestType.UserRequest -> readPreviousQueriesAdapter, RequestType.InstanceRequest -> readInstanceResultsAdapter, RequestType.MasterDeleteRequest -> deleteQueryAdapter, RequestType.MasterRenameRequest -> renameQueryAdapter, RequestType.GetQueryResult -> readQueryResultAdapter, RequestType.ReadTranslatedQueryDefinitionRequest -> readTranslatedQueryDefinitionAdapter, RequestType.FlagQueryRequest -> flagQueryAdapter, RequestType.UnFlagQueryRequest -> unFlagQueryAdapter)) AdapterComponents( new AdapterService(nodeId, signerVerifier, adapterConfig.maxSignatureAge, adapterMap), new I2b2AdminService(adapterDao, i2b2AdminDao, pmPoster, runQueryAdapter), adapterDao, adapterMappings) }) val shouldQuerySelf = "hub.shouldQuerySelf" lazy val localAdapterServiceOption: Option[AdapterRequestHandler] = if(shrineConfig.getOption(shouldQuerySelf,_.getBoolean).getOrElse(false)) { //todo give this a default value (of false) in the reference.conf for the Hub, and make it part of the Hub's apply(config) require(adapterService.isDefined, s"Self-querying requested because shrine.$shouldQuerySelf is true, but this node is not configured to have an adapter") adapterService } else None //todo eventually make this just another downstream node accessed via loopback private lazy val broadcastDestinations: Option[Set[NodeHandle]] = shrineConfigurationBall.hubConfig.map(hubConfig => makeNodeHandles(keystoreTrustParam, hubConfig.maxQueryWaitTime, hubConfig.downstreamNodes, nodeId, localAdapterServiceOption, breakdownTypes)) protected lazy val (shrineService, i2b2Service, auditDao) = queryEntryPointComponentsToTuple(shrineConfigurationBall.queryEntryPointConfig.map { queryEntryPointConfig => val broadcasterClient: BroadcasterClient = { if(queryEntryPointConfig.broadcasterIsLocal) { //If broadcaster is local, we need a hub config //TODO: Enforce this when unmarshalling configs require(broadcastDestinations.isDefined, s"The QEP's config implied a local hub (no broadcasterServiceEndpoint), but either no downstream nodes were configured, the hub was not configured, or the hub's configuration specified not to create it.") val broadcaster: AdapterClientBroadcaster = AdapterClientBroadcaster(broadcastDestinations.get, hubDao) InJvmBroadcasterClient(broadcaster) } else { //if broadcaster is remote, we need an endpoint //TODO: Enforce this when unmarshalling configs require(queryEntryPointConfig.broadcasterServiceEndpoint.isDefined, "Non-local broadcaster requested, but no URL for the remote broadcaster is specified") PosterBroadcasterClient(makePoster(queryEntryPointConfig.broadcasterServiceEndpoint.get), breakdownTypes) } } val commonName:String = shrineCertCollection.myCommonName.getOrElse{ val hostname = java.net.InetAddress.getLocalHost.getHostName warn(s"No common name available from ${shrineCertCollection.descriptor}. Using $hostname instead.") hostname } val broadcastService: BroadcastAndAggregationService = SigningBroadcastAndAggregationService(broadcasterClient, signerVerifier, queryEntryPointConfig.signingCertStrategy) val auditDao: AuditDao = new SquerylAuditDao(squerylInitializer, new HubTables) val authenticationType = queryEntryPointConfig.authenticationType val authorizationType = queryEntryPointConfig.authorizationType val authenticator: Authenticator = AuthStrategy.determineAuthenticator(authenticationType, pmPoster) val authorizationService: QueryAuthorizationService = AuthStrategy.determineQueryAuthorizationService(authorizationType, shrineConfigurationBall, authenticator) debug(s"authorizationService set to $authorizationService") QueryEntryPointComponents( QepService( commonName, auditDao, authenticator, authorizationService, queryEntryPointConfig.includeAggregateResults, broadcastService, queryEntryPointConfig.maxQueryWaitTime, breakdownTypes, queryEntryPointConfig.collectQepAudit ), I2b2QepService( commonName, auditDao, authenticator, authorizationService, queryEntryPointConfig.includeAggregateResults, broadcastService, queryEntryPointConfig.maxQueryWaitTime, breakdownTypes, queryEntryPointConfig.collectQepAudit ), auditDao) }) private lazy val broadcasterOption = unpackHubComponents { for { hubConfig <- shrineConfigurationBall.hubConfig } yield { require(broadcastDestinations.isDefined, "This node is configured to be a hub, but no downstream nodes are defined") HubComponents(AdapterClientBroadcaster(broadcastDestinations.get, hubDao)) } } protected lazy val broadcasterMultiplexerService = { for { broadcaster <- broadcasterOption hubConfig <- shrineConfigurationBall.hubConfig } yield { BroadcasterMultiplexerService(broadcaster, hubConfig.maxQueryWaitTime) } } protected lazy val pmUrlString: String = pmEndpoint.url.toString protected lazy val ontologyMetadata: OntologyMetadata = { import scala.concurrent.duration._ //TODO: XXX: Un-hard-code max wait time param - val ontClient: OntClient = new PosterOntClient(shrineConfigurationBall.ontHiveCredentials, 1.minute, ontPoster) + val ontClient: OntClient = new PosterOntClient(shrineConfig.getConfigured("hiveCredentials", HiveCredentials(_, HiveCredentials.ONT)), 1.minute, ontPoster) new OntClientOntologyMetadata(ontClient) } //TODO: Don't assume we're an adapter with an AdapterMappings (don't call .get) protected lazy val happyService: HappyShrineService = { new HappyShrineService( config = config, keystoreDescriptor = keyStoreDescriptor, shrineConfigObject = shrineConfigurationBall, certCollection = shrineCertCollection, signer = signerVerifier, pmPoster = pmPoster, ontologyMetadata = ontologyMetadata, adapterMappings = adapterMappings, auditDaoOption = auditDao, adapterDaoOption = adapterDao, broadcasterOption = broadcasterOption, adapterOption = adapterService ) } protected lazy val happyResource: HappyShrineResource = new HappyShrineResource(happyService) protected lazy val statusJaxrs: StatusJaxrs = StatusJaxrs(config) protected lazy val shrineResource: Option[ShrineResource] = shrineService.map(ShrineResource(_)) protected lazy val i2b2BroadcastResource: Option[I2b2BroadcastResource] = i2b2Service.map(new I2b2BroadcastResource(_, breakdownTypes)) protected lazy val adapterResource: Option[AdapterResource] = adapterService.map(AdapterResource(_)) protected lazy val i2b2AdminResource: Option[I2b2AdminResource] = i2b2AdminService.map(I2b2AdminResource(_, breakdownTypes)) protected lazy val broadcasterMultiplexerResource: Option[BroadcasterMultiplexerResource] = broadcasterMultiplexerService.map(BroadcasterMultiplexerResource(_)) def makeHttpClient(keystoreCertCollection: KeyStoreCertCollection, endpoint: EndpointConfig): HttpClient = { import TrustParam.{AcceptAllCerts, SomeKeyStore} val trustParam = if (endpoint.acceptAllCerts) AcceptAllCerts else SomeKeyStore(keystoreCertCollection) JerseyHttpClient(trustParam, endpoint.timeout) } private final case class AdapterComponents(adapterService: AdapterService, i2b2AdminService: I2b2AdminService, adapterDao: AdapterDao, adapterMappings: AdapterMappings) private final case class QueryEntryPointComponents(shrineService: QepService, i2b2Service: I2b2QepService, auditDao: AuditDao) private final case class HubComponents(broadcaster: AdapterClientBroadcaster) //TODO: TEST //todo get rid of this private def adapterComponentsToTuple(option: Option[AdapterComponents]): (Option[AdapterService], Option[I2b2AdminService], Option[AdapterDao], Option[AdapterMappings]) = option match { case None => (None, None, None, None) case Some(AdapterComponents(a, b, c, d)) => (Option(a), Option(b), Option(c), Option(d)) } //TODO: TEST //todo get rid of this private def queryEntryPointComponentsToTuple(option: Option[QueryEntryPointComponents]): (Option[QepService], Option[I2b2QepService], Option[AuditDao]) = option match { case None => (None, None, None) case Some(QueryEntryPointComponents(a, b, c)) => (Option(a), Option(b), Option(c)) } //TODO: TEST //todo get rid of this private def unpackHubComponents(option: Option[HubComponents]): Option[AdapterClientBroadcaster] = option.map(_.broadcaster) def poster(keystoreCertCollection: KeyStoreCertCollection)(endpoint: EndpointConfig): Poster = { val httpClient = makeHttpClient(keystoreCertCollection, endpoint) Poster(endpoint.url.toString, httpClient) } } diff --git a/apps/shrine-app/src/test/scala/net/shrine/wiring/AuthStrategyTest.scala b/apps/shrine-app/src/test/scala/net/shrine/wiring/AuthStrategyTest.scala index 45c8267e9..cb352cb00 100644 --- a/apps/shrine-app/src/test/scala/net/shrine/wiring/AuthStrategyTest.scala +++ b/apps/shrine-app/src/test/scala/net/shrine/wiring/AuthStrategyTest.scala @@ -1,105 +1,104 @@ package net.shrine.wiring import net.shrine.protocol.CredentialConfig import net.shrine.util.ShouldMatchersForJUnit import org.junit.Test import net.shrine.client.{EndpointConfig, Poster} import net.shrine.authentication.{AuthenticationType, PmAuthenticator, Authenticator} import net.shrine.hms.authentication.EcommonsPmAuthenticator import net.shrine.qep.{QepConfig, AllowsAllAuthenticator} import net.shrine.authorization.{AuthorizationType, AllowsAllAuthorizationService} import net.shrine.hms.authorization.HmsDataStewardAuthorizationService import java.net.URL import net.shrine.hms.authorization.JerseySheriffClient import net.shrine.crypto.SigningCertStrategy /** * @author clint * @since Jul 2, 2014 */ final class AuthStrategyTest extends ShouldMatchersForJUnit { private[this] val pmPoster = Poster("http://example.com", null) @Test def testDefaultDetermineAuthenticator(): Unit = { import AuthenticationType._ intercept[Exception] { AuthStrategy.determineAuthenticator(null, pmPoster) } { val authenticator = AuthStrategy.determineAuthenticator(Pm, pmPoster).asInstanceOf[PmAuthenticator] authenticator.pmPoster should be(pmPoster) } { val authenticator = AuthStrategy.determineAuthenticator(Ecommons, pmPoster).asInstanceOf[EcommonsPmAuthenticator] authenticator.pmPoster should be(pmPoster) } { val authenticator = AuthStrategy.determineAuthenticator(NoAuthentication, pmPoster) authenticator should be(AllowsAllAuthenticator) } } @Test def testDefaultDetermineAuthorizationService(): Unit = { import AuthorizationType._ intercept[Exception] { AuthStrategy.determineQueryAuthorizationService(null, null, null) } { val authService = AuthStrategy.determineQueryAuthorizationService(NoAuthorization, null, null) authService should be(AllowsAllAuthorizationService) } { val authenticationType = AuthenticationType.Ecommons val authorizationType = HmsSteward import scala.concurrent.duration._ val sheriffUrl = "http://example.com/sheriff" val sheriffCredentials = CredentialConfig(None, "u", "p") val shrineConfig = ShrineConfig( None, //hub config Some(QepConfig( authenticationType, authorizationType, Some(EndpointConfig(new URL(sheriffUrl), acceptAllCerts = false, 42.minutes)), Some(sheriffCredentials), None, includeAggregateResults = false, 1.minute, None, SigningCertStrategy.Attach, collectQepAudit = false)), - null, //more hiveCredentials null //adapterStatusQuery ) //breakdown types val authenticator: Authenticator = AllowsAllAuthenticator val authService = AuthStrategy.determineQueryAuthorizationService(HmsSteward, shrineConfig, authenticator).asInstanceOf[HmsDataStewardAuthorizationService] authService.authenticator should be(authenticator) //noinspection ScalaUnnecessaryParentheses authService.sheriffClient should not be(null) val jerseySheriffClient = authService.sheriffClient.asInstanceOf[JerseySheriffClient] jerseySheriffClient.sheriffUrl should equal(sheriffUrl) jerseySheriffClient.sheriffUsername should equal(sheriffCredentials.username) jerseySheriffClient.sheriffPassword should equal(sheriffCredentials.password) } } } \ No newline at end of file diff --git a/apps/shrine-app/src/test/scala/net/shrine/wiring/ShrineConfigTest.scala b/apps/shrine-app/src/test/scala/net/shrine/wiring/ShrineConfigTest.scala index 7bbaa9404..f090be5b0 100644 --- a/apps/shrine-app/src/test/scala/net/shrine/wiring/ShrineConfigTest.scala +++ b/apps/shrine-app/src/test/scala/net/shrine/wiring/ShrineConfigTest.scala @@ -1,91 +1,81 @@ package net.shrine.wiring import com.typesafe.config.ConfigFactory import net.shrine.authentication.AuthenticationType import net.shrine.authorization.AuthorizationType import net.shrine.broadcaster.NodeListParserTest import net.shrine.client.EndpointConfigTest import net.shrine.crypto.SigningCertStrategy import net.shrine.util.ShouldMatchersForJUnit import org.junit.Test /** * @author clint * @since Feb 6, 2013 */ final class ShrineConfigTest extends ShouldMatchersForJUnit { private def shrineConfig(baseFileName: String, loadBreakdownsFile: Boolean = true) = { val baseConfig = ConfigFactory.load(baseFileName) val breakdownConfig = ConfigFactory.load("breakdowns") val config = if(loadBreakdownsFile) baseConfig.withFallback(breakdownConfig) else baseConfig ShrineConfig(config) } import scala.concurrent.duration._ @Test def testApply() { import NodeListParserTest.node import EndpointConfigTest.endpoint val conf = shrineConfig("shrine") conf.queryEntryPointConfig.get.authenticationType should be(AuthenticationType.Ecommons) conf.queryEntryPointConfig.get.authorizationType should be(AuthorizationType.HmsSteward) conf.queryEntryPointConfig.get.sheriffEndpoint.get should equal(endpoint("http://localhost:8080/shrine-hms-authorization/queryAuthorization")) conf.queryEntryPointConfig.get.sheriffCredentials.get.domain should be(None) conf.queryEntryPointConfig.get.sheriffCredentials.get.username should be("sheriffUsername") conf.queryEntryPointConfig.get.sheriffCredentials.get.password should be("sheriffPassword") - conf.ontHiveCredentials.domain should equal("HarvardDemo") - conf.ontHiveCredentials.username should equal("demo") - conf.ontHiveCredentials.password should equal("demouser") - conf.ontHiveCredentials.projectId should equal("SHRINE") - - conf.ontHiveCredentials.domain should equal("HarvardDemo") - conf.ontHiveCredentials.username should equal("demo") - conf.ontHiveCredentials.password should equal("demouser") - conf.ontHiveCredentials.projectId should equal("SHRINE") - conf.queryEntryPointConfig.get.broadcasterIsLocal should be(false) conf.queryEntryPointConfig.get.broadcasterServiceEndpoint.get should equal(endpoint("http://example.com/shrine/rest/broadcaster/broadcast")) conf.queryEntryPointConfig.get.maxQueryWaitTime should equal(5.minutes) conf.queryEntryPointConfig.get.signingCertStrategy should equal(SigningCertStrategy.Attach) conf.queryEntryPointConfig.get.includeAggregateResults should equal(false) conf.hubConfig.get.maxQueryWaitTime should equal(4.5.minutes) conf.adapterStatusQuery should equal("""\\SHRINE\SHRINE\Diagnoses\Mental Illness\Disorders usually diagnosed in infancy, childhood, or adolescence\Pervasive developmental disorders\Infantile autism, current or active state\""") conf.hubConfig.get.downstreamNodes.toSet should equal { Set( node("some hospital", "http://example.com/foo"), node("CHB", "http://example.com/chb"), node("PHS", "http://example.com/phs")) } } @Test def testApplyOptionalFields() { val conf = shrineConfig("shrine-no-optional-configs", loadBreakdownsFile = false) conf.hubConfig should be(None) conf.queryEntryPointConfig should be(None) } @Test def testApplySomeOptionalFields() { val conf = shrineConfig("shrine-some-optional-props") conf.queryEntryPointConfig.get.authenticationType should be(AuthenticationType.Pm) conf.queryEntryPointConfig.get.authorizationType should be(AuthorizationType.NoAuthorization) conf.queryEntryPointConfig.get.signingCertStrategy should be(SigningCertStrategy.DontAttach) } } \ No newline at end of file diff --git a/commons/config/src/main/scala/net/shrine/config/Keys.scala b/commons/config/src/main/scala/net/shrine/config/Keys.scala index 53c70372a..913544aed 100644 --- a/commons/config/src/main/scala/net/shrine/config/Keys.scala +++ b/commons/config/src/main/scala/net/shrine/config/Keys.scala @@ -1,38 +1,37 @@ package net.shrine.config /** * @author clint * @since Jan 17, 2014 * * Keys for Shrine */ //todo distribute to where they are used once the rest of config is cleaned up object Keys { val crcEndpoint = "crcEndpoint" val sheriffEndpoint = "sheriffEndpoint" val sheriffCredentials = "sheriffCredentials" val shrineSteward = "shrineSteward" - val hiveCredentials = "hiveCredentials" //delete when done with ont credentials val ontProjectId = "ontProjectId" val crcProjectId = "crcProjectId" val setSizeObfuscation = "setSizeObfuscation" val isAdapter = "isAdapter" val isBroadcaster = "isBroadcaster" val includeAggregateResults = "includeAggregateResults" val adapterLockoutAttemptsThreshold = "adapterLockoutAttemptsThreshold" val maxQueryWaitTime = "maxQueryWaitTime" val networkStatusQuery = "networkStatusQuery" val adapterMappingsFileName = "adapterMappingsFileName" val adapterMappingsFileType = "adapterMappingsFileType" val downstreamNodes = "downstreamNodes" val maxSignatureAge = "maxSignatureAge" val adapter = "adapter" val hub = "hub" val queryEntryPoint = "queryEntryPoint" val broadcasterIsLocal = "broadcasterIsLocal" val broadcasterServiceEndpoint = "broadcasterServiceEndpoint" val immediatelyRunIncomingQueries = "immediatelyRunIncomingQueries" val authenticationType = "authenticationType" val authorizationType = "authorizationType" val attachSigningCert = "attachSigningCert" }