Functions/Publish-DatabricksFilesToWorkspaceByName.ps1

<#
.SYNOPSIS
Deploys DataBricks Files from configuration json file to a workspace
 
.DESCRIPTION
Deploys DataBricks Files from configuration json file to a workspace
 
.PARAMETER config
Configuration json file from the environment used to workout whether to deploy a clusters from a folder or file(s)
 
.PARAMETER bearerToken
Your Databricks Bearer token to authenticate to your workspace (see User Settings in Datatbricks WebUI)
 
.EXAMPLE
Publish-DatabricksFilesToWorkspaceByName -config $config -bearerToken 'dapi1234567890' -localInputPath '</path/to/file>'
 
.NOTES
Author: Sabin IO
 
#>
 
Function Publish-DatabricksFilesToWorkspaceByName {
    [cmdletbinding()]
    Param(
        [parameter(Mandatory = $true)]$config,
        [parameter(Mandatory = $true)][string]$bearerToken,
        [parameter(Mandatory = $true)][string]$localInputPath
    )
    try {
                    
        if ($config.dbfsFiles) {
            Write-Output "dbfsFiles config key supplied"
            if ($config.dbfsFiles.Length -ge 1) {               
                # Check if clusters exist in the first place
                foreach ($file in $config.dbfsFiles) {
                    Add-DatabricksDBFSFile -BearerToken $bearerToken `
                        -Region $config.region `
                        -LocalRootFolder $localInputPath `
                        -FilePattern $file.filePattern `
                        -TargetLocation $file.targetLocation
                } 
            } 
        }
        else {
            Write-Warning "dbfsFiles config key not supplied, but the switch has been supplied to the pipeline."
        }
    }    
    catch {
        #uh oh
        throw $_.Exception
    }
}