Skip to content

Commit

Permalink
Merge branch 'develop' into update/commons-io-2.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb authored Nov 13, 2024
2 parents 5bed4df + 856e709 commit 0b93153
Show file tree
Hide file tree
Showing 28 changed files with 289 additions and 152 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .git-blame-ignore-revs

# scalafmt mass change
3487e7a60194a66886572c899a6a93d7355dc376
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @broadinstitute/dsp-core-services
28 changes: 28 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check formatting for modified files with scalafmt

on:
pull_request:
paths-ignore: ['**.md']

jobs:
format:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v4
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.sha }}

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: sbt

- name: Check formatting for modified files
run: |
sbt scalafmtCheckAll
8 changes: 5 additions & 3 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
version = 2.4.2
version = 3.8.3
align = none
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses = true
danglingParentheses.preset = true
rewrite.rules = [SortImports, RedundantBraces, RedundantParens, SortModifiers]
docstrings = JavaDoc
docstrings.style = keep
project.excludeFilters = [
Dependencies.scala,
Settings.scala,
build.sbt
]
runner.dialect = scala213
project.git = true
27 changes: 16 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@ version := "0.2"

organization := "org.broadinstitute"

scalaVersion := "2.13.10"
scalaVersion := "2.13.15"

val akkaV = "2.6.18"
val akkaHttpV = "10.2.7"
val slickV = "3.3.3"
val workbenchGoogleV = "0.28-3ad3700"
val scalaTestV = "3.2.11"

val scalaTestV = "3.2.19"

val workbenchLibsHash = "9254729"
val workbenchGoogleV = s"0.32-$workbenchLibsHash"
val workbenchNotificationsV = s"0.7-$workbenchLibsHash"


resolvers ++= Seq(
"Broad Artifactory Releases" at "https://broadinstitute.jfrog.io/broadinstitute/libs-release/",
"Broad Artifactory Snapshots" at "https://broadinstitute.jfrog.io/broadinstitute/libs-snapshot/")

libraryDependencies ++= Seq(
"org.webjars" % "swagger-ui" % "4.1.3",
"org.webjars" % "swagger-ui" % "5.17.14",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5",
"com.typesafe.akka" %% "akka-http-spray-json" % "10.2.9",
"com.google.protobuf" % "protobuf-java" % "4.0.0-rc-2",
"com.google.protobuf" % "protobuf-java" % "4.29.0-RC1",
"io.sentry" % "sentry" % "6.9.2",
"io.sentry" % "sentry-logback" % "6.9.2",
"org.broadinstitute.dsde.workbench" %% "workbench-google" % workbenchGoogleV
Expand All @@ -32,7 +37,7 @@ libraryDependencies ++= Seq(
exclude("org.bouncycastle", "bcprov-ext-jdk15on")
exclude("org.bouncycastle", "bcutil-jdk15on")
exclude("org.bouncycastle", "bcpkix-jdk15on"),
"org.broadinstitute.dsde.workbench" %% "workbench-notifications" % "0.7-9254729"
"org.broadinstitute.dsde.workbench" %% "workbench-notifications" % workbenchNotificationsV
exclude("com.typesafe.akka", "akka-protobuf-v3_2.13")
exclude("com.google.protobuf", "protobuf-java"),
"com.typesafe.akka" %% "akka-http" % akkaHttpV,
Expand All @@ -46,19 +51,19 @@ libraryDependencies ++= Seq(
"commons-io" % "commons-io" % "2.17.0",
"commons-codec" % "commons-codec" % "1.15",
"mysql" % "mysql-connector-java" % "8.0.28",
"org.liquibase" % "liquibase-core" % "4.7.1",
"org.hsqldb" % "hsqldb" % "2.6.1",
"org.liquibase" % "liquibase-core" % "4.30.0",
"org.hsqldb" % "hsqldb" % "2.7.4",
"com.sendgrid" % "sendgrid-java" % "2.2.2",
"ch.qos.logback" % "logback-classic" % "1.4.14",
"ch.qos.logback" % "logback-classic" % "1.5.12",
"org.broadinstitute.dsde.workbench" %% "sam-client" % "0.1-4cde1ff",
"com.azure" % "azure-identity" % "1.12.2",
"com.azure" % "azure-core-management" % "1.15.0",
"com.azure" % "azure-core-management" % "1.15.5",
//---------- Test libraries -------------------//
"org.broadinstitute.dsde.workbench" %% "workbench-google" % workbenchGoogleV % Test classifier "tests",
"com.typesafe.akka" %% "akka-testkit" % akkaV % Test,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpV % Test,
"org.scalatest" %% "scalatest" % scalaTestV % Test,
"org.mockito" %% "mockito-scala-scalatest" % "1.17.12" % Test,
"org.mockito" %% "mockito-scala-scalatest" % "1.17.37" % Test,
"org.yaml" % "snakeyaml" % "1.33" % Test
)

Expand Down
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fi
function make_jar()
{
echo "building thurloe jar..."
docker run --rm -v $PWD:/working -v jar-cache:/root/.ivy -v jar-cache:/root/.ivy2 sbtscala/scala-sbt:openjdk-17.0.2_1.7.2_2.13.10 /working/docker/install.sh /working
docker run --rm -v $PWD:/working -v jar-cache:/root/.ivy -v jar-cache:/root/.ivy2 sbtscala/scala-sbt:eclipse-temurin-17.0.13_11_1.10.5_2.13.15 /working/docker/install.sh /working
}

function docker_cmd()
Expand Down
2 changes: 1 addition & 1 deletion docker/build_jar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo "building thurloe jar..."

docker run --rm -v $PWD:/working \
-v jar-cache:/root/.ivy \
-v jar-cache:/root/.ivy2 sbtscala/scala-sbt:openjdk-17.0.2_1.7.2_2.13.10 /working/docker/install.sh /working
-v jar-cache:/root/.ivy2 sbtscala/scala-sbt:eclipse-temurin-17.0.13_11_1.10.5_2.13.15 /working/docker/install.sh /working


EXIT_CODE=$?
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.2
sbt.version=1.10.5
12 changes: 6 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.5")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin(
"com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16"
"com.github.cb372" % "sbt-explicit-dependencies" % "0.3.1"
) // Use `unusedCompileDependencies` to see unused dependencies

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")

addDependencyTreePlugin
addDependencyTreePlugin
4 changes: 4 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ akka.http {
}
}

