Skip to content

Commit

Permalink
support for endpoint URL for local testing akka#3253
Browse files Browse the repository at this point in the history
  • Loading branch information
sfali committed Aug 25, 2024
1 parent 44c2f84 commit 93c2aab
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions azure-storage/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -104,24 +118,33 @@ 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,
algorithm: String
): StorageSettings =
StorageSettings(apiVersion,
authorizationType,
Option(endPointUrl.orElse(null)),
azureNameKeyCredential,
Option(sasToken.orElse(null)),
retrySettings,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit 93c2aab

Please sign in to comment.