Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added post deployment step to create SAS with additional permission #11509

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion sdk/storage/test-resources-post.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,51 @@ Write-Verbose "CORS rule set for $storageAccountName"
$datalakeStorageAccountName = $DeploymentOutputs['DFS_ACCOUNT_NAME']
$context = New-AzStorageContext -StorageAccountName $datalakeStorageAccountName
Set-AzStorageCORSRule -ServiceType 'Blob' -CorsRules $corsRules -Context $context
Write-Verbose "CORS rule set for $datalakeStorageAccountName"
Write-Verbose "CORS rule set for $datalakeStorageAccountName"

# Run any post deployment script and set any additional keys to set in Env
$AdditionalEnvKeys = @{}

# Create SAS for storage account with additional permissions that are not supported by SRP deployment
$storageAccount = $DeploymentOutputs['ACCOUNT_NAME']
Write-Host "Creating SAS for storage account $storageAccount"
$storageContext = New-AzStorageContext -StorageAccountName $storageAccount -StorageAccountKey $DeploymentOutputs['ACCOUNT_KEY']
$storageSas = New-AzStorageAccountSASToken -ResourceType Service, Container, Object -Service Blob, File, Queue, Table -Permission "rwdxftlacup" -Context $storageContext
$AdditionalEnvKeys["ACCOUNT_SAS"] = $storageSas

$datalakeStorageAccount = $DeploymentOutputs['DFS_ACCOUNT_NAME']
Write-Host "Creating SAS for datalake storage account $datalakeStorageAccount"
$storageContext = New-AzStorageContext -StorageAccountName $datalakeStorageAccount -StorageAccountKey $DeploymentOutputs['DFS_ACCOUNT_KEY']
$storageSas = New-AzStorageAccountSASToken -ResourceType Service, Container, Object -Service Blob, File, Queue, Table -Permission "rwdxftlacup" -Context $storageContext
$AdditionalEnvKeys["DFS_ACCOUNT_SAS"] = $storageSas


# Try to detect the shell based on the parent process name (e.g. launch via shebang).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we talked I'm Ok with this approach for now but I do think it is worth filing an issue in the tools repo about adding support for such scenarios because I'd hate to see this code duplicated a lot of times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File issue Azure/azure-sdk-tools#1044 to track and add support in common place rather than in individual service script.

$shell, $shellExportFormat = if (($parentProcessName = (Get-Process -Id $PID).Parent.ProcessName) -and $parentProcessName -eq 'cmd') {
'cmd', 'set {0}={1}'
}
elseif (@('bash', 'csh', 'tcsh', 'zsh') -contains $parentProcessName) {
'shell', 'export {0}={1}'
}
else {
'PowerShell', '$env:{0} = ''{1}'''
}

$CI = ($null -ne $env:SYSTEM_TEAMPROJECTID)

# Set additional keys as ENV variables
foreach ($key in $AdditionalEnvKeys.Keys) {
$value = $AdditionalEnvKeys[$key]
$environmentVariables[$key] = $value

if ($CI) {
# Treat all ARM template output variables as secrets since "SecureString" variables do not set values.
# In order to mask secrets but set environment variables for any given ARM template, we set variables twice as shown below.
Write-Host "Setting variable '$key': ***"
Write-Host "##vso[task.setvariable variable=_$key;issecret=true;]$($value)"
Write-Host "##vso[task.setvariable variable=$key;]$($value)"
}
else {
Write-Host ($shellExportFormat -f $key, $value)
}
}