Skip to content

Commit

Permalink
:whiteList to whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
asingh7115 committed Oct 24, 2017
1 parent 4b30b77 commit 9029d5a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object Boot extends App with LazyLogging {
val proxyConfig = config.as[ProxyConfig]("proxy")
val clusterResourcesConfig = config.as[ClusterResourcesConfig]("clusterResources")
val monitorConfig = config.as[MonitorConfig]("monitor")
val whiteListConfig = config.as[(Set[String])]("whiteList").map(WorkbenchUserEmail(_))
val whitelistConfig = config.as[(Set[String])]("whitelist").map(WorkbenchUserEmail(_))

// we need an ActorSystem to host our application in
implicit val system = ActorSystem("leonardo")
Expand All @@ -58,7 +58,7 @@ object Boot extends App with LazyLogging {
val leonardoService = new LeonardoService(dataprocConfig, clusterResourcesConfig, proxyConfig, gdDAO, dbRef, clusterMonitorSupervisor)
val clusterDnsCache = system.actorOf(ClusterDnsCache.props(proxyConfig, dbRef))
val proxyService = new ProxyService(proxyConfig, gdDAO, dbRef, clusterDnsCache)
val leoRoutes = new LeoRoutes(leonardoService, proxyService, config.as[SwaggerConfig]("swagger"), whiteListConfig) with StandardUserInfoDirectives
val leoRoutes = new LeoRoutes(leonardoService, proxyService, config.as[SwaggerConfig]("swagger"), whitelistConfig) with StandardUserInfoDirectives

startClusterMonitors(dbRef, clusterMonitorSupervisor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.broadinstitute.dsde.workbench.model.{ErrorReport, WorkbenchExceptionW

import scala.concurrent.{ExecutionContext, Future}

abstract class LeoRoutes(val leonardoService: LeonardoService, val proxyService: ProxyService, val swaggerConfig: SwaggerConfig, val whiteListConfig: Set[WorkbenchUserEmail])(implicit val system: ActorSystem, val materializer: Materializer, val executionContext: ExecutionContext) extends LazyLogging with ProxyRoutes with SwaggerRoutes with UserInfoDirectives {
abstract class LeoRoutes(val leonardoService: LeonardoService, val proxyService: ProxyService, val swaggerConfig: SwaggerConfig, val whitelistConfig: Set[WorkbenchUserEmail])(implicit val system: ActorSystem, val materializer: Materializer, val executionContext: ExecutionContext) extends LazyLogging with ProxyRoutes with SwaggerRoutes with UserInfoDirectives {

def unauthedRoutes: Route =
path("ping") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import scala.concurrent.ExecutionContext
*/
trait ProxyRoutes extends UserInfoDirectives{ self: LazyLogging =>
val proxyService: ProxyService
val whiteListConfig: Set[WorkbenchUserEmail]
val whitelistConfig: Set[WorkbenchUserEmail]
implicit val executionContext: ExecutionContext

protected val tokenCookieName = "FCToken"
Expand All @@ -25,7 +25,7 @@ trait ProxyRoutes extends UserInfoDirectives{ self: LazyLogging =>
cookie(tokenCookieName) { tokenCookie => // rejected with MissingCookieRejection if the cookie is not present
complete {
proxyService.getCachedEmailFromToken(tokenCookie.value).flatMap { email =>
if (whiteListConfig.contains(email)) {
if (whitelistConfig.contains(email)) {
// Proxy logic handled by the ProxyService class
proxyService.proxy(GoogleProject(googleProject), ClusterName(clusterName), request, tokenCookie)
} else throw AuthorizationError(email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ case class AuthorizationError(email: WorkbenchUserEmail) extends LeoException(s"

trait UserInfoDirectives {
def requireUserInfo: Directive1[UserInfo]
def whiteListConfig: Set[WorkbenchUserEmail]
def whitelistConfig: Set[WorkbenchUserEmail]

def checkWhiteList(userEmail: WorkbenchUserEmail): Directive0 = {
Directives.mapInnerRoute { r =>
if (!whiteListConfig.contains(userEmail)) throw AuthorizationError(userEmail)
if (!whitelistConfig.contains(userEmail)) throw AuthorizationError(userEmail)
else r
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,15 @@ class GoogleDataprocDAO(protected val dataprocConfig: DataprocConfig, protected
Future {
blocking(executeGoogleRequest(request))
} recover {
case e: GoogleJsonResponseException =>
logger.error(s"Error occurred executing Google request for ${googleProject.string} / $context", e)
throw CallToGoogleApiFailedException(googleProject, context, e.getStatusCode, e.getDetails.getMessage)
case illegalArgumentException: IllegalArgumentException =>
logger.error(s"Illegal argument passed to Google request for ${googleProject.string} / $context", illegalArgumentException)
throw CallToGoogleApiFailedException(googleProject, context, StatusCodes.BadRequest.intValue, illegalArgumentException.getMessage)
case e: Exception if e.getCause.isInstanceOf[GoogleJsonResponseException] =>
val googleEx = e.getCause.asInstanceOf[GoogleJsonResponseException]
throw CallToGoogleApiFailedException(googleProject, context, googleEx.getStatusCode, googleEx.getDetails.getMessage)
// case e: GoogleJsonResponseException =>
// logger.error(s"Error occurred executing Google request for ${googleProject.string} / $context", e)
// throw CallToGoogleApiFailedException(googleProject, context, e.getStatusCode, e.getDetails.getMessage)
// case illegalArgumentException: IllegalArgumentException =>
// logger.error(s"Illegal argument passed to Google request for ${googleProject.string} / $context", illegalArgumentException)
// throw CallToGoogleApiFailedException(googleProject, context, StatusCodes.BadRequest.intValue, illegalArgumentException.getMessage)
}
}
}
2 changes: 1 addition & 1 deletion src/test/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ akka.ssl-config {
}
}

whiteList = ["user1@example.com"]
whitelist = ["user1@example.com"]

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LeoRoutesSpec extends FlatSpec with Matchers with ScalatestRouteTest with
}

it should "401 when using a non-white-listed user" in isolatedDbTest {
val invalidUserLeoRoutes = new LeoRoutes(leonardoService, proxyService, swaggerConfig, whiteListConfig) with MockUserInfoDirectives {
val invalidUserLeoRoutes = new LeoRoutes(leonardoService, proxyService, swaggerConfig, whitelistConfig) with MockUserInfoDirectives {
override val userInfo: UserInfo = UserInfo(OAuth2BearerToken("accessToken"), WorkbenchUserId("badUser"), WorkbenchUserEmail("badUser@example.com"), 0)
}
Get("/api/clusters") ~> invalidUserLeoRoutes.route ~> check {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ trait TestLeoRoutes { this: ScalatestRouteTest =>
val dataprocConfig = config.as[DataprocConfig]("dataproc")
val proxyConfig = config.as[ProxyConfig]("proxy")
val clusterResourcesConfig = config.as[ClusterResourcesConfig]("clusterResources")
val whiteListConfig = config.as[(Set[String])]("whiteList").map(WorkbenchUserEmail(_))
val whitelistConfig = config.as[(Set[String])]("whitelist").map(WorkbenchUserEmail(_))
val mockGoogleDataprocDAO = new MockGoogleDataprocDAO(dataprocConfig, proxyConfig)
// Route tests don't currently do cluster monitoring, so use NoopActor
val clusterMonitorSupervisor = system.actorOf(NoopActor.props)
val leonardoService = new LeonardoService(dataprocConfig, clusterResourcesConfig, proxyConfig, mockGoogleDataprocDAO, DbSingleton.ref, clusterMonitorSupervisor)
val proxyService = new MockProxyService(proxyConfig, mockGoogleDataprocDAO, DbSingleton.ref)
val swaggerConfig = SwaggerConfig("", "")
val defaultUserInfo = UserInfo(OAuth2BearerToken("accessToken"), WorkbenchUserId("user1"), WorkbenchUserEmail("user1@example.com"), 0)
val leoRoutes = new LeoRoutes(leonardoService, proxyService, swaggerConfig, whiteListConfig) with MockUserInfoDirectives {
val leoRoutes = new LeoRoutes(leonardoService, proxyService, swaggerConfig, whitelistConfig) with MockUserInfoDirectives {
override val userInfo: UserInfo = defaultUserInfo
}
}

0 comments on commit 9029d5a

Please sign in to comment.