auth {
googleClientId = ""
}

swagger {
docsPath = "swagger/thurloe.yaml"
uiVersion = "2.1.1"
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/thurloe/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ object Main extends App {
val routes = new ThurloeServiceActor(samDao)

for {
binding <- Http().newServerAt("0.0.0.0", 8000).bind(routes.route).recover {
case t: Throwable =>
system.log.error("FATAL - failure starting http server", t)
throw t
binding <- Http().newServerAt("0.0.0.0", 8000).bind(routes.route).recover { case t: Throwable =>
system.log.error("FATAL - failure starting http server", t)
throw t
}
_ = system.log.info("Thurloe now available for all your key/value pair and notification needs.")
_ <- binding.whenTerminated
Expand All @@ -56,7 +55,8 @@ object Main extends App {

val pem =
GoogleCredentialModes.Pem(WorkbenchEmail(gcsConfig.getString("clientEmail")),
new File(gcsConfig.getString("pathToPem")))
new File(gcsConfig.getString("pathToPem"))
)
val pubSubDAO = new HttpGooglePubSubDAO(
gcsConfig.getString("appName"),
pem,
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/thurloe/crypto/Encryption.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ case object Aes256Cbc {
}

final def decrypt(encryptedBytes: EncryptedBytes, secretKey: SecretKey): Try[Array[Byte]] =
validateLength("Secret key", secretKey.key, keySize) validateAnotherLength ("Initialization vector", encryptedBytes.iv, blockSize) map {
_ =>
val cipher = init(Cipher.DECRYPT_MODE, secretKey.key, encryptedBytes.iv)
cipher.doFinal(encryptedBytes.cipherText)
validateLength("Secret key", secretKey.key, keySize) validateAnotherLength ("Initialization vector",
encryptedBytes.iv,
blockSize
) map { _ =>
val cipher = init(Cipher.DECRYPT_MODE, secretKey.key, encryptedBytes.iv)
cipher.doFinal(encryptedBytes.cipherText)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/thurloe/dataaccess/HttpSamDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class HttpSamDAO(config: Config, cloudServiceAuthTokenProvider: CloudServiceAuth
protected def adminApi(samApiClient: ApiClient) = new AdminApi(samApiClient)

override def getUserById(userId: String): List[sam.model.User] =
try {
try
adminApi(getApiClient).adminGetUsersByQuery(userId, userId, userId, 5).asScala.toList
} catch {
catch {
case e: Exception =>
logger.warn(s"Sam user not found: $userId", e)
List.empty
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/thurloe/dataaccess/HttpSendGridDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HttpSendGridDAO(samDao: SamDAO) extends SendGridDAO with LazyLogging {
}
}

//Looks up a KVP, converting empty values or missing KVPs into None
// Looks up a KVP, converting empty values or missing KVPs into None
private def lookupNonEmptyKeyValuePair(userId: String, key: String) =
dataAccess
.lookup(samDao, userId, key)
Expand All @@ -42,7 +42,7 @@ class HttpSendGridDAO(samDao: SamDAO) extends SendGridDAO with LazyLogging {
}
.recover(_ => None)

//There are two cases that need to be handled when looking up the preferred contact email:
// There are two cases that need to be handled when looking up the preferred contact email:
// 1) If the contactEmail is not present at all, the DB query will throw an exception. So that needs to be handled.
// 2) If the contactEmail is present but blank, it also needs to be ignored. Thurloe accepts arbitrary key/value pairs
// and makes no guarantees about what the data might look like, so a blank value or invalid email is a valid case.
Expand All @@ -54,12 +54,13 @@ class HttpSendGridDAO(samDao: SamDAO) extends SendGridDAO with LazyLogging {
// how profiles are populated.
def lookupPreferredEmail(userId: WorkbenchUserId): Future[WorkbenchEmail] =
lookupNonEmptyKeyValuePair(userId.value, "contactEmail") flatMap {
case Some(kvp) => Future.successful(WorkbenchEmail(kvp.keyValuePair.value)) //contactEmail was found and non-empty
case Some(kvp) =>
Future.successful(WorkbenchEmail(kvp.keyValuePair.value)) // contactEmail was found and non-empty
case None =>
logger.info(s"Failed to get stored contactEmail for ${userId.value}. Defaulting to account email for user.")
lookupNonEmptyKeyValuePair(userId.value, "email") flatMap {
case Some(kvp) =>
Future.successful(WorkbenchEmail(kvp.keyValuePair.value)) //account email was found and non-empty
Future.successful(WorkbenchEmail(kvp.keyValuePair.value)) // account email was found and non-empty
case None => Future.failed(new KeyNotFoundException(userId.value, "email"))
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/thurloe/dataaccess/SendGridDAO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ trait SendGridDAO {
new NotificationException(StatusCodes.BadRequest,
"No recipient specified",
Seq.empty,
notification.notificationId)
notification.notificationId
)
)
)
)
Expand All @@ -45,12 +46,12 @@ trait SendGridDAO {
Future.traverse(_)(lookupPreferredEmail).map(replyToEmails => Option(replyToEmails))
} getOrElse Future.successful(None)

val emailSubstitutionsFuture = Future.traverse(notification.emailLookupSubstitutions.toList) {
case (key, id) => lookupPreferredEmail(id).map(email => key -> email.value)
val emailSubstitutionsFuture = Future.traverse(notification.emailLookupSubstitutions.toList) { case (key, id) =>
lookupPreferredEmail(id).map(email => key -> email.value)
}

val nameSubstitutionsFuture = Future.traverse(notification.nameLookupSubstitution.toList) {
case (key, id) => lookupUserName(id).map(name => key -> name)
val nameSubstitutionsFuture = Future.traverse(notification.nameLookupSubstitution.toList) { case (key, id) =>
lookupUserName(id).map(name => key -> name)
}

val recipientFirstNameSubstitutionFuture = notification.userId match {
Expand Down Expand Up @@ -82,7 +83,8 @@ trait SendGridDAO {
def createEmail(toAddress: WorkbenchEmail,
replyTos: Option[Set[WorkbenchEmail]],
notificationId: String,
substitutions: Map[String, String] = Map.empty): SendGrid.Email = {
substitutions: Map[String, String] = Map.empty
): SendGrid.Email = {
val email = new SendGrid.Email()

email.addTo(toAddress.value)
Expand Down Expand Up @@ -115,8 +117,8 @@ trait SendGridDAO {
case class NotificationException(statusCode: StatusCode,
message: String,
recipients: Seq[String],
notificationId: String)
extends Exception {
notificationId: String
) extends Exception {
override def getMessage =
s"Error message: [${message}], recipients: [${recipients.mkString(",")}], notificationId: [${notificationId}]"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ object CloudServiceAuthTokenProvider {
val gcsConfig = config.getConfig("gcs")
val pem =
GoogleCredentialModes.Pem(WorkbenchEmail(gcsConfig.getString("clientEmail")),
new File(gcsConfig.getString("pathToPem")))
new File(gcsConfig.getString("pathToPem"))
)

new GcpAuthTokenProvider(pem)
}
Expand Down
Loading

0 comments on commit 0b93153

Please sign in to comment.