Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BT-710 Add configs for BlobPathBuilderFactory #6817

Merged
merged 11 commits into from
Aug 4, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import com.typesafe.config.Config
import cromwell.core.WorkflowOptions
import cromwell.core.path.PathBuilderFactory
import cromwell.filesystems.blob.BlobPathBuilder
import net.ceedubs.ficus.Ficus._

import scala.concurrent.ExecutionContext
import scala.concurrent.Future

final case class BlobPathBuilderFactory(globalConfig: Config, instanceConfig: Config) extends PathBuilderFactory {
final case class BlobFileSystemConfig(config: Config)
final case class BlobPathBuilderFactory(globalConfig: Config, instanceConfig: Config, singletonConfig: BlobFileSystemConfig) extends PathBuilderFactory {
val sasToken: String = instanceConfig.as[String]("sas-token")
val container: String = instanceConfig.as[String]("store")
val endpoint: String = instanceConfig.as[String]("endpoint")
val workspaceId: String = instanceConfig.as[String]("workspace-id")
val workspaceManagerURL = singletonConfig.config.as[String]("workspace-manager-url")

override def withOptions(options: WorkflowOptions)(implicit as: ActorSystem, ec: ExecutionContext): Future[BlobPathBuilder] = {
val sasToken: String = instanceConfig.getString("sasToken")
val container: String = instanceConfig.getString("store")
val endpoint: String = instanceConfig.getString("endpoint")
Future {
new BlobPathBuilder(new AzureSasCredential(sasToken), container, endpoint)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cromwell.filesystems.blob

import com.typesafe.config.ConfigFactory
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

class BlobPathBuilderFactorySpec extends AnyFlatSpec with Matchers {

it should "parse configs for a functioning factory" in {
val endpoint = BlobPathBuilderSpec.buildEndpoint("coaexternalstorage")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not check in this storage account name.

It might be worth taking another look at this test as part of our conversations about overall testing strategy, but I think it's fine to merge for now.

val store = "inputs"
val sasToken = "{SAS TOKEN HERE}"
val workspaceId = "mockWorkspaceId"
val workspaceManagerURL = "https://test.ws.org"
val instanceConfig = ConfigFactory.parseString(
s"""
|sas-token = "$sasToken"
|store = "$store"
|endpoint = "$endpoint"
|workspace-id = "$workspaceId"
""".stripMargin)
val singletonConfig = ConfigFactory.parseString(s"""workspace-manager-url = "$workspaceManagerURL" """)
val globalConfig = ConfigFactory.parseString("""""")
val factory = BlobPathBuilderFactory(globalConfig, instanceConfig, new BlobFileSystemConfig(singletonConfig))
factory.container should equal(store)
factory.endpoint should equal(endpoint)
factory.sasToken should equal(sasToken)
factory.workspaceId should equal(workspaceId)
factory.workspaceManagerURL should equal(workspaceManagerURL)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class BlobPathBuilderSpec extends AnyFlatSpec with Matchers{
}

ignore should "build a blob path from a test string and read a file" in {
val endpoint = BlobPathBuilderSpec.buildEndpoint("coaexternalstorage")
val endpoint = BlobPathBuilderSpec.buildEndpoint("teststorageaccount")
val endpointHost = BlobPathBuilder.parseURI(endpoint).getHost
val store = "inputs"
val evalPath = "/test/inputFile.txt"
val store = "testContainer"
val evalPath = "/test/file.txt"
val sas = "{SAS TOKEN HERE}"
val testString = endpoint + "/" + store + evalPath
val blobPath: BlobPath = new BlobPathBuilder(new AzureSasCredential(sas), store, endpoint) build testString getOrElse fail()
Expand Down