-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
Set-VSTeamPipelineAuthorization
to set pipeline authorization…
…s. (#408) * Added pipeline authorization cmdlet * added unit tests * added documentation
- Loading branch information
1 parent
e605f46
commit d4bd3ba
Showing
6 changed files
with
482 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<!-- #include "./common/header.md" --> | ||
|
||
# Set-VSTeamPipelineAuthorization | ||
|
||
## SYNOPSIS | ||
|
||
<!-- #include "./synopsis/Set-VSTeamPipelineAuthorization.md" --> | ||
|
||
## SYNTAX | ||
|
||
## DESCRIPTION | ||
|
||
<!-- #include "./synopsis/Set-VSTeamPipelineAuthorization.md" --> | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
|
||
```powershell | ||
Set-VSTeamPipelineAuthorization -PipelineIds 1 -ResourceId 34 -ResourceType Queue -Authorize $true | ||
``` | ||
Authorizes the pipeline to access the resource 34 of type Queue (Agent Pool). | ||
|
||
### Example 2 | ||
|
||
```powershell | ||
Set-VSTeamPipelineAuthorization -PipelineIds 1 -ResourceId $resourceId -ResourceType VariableGroup -Authorize $false | ||
``` | ||
Removes authorization from the pipeline to access the resource with id $resourceId of type VariableGroup. | ||
|
||
### Example 3 | ||
|
||
```powershell | ||
Set-VSTeamPipelineAuthorization -PipelineIds @(1,2,3) -ResourceId 34 -ResourceType Queue -Authorize $true | ||
``` | ||
Authorizes the pipelines 1, 2 and 3 to access the resource 34 of type Queue (Agent Pool). | ||
|
||
### Example 4 | ||
```powershell | ||
Set-VSTeamPipelineAuthorization -ResourceId $resourceId -ResourceType Repository -AuthorizeAll $true | ||
``` | ||
Authorize all pipelines to access the resource with id $resourceId of type Repository. | ||
|
||
## PARAMETERS | ||
|
||
### -Authorize | ||
Allows given pipelines to use the named resource | ||
|
||
```yaml | ||
Type: Boolean | ||
Parameter Sets: AuthorizeResource | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -AuthorizeAll | ||
Removes any authorization restrictions for the given resource | ||
|
||
```yaml | ||
Type: Boolean | ||
Parameter Sets: AuthorizeAll | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -PipelineIds | ||
List of pipeline Ids to authorize | ||
|
||
```yaml | ||
Type: Int32[] | ||
Parameter Sets: AuthorizeResource | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -ResourceId | ||
Resource which the pipelines are authorized to use. | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
### -ResourceType | ||
Resource type to authorize the pipeline on | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Aliases: | ||
Accepted values: Queue, Endpoint, Environment, VariableGroup, SecureFile, Repository | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
|
||
<!-- #include "./params/projectName.md" --> | ||
|
||
## INPUTS | ||
|
||
### System.Int32[] | ||
|
||
## OUTPUTS | ||
|
||
### System.Object | ||
|
||
## NOTES | ||
<!-- #include "./common/prerequisites.md" --> | ||
|
||
## RELATED LINKS | ||
|
||
<!-- #include "./common/related.md" --> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Authorizes pipelines to use the given resources. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function Set-VSTeamPipelineAuthorization { | ||
[CmdletBinding(DefaultParameterSetName = 'AuthorizeResource', SupportsShouldProcess = $true, ConfirmImpact = "Medium", | ||
HelpUri = 'https://methodsandpractices.github.io/vsteam-docs/docs/modules/vsteam/commands/Set-VSTeamPipelineAuthorization')] | ||
param ( | ||
[Parameter(ParameterSetName = 'AuthorizeResource', Mandatory = $true, ValueFromPipeline = $true, Position = 0)] | ||
[int[]] $PipelineIds, | ||
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] | ||
[vsteam_lib.ProjectValidateAttribute($false)] | ||
[ArgumentCompleter([vsteam_lib.ProjectCompleter])] | ||
[string] $ProjectName, | ||
[Parameter(ParameterSetName = 'AuthorizeResource', Mandatory = $true)] | ||
[Parameter(ParameterSetName = 'AuthorizeAll', Mandatory = $true)] | ||
[string] | ||
|
||
$ResourceId, | ||
[Parameter(ParameterSetName = 'AuthorizeResource', Mandatory = $true)] | ||
[Parameter(ParameterSetName = 'AuthorizeAll', Mandatory = $true)] | ||
[string] | ||
[ValidateSet("Queue", "Endpoint", "Environment", "VariableGroup", "SecureFile", "Repository")] | ||
$ResourceType, | ||
[Parameter(ParameterSetName = 'AuthorizeResource', Mandatory = $true)] | ||
[bool] | ||
$Authorize, | ||
[Parameter(ParameterSetName = 'AuthorizeAll', Mandatory = $true)] | ||
[bool] | ||
$AuthorizeAll | ||
) | ||
|
||
process { | ||
$permPipeBody = @{ | ||
# this part is actually disabling auto approval for pipelines (also future) to use this resource | ||
|
||
allPipelines = @{ | ||
authorized = $AuthorizeAll | ||
} | ||
# this part is tragetting specific pipelines that are supposed to be authorized for the resource | ||
pipelines = @( ) | ||
} | ||
|
||
if ($PipelineIds) { | ||
foreach ($id in $PipelineIds) { | ||
$permPipeBody.pipelines += @{ | ||
id = $id | ||
authorized = $Authorize | ||
} | ||
} | ||
} | ||
|
||
$permPipeJsonBody = $permPipeBody | ConvertTo-Json -Compress -Depth 100 | ||
|
||
$completeResourceId = $null | ||
|
||
switch ($ResourceType) { | ||
"Repository" { | ||
$projectId = (Get-VSTeamProject -Name $ProjectName).id | ||
$completeResourceId = "$ResourceType/$projectId." + $ResourceId | ||
} | ||
Default { | ||
$completeResourceId = "$ResourceType/" + $ResourceId | ||
} | ||
} | ||
|
||
if ($PSCmdlet.ShouldProcess("$ResourceType $ResourceId with Pipeline $PipelineId", $Authorized)) { | ||
|
||
$resp = _callAPI -Method PATCH ` | ||
-ProjectName $ProjectName ` | ||
-Area 'Pipelines' ` | ||
-Resource 'pipelinePermissions' ` | ||
-Id $completeResourceId ` | ||
-Body $permPipeJsonBody ` | ||
-Version $(_getApiVersion Pipelines) | ||
|
||
Write-Output $resp | ||
} | ||
} | ||
} |
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
Oops, something went wrong.