src/Public/permissions.ps1

function Set-RedkitePermissions {
    <#
    .Description
    Takes the contents of a json permissions files and applies the permissions
    #>

    [CmdletBinding()]
    param([PSCustomObject[]]$Permissions)

    foreach ($Permission in $Permissions) {
        Write-Host "applyPermissionSet: $($Permission | ConvertTo-Json)"
        switch ($Permission.type) {
            "rbac" { applyRbacPermission $Permission }
            # "sql" { applySQLPermission $Permission}
            "datalake" { Set-RedkiteDataLakeAcl $Permission}
            Default { throw "Unknown Type - $($Permission.type)" }
        }
        Write-Host "applyPermissionSet: $($Permission | ConvertTo-Json)...done"
    }
    UpdateLakeFromCache
}

function Set-RedkiteDataLakeAcl{
    <#
    .Description
    Set the permission on a Data Folder and parent folders (to reach the folder)
    #>

    [CmdletBinding()]
    param([PSCustomObject[]]$Permission)
    
    $DataLakeName = $Permission.dataLakeName
    $ContainerName = $Permission.containerName

    $ctx = getStorageContext -StorageAccountName $DataLakeName -ContainerName $ContainerName
    Write-Verbose "applyLakePermission: objectType: '$($Permission.principalType)', DisplayName: '$($Permission.principalName)', Permission: '$($Permission.permission)', path: '$($Permission.path)'"
    Apply-LakePathAcl -ctx $ctx -ContainerName $ContainerName -ObjectType $Permission.principalType -DisplayName $Permission.principalName -Permissions $Permission.permission -Path $Permission.path
}