Skip to content

Commit

Permalink
Added Set-VSTeamPipelineAuthorization to set pipeline authorization…
Browse files Browse the repository at this point in the history
…s. (#408)

* Added pipeline authorization cmdlet
* added unit tests
* added documentation
  • Loading branch information
SebastianSchuetze authored Jul 31, 2021
1 parent e605f46 commit d4bd3ba
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 2 deletions.
137 changes: 137 additions & 0 deletions .docs/Set-VSTeamPipelineAuthorization.md
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" -->
1 change: 1 addition & 0 deletions .docs/synopsis/Set-VSTeamPipelineAuthorization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Authorizes pipelines to use the given resources.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Changelog

## 7.3.1
## 7.4.0

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/400) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:

- Fixes ambiguity of parameter sets in VSTeamUserEntitlement cmdlets [#393](https://github.com/DarqueWarrior/vsteam/issues/393)

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/408) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:

- Added `Set-VSTeamPipelineAuthorization` to set pipeline authorizations.

## 7.3.0

Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/396) from [Markus Blaschke](https://github.com/mblaschke) which included the following:
Expand Down
76 changes: 76 additions & 0 deletions Source/Public/Set-VSTeamPipelineAuthorization.ps1
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
}
}
}
2 changes: 1 addition & 1 deletion Source/VSTeam.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'VSTeam.psm1'

# Version number of this module.
ModuleVersion = '7.3.1'
ModuleVersion = '7.4.0'

# Supported PSEditions
CompatiblePSEditions = @('Core', 'Desktop')
Expand Down
Loading

0 comments on commit d4bd3ba

Please sign in to comment.