Skip to content

Commit

Permalink
Merge 60e8ce1 into dee9a5d
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoet committed Sep 17, 2018
2 parents dee9a5d + 60e8ce1 commit 8bb9bec
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ scalacOptions ++= Seq(
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
// "-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Dependencies {
val scalaTestV = "3.0.1"
val scalaCheckV = "1.14.0"

val workbenchUtilV = "0.3-f2a0020"
val workbenchUtilV = "0.3-2771e2d"
val workbenchModelV = "0.12-a19203d"
val workbenchGoogleV = "0.16-f2a0020"
val workbenchNotificationsV = "0.1-f2a0020"
Expand Down
17 changes: 14 additions & 3 deletions src/main/scala/org/broadinstitute/dsde/workbench/sam/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import com.typesafe.scalalogging.LazyLogging
import com.unboundid.ldap.sdk.{LDAPConnection, LDAPConnectionPool}
import javax.net.SocketFactory
import javax.net.ssl.SSLContext

import cats.data.NonEmptyList
import net.ceedubs.ficus.Ficus._
import org.broadinstitute.dsde.workbench.dataaccess.PubSubNotificationDAO
import org.broadinstitute.dsde.workbench.google.GoogleCredentialModes.Pem
import org.broadinstitute.dsde.workbench.google.{HttpGoogleDirectoryDAO, HttpGoogleIamDAO, HttpGoogleProjectDAO, HttpGooglePubSubDAO, HttpGoogleStorageDAO}
import org.broadinstitute.dsde.workbench.google.GoogleCredentialModes.{Json, Pem}
import org.broadinstitute.dsde.workbench.google.{GoogleDirectoryDAO, HttpGoogleDirectoryDAO, HttpGoogleIamDAO, HttpGoogleProjectDAO, HttpGooglePubSubDAO, HttpGoogleStorageDAO}
import org.broadinstitute.dsde.workbench.model.{WorkbenchEmail, WorkbenchException}
import org.broadinstitute.dsde.workbench.sam.api.{SamRoutes, StandardUserInfoDirectives}
import org.broadinstitute.dsde.workbench.sam.config._
Expand All @@ -24,6 +26,7 @@ import org.broadinstitute.dsde.workbench.sam.model._
import org.broadinstitute.dsde.workbench.sam.openam._
import org.broadinstitute.dsde.workbench.sam.schema.JndiSchemaDAO
import org.broadinstitute.dsde.workbench.sam.service._
import org.broadinstitute.dsde.workbench.util.DelegatePool

import scala.concurrent.Future
import scala.concurrent.duration._
Expand Down Expand Up @@ -63,7 +66,15 @@ object Boot extends App with LazyLogging {
val cloudExt = googleServicesConfigOption match {
case Some(googleServicesConfig) =>
val petServiceAccountConfig = config.as[PetServiceAccountConfig]("petServiceAccount")
val googleDirectoryDAO = new HttpGoogleDirectoryDAO(googleServicesConfig.appName, Pem(WorkbenchEmail(googleServicesConfig.serviceAccountClientId), new File(googleServicesConfig.pemFile), Option(googleServicesConfig.subEmail)), "google")

val googleDirDaos = (googleServicesConfig.adminSdkServiceAccounts match {
case None => NonEmptyList.one(Pem(WorkbenchEmail(googleServicesConfig.serviceAccountClientId), new File(googleServicesConfig.pemFile), Option(googleServicesConfig.subEmail)))
case Some(accounts) => accounts.map(account => Json(account.json))
}).map { credentials =>
new HttpGoogleDirectoryDAO(googleServicesConfig.appName, credentials, "google")
}

val googleDirectoryDAO = DelegatePool[GoogleDirectoryDAO](googleDirDaos)
val googleIamDAO = new HttpGoogleIamDAO(googleServicesConfig.appName, Pem(WorkbenchEmail(googleServicesConfig.serviceAccountClientId), new File(googleServicesConfig.pemFile)), "google")
val googlePubSubDAO = new HttpGooglePubSubDAO(googleServicesConfig.appName, Pem(WorkbenchEmail(googleServicesConfig.serviceAccountClientId), new File(googleServicesConfig.pemFile)), "google", googleServicesConfig.groupSyncPubSubProject)
val googleStorageDAO = new HttpGoogleStorageDAO(googleServicesConfig.appName, Pem(WorkbenchEmail(googleServicesConfig.serviceAccountClientId), new File(googleServicesConfig.pemFile)), "google")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.broadinstitute.dsde.workbench.sam.config

import cats.data.NonEmptyList
import org.broadinstitute.dsde.workbench.model.WorkbenchEmail
import org.broadinstitute.dsde.workbench.model.google.GoogleProject

Expand Down Expand Up @@ -28,5 +29,8 @@ case class GoogleServicesConfig(appName: String,
groupSyncWorkerCount: Int,
notificationTopic: String,
googleKeyCacheConfig: GoogleKeyCacheConfig,
resourceNamePrefix: Option[String]
resourceNamePrefix: Option[String],
adminSdkServiceAccounts: Option[NonEmptyList[ServiceAccountConfig]]
)

case class ServiceAccountConfig(json: String)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.broadinstitute.dsde.workbench.sam

import cats.data.NonEmptyList
import com.google.api.client.json.jackson2.JacksonFactory
import com.typesafe.config.ConfigException.WrongType
import com.typesafe.config._
Expand Down Expand Up @@ -95,6 +96,20 @@ package object config {

val jsonFactory = JacksonFactory.getDefaultInstance

implicit val serviceAccountConfigReader: ValueReader[ServiceAccountConfig] = ValueReader.relative { config =>
ServiceAccountConfig(config.root().render(ConfigRenderOptions.concise))
}

implicit def nonEmptyListReader[A](implicit valueReader: ValueReader[List[A]]): ValueReader[Option[NonEmptyList[A]]] = new ValueReader[Option[NonEmptyList[A]]] {
def read(config: Config, path: String): Option[NonEmptyList[A]] = {
if (config.hasPath(path)) {
NonEmptyList.fromList(valueReader.read(config, path))
} else {
None
}
}
}

implicit val googleServicesConfigReader: ValueReader[GoogleServicesConfig] = ValueReader.relative { config =>
GoogleServicesConfig(
config.getString("appName"),
Expand All @@ -117,7 +132,8 @@ package object config {
config.getInt("groupSync.workerCount"),
config.getString("notifications.topicName"),
config.as[GoogleKeyCacheConfig]("googleKeyCache"),
config.as[Option[String]]("resourceNamePrefix")
config.as[Option[String]]("resourceNamePrefix"),
config.as[Option[NonEmptyList[ServiceAccountConfig]]]("adminSdkServiceAccounts")
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.broadinstitute.dsde.workbench.sam.config

import cats.data.NonEmptyList
import org.scalatest.{FlatSpec, Matchers}
import com.typesafe.config._
import net.ceedubs.ficus.Ficus._

class NonEmptyListConfigReaderSpec extends FlatSpec with Matchers {
"NonEmptyListConfigReader" should "read missing list" in {
val c = ConfigFactory.empty()
val test = c.as[Option[NonEmptyList[String]]]("test")
test should equal(None)
}

it should "read empty list" in {
val c = ConfigFactory.parseString("test = []")
val test = c.as[Option[NonEmptyList[String]]]("test")
test should equal(None)
}

it should "read non empty list" in {
val c = ConfigFactory.parseString("test = [foo, bar]")
val test = c.as[Option[NonEmptyList[String]]]("test")
test should equal(Some(NonEmptyList.of("foo", "bar")))
}

}

0 comments on commit 8bb9bec

Please sign in to comment.