Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Created August 30, 2018 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/b10f171a3808a7ef4cd1743a83fddaa8 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/b10f171a3808a7ef4cd1743a83fddaa8 to your computer and use it in GitHub Desktop.
$token = '<replace>'
$roles = @("role1", "role2")
$headers = @{
"Authorization" = "Bearer $token"
"Content-type" = "application/json"
}
function UpdateSingleRolePermission ($roleName, $environmentId, $permission) {
$setting = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/environments/$environmentId/settings" -Headers $headers -Method Get
$rights = (($setting.environment.securityDescriptor.roleAces | ? {$_.name -eq $roleName}).accessRights | ? {$_.name -eq $permission})
if ($rights.allowed -ne $null) {$rights.allowed = $true} else {$rights | Add-Member "allowed" $true}
Invoke-RestMethod -Uri 'https://ci.appveyor.com/api/environments' -Headers $headers -Body ($setting.environment | ConvertTo-Json -Depth 10) -Method Put
}
function UpdateMultipleRolesPermission($roles, $environmentId, $permission) {
$roles | % {UpdateSingleRolePermission $_ $environmentId $permission}
}
$environments = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/environments/" -Headers $headers -Method Get
$environments | % {echo "Updating environment $($_.name)"; UpdateMultipleRolesPermission $roles $_.deploymentEnvironmentId "View"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment