Created
May 25, 2020 08:50
-
-
Save JamesDLD/70be3cc584fb762e1c4eebdabf3f1fc5 to your computer and use it in GitHub Desktop.
Add a Databricks Service Principal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the Service Principal dbx-datascientist-spn1 | |
$datascientist_spn = Get-AzADServicePrincipal -DisplayName "dbx-datascientist-spn1" | |
# Get Databricks groups | |
$headers = @{ | |
"Authorization"="Bearer $apiKey"; | |
"Content-Type" = "application/scim+json"; | |
} | |
$uri = "$uriroot/2.0/preview/scim/v2/Groups" | |
$Groups = Invoke-RestMethod -Method 'Get' -Uri $uri -Headers $headers | |
Write-Output "Displaying the Databricks Groups available" | |
$Groups.Resources | |
# Add a Service Principal into Databricks | |
$datascientist_gpid = ($Groups.Resources | Where-Object {$_.displayName -eq "datascientist"}).id | |
$params = @{ | |
"schemas"=@("urn:ietf:params:scim:schemas:core:2.0:ServicePrincipal"); | |
"applicationId"="$($datascientist_spn.ApplicationId.Guid)"; | |
"displayName"="$($datascientist_spn.displayName)" | |
} | |
$groups = New-Object System.Collections.ArrayList | |
$groups.Add(@{"value"=$datascientist_gpid;}) | |
$entitlements = New-Object System.Collections.ArrayList | |
$entitlements.Add(@{"value"="allow-cluster-create";}) | |
$params.Add("groups",$groups) | |
$params.Add("entitlements",$entitlements) | |
$headers = @{ | |
"Authorization"="Bearer $apiKey"; | |
"Content-Type" = "application/scim+json"; | |
} | |
$uri = "$uriroot/2.0/preview/scim/v2/ServicePrincipals" | |
Invoke-RestMethod -Method 'POST' -Uri $uri -Headers $headers -Body ( $params | ConvertTo-Json ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment