Created
August 30, 2018 06:58
-
-
Save IlyaFinkelshteyn/b10f171a3808a7ef4cd1743a83fddaa8 to your computer and use it in GitHub Desktop.
This file contains 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
$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