From 93c2aab79c7f1e1595fd3ea932297fcc65bb4d6f Mon Sep 17 00:00:00 2001 From: sfali Date: Sun, 25 Aug 2024 13:14:19 -0400 Subject: [PATCH] support for endpoint URL for local testing #3253 --- .../src/main/resources/reference.conf | 3 ++ .../alpakka/azure/storage/settings.scala | 30 +++++++++++++++++-- .../azure/storage/StorageSettingsSpec.scala | 6 ++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/azure-storage/src/main/resources/reference.conf b/azure-storage/src/main/resources/reference.conf index f80b13f535..fd4555bb70 100644 --- a/azure-storage/src/main/resources/reference.conf +++ b/azure-storage/src/main/resources/reference.conf @@ -4,6 +4,9 @@ alpakka { api-version = ${?AZURE_STORAGE_API_VERSION} signing-algorithm = "HmacSHA256" + # for local testing via emulator + # endpoint-url = "" + credentials { # valid values are anon (annonymous), SharedKey, SharedKeyLite, sas authorization-type = anon diff --git a/azure-storage/src/main/scala/akka/stream/alpakka/azure/storage/settings.scala b/azure-storage/src/main/scala/akka/stream/alpakka/azure/storage/settings.scala index 3dec2b33de..686ece1e6c 100644 --- a/azure-storage/src/main/scala/akka/stream/alpakka/azure/storage/settings.scala +++ b/azure-storage/src/main/scala/akka/stream/alpakka/azure/storage/settings.scala @@ -18,6 +18,7 @@ import scala.util.Try final class StorageSettings(val apiVersion: String, val authorizationType: String, + val endPointUrl: Option[String], val azureNameKeyCredential: AzureNameKeyCredential, val sasToken: Option[String], val retrySettings: RetrySettings, @@ -29,6 +30,9 @@ final class StorageSettings(val apiVersion: String, /** Java API */ def getAuthorizationType: String = authorizationType + /** Java API */ + def getEndPointUrl: Optional[String] = endPointUrl.toJava + /** Java API */ def getAzureNameKeyCredential: AzureNameKeyCredential = azureNameKeyCredential @@ -47,12 +51,15 @@ final class StorageSettings(val apiVersion: String, /** Java API */ def withAuthorizationType(authorizationType: String): StorageSettings = copy(authorizationType = authorizationType) + /** Java API */ + def withSasToken(sasToken: String): StorageSettings = copy(sasToken = emptyStringToOption(sasToken)) + /** Java API */ def withAzureNameKeyCredential(azureNameKeyCredential: AzureNameKeyCredential): StorageSettings = copy(azureNameKeyCredential = azureNameKeyCredential) /** Java API */ - def withSasToken(sasToken: String): StorageSettings = copy(sasToken = emptyStringToOption(sasToken)) + def withEndPointUrl(endPointUrl: String): StorageSettings = copy(endPointUrl = emptyStringToOption(endPointUrl)) /** Java API */ def withRetrySettings(retrySettings: RetrySettings): StorageSettings = copy(retrySettings = retrySettings) @@ -88,12 +95,19 @@ final class StorageSettings(val apiVersion: String, private def copy( apiVersion: String = apiVersion, authorizationType: String = authorizationType, + endPointUrl: Option[String] = endPointUrl, azureNameKeyCredential: AzureNameKeyCredential = azureNameKeyCredential, sasToken: Option[String] = sasToken, retrySettings: RetrySettings = retrySettings, algorithm: String = algorithm ) = - StorageSettings(apiVersion, authorizationType, azureNameKeyCredential, sasToken, retrySettings, algorithm) + StorageSettings(apiVersion, + authorizationType, + endPointUrl, + azureNameKeyCredential, + sasToken, + retrySettings, + algorithm) } object StorageSettings { @@ -104,17 +118,25 @@ object StorageSettings { def apply( apiVersion: String, authorizationType: String, + endPointUrl: Option[String], azureNameKeyCredential: AzureNameKeyCredential, sasToken: Option[String], retrySettings: RetrySettings, algorithm: String ): StorageSettings = - new StorageSettings(apiVersion, authorizationType, azureNameKeyCredential, sasToken, retrySettings, algorithm) + new StorageSettings(apiVersion, + authorizationType, + endPointUrl, + azureNameKeyCredential, + sasToken, + retrySettings, + algorithm) /** Java API */ def create( apiVersion: String, authorizationType: String, + endPointUrl: Optional[String], azureNameKeyCredential: AzureNameKeyCredential, sasToken: Optional[String], retrySettings: RetrySettings, @@ -122,6 +144,7 @@ object StorageSettings { ): StorageSettings = StorageSettings(apiVersion, authorizationType, + Option(endPointUrl.orElse(null)), azureNameKeyCredential, Option(sasToken.orElse(null)), retrySettings, @@ -145,6 +168,7 @@ object StorageSettings { StorageSettings( apiVersion = apiVersion, authorizationType = authorizationType, + endPointUrl = config.getOptionalString("endpoint-url"), azureNameKeyCredential = AzureNameKeyCredential(credentials), sasToken = credentials.getOptionalString("sas-token"), retrySettings = retrySettings, diff --git a/azure-storage/src/test/scala/akka/stream/alpakka/azure/storage/StorageSettingsSpec.scala b/azure-storage/src/test/scala/akka/stream/alpakka/azure/storage/StorageSettingsSpec.scala index 831d14a959..f8a4a978ac 100644 --- a/azure-storage/src/test/scala/akka/stream/alpakka/azure/storage/StorageSettingsSpec.scala +++ b/azure-storage/src/test/scala/akka/stream/alpakka/azure/storage/StorageSettingsSpec.scala @@ -124,5 +124,11 @@ class StorageSettingsSpec extends AnyWordSpec with Matchers { val settings = mkSettings("retry-settings.min-backoff=hello") settings.retrySettings shouldBe RetrySettings.Default } + + "populate endpoint URL if provided" in { + val settings = mkSettings("""endpoint-url="http://localhost:1234" """) + settings.endPointUrl shouldBe defined + settings.endPointUrl.get shouldBe "http://localhost:1234" + } } }