Skip to content

Commit

Permalink
add regex for onelake + test
Browse files Browse the repository at this point in the history
  • Loading branch information
pj-spoelders committed May 8, 2024
1 parent 41cc2ff commit 6eb754b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ final case class AzureAbfsBucket(path: String, params: StorageProperties) extend

// Intentionally copy-paste, duplicate count: 2. Please, refactor when
// it reaches 3+.
// Fabric / OneLake: .dfs.fabric.microsoft.com
private[this] final val AZURE_ABFS_PATH_REGEX: Regex =
"""abfss?://(.*)@([^.]+).dfs.core.windows.net/(.*)$""".r
private[this] final val AZURE_ABFS_ONELAKE_PATH_REGEX: Regex =
"""abfss?://(.*)@([^.]+)\.dfs\.fabric\.microsoft\.com/(.*)$""".r

private[this] def regexParsePath(path: String): AccountAndContainer = path match {
case AZURE_ABFS_PATH_REGEX(containerName, accountName, _) =>
AccountAndContainer(accountName, containerName)
case AZURE_ABFS_ONELAKE_PATH_REGEX(containerName, accountName, _) =>
AccountAndContainer(accountName, containerName)
case _ =>
throw new BucketValidationException(
ExaError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ class AzureAbfsBucketTest extends AbstractBucketTest {
assert(thrown.getMessage().startsWith("E-CSE-20"))
assert(thrown.getMessage().contains(s"path '$path' scheme is not valid."))
}
// https://github.com/MicrosoftDocs/fabric-docs/blob/main/docs/onelake/onelake-access-api.md
// "abfss://[email protected]/data/"
// The account name is always onelake
// The container name is your workspace name.
//
// From the docs
// -> abfs[s]://<workspace>@onelake.dfs.fabric.microsoft.com/<item>.<itemtype>/<path>/<fileName>
test("apply throws if Azure OneLake path does not return valid Bucket") {
val path = "abfss://[email protected]/item.itemtype/path/filename"
val exaMetadata = mockConnectionInfo("", "AZURE_SECRET_KEY=secret")
properties = defaultProperties ++ Map(PATH -> path, "CONNECTION_NAME" -> "connection_info")

val bucket = getBucket(properties, exaMetadata)
assert(bucket.isInstanceOf[AzureAbfsBucket])
}

test("apply throws if no connection name is provided") {
properties = defaultProperties
Expand Down

0 comments on commit 6eb754b

Please sign in to comment.