Skip to content

Commit

Permalink
Remove-TssIpRestriction - new command to delete IP Address Restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Sep 28, 2021
1 parent f3a9f83 commit d63d657
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 0 deletions.
104 changes: 104 additions & 0 deletions docs/commands/ipaddress-restrictions/Remove-TssIpRestriction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Remove-TssIpRestriction

## SYNOPSIS
Delete an IP Address restriction

## SYNTAX

```
Remove-TssIpRestriction [-TssSession] <Session> -Id <Int32> [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Delete an IP Address restriction

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestriction -TssSession $session -Id 5
```

Delete the IP Address restriction 5

## PARAMETERS

### -TssSession
TssSession object created by New-TssSession for authentication

```yaml
Type: Session
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### -Id
IP Address Restriction Id
```yaml
Type: Int32
Parameter Sets: (All)
Aliases: IpAddressRestrictionId

Required: True
Position: Named
Default value: 0
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
### Thycotic.PowerShell.Common.Delete
## NOTES
Requires TssSession object returned by New-TssSession
## RELATED LINKS
[https://thycotic-ps.github.io/thycotic.secretserver/commands/ipaddress-restrictions/Remove-TssIpRestriction](https://thycotic-ps.github.io/thycotic.secretserver/commands/ipaddress-restrictions/Remove-TssIpRestriction)
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/ipaddress-restrictions/Remove-TssIpRestriction.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/ipaddress-restrictions/Remove-TssIpRestriction.ps1)
74 changes: 74 additions & 0 deletions src/functions/ipaddress-restrictions/Remove-TssIpRestriction.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function Remove-TssIpRestriction {
<#
.SYNOPSIS
Delete an IP Address restriction
.DESCRIPTION
Delete an IP Address restriction
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestriction -TssSession $session -Id 5
Delete the IP Address restriction 5
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/ipaddress-restrictions/Remove-TssIpRestriction
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/ipaddress-restrictions/Remove-TssIpRestriction.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding(SupportsShouldProcess)]
[OutputType('Thycotic.PowerShell.Common.Delete')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession,

# IP Address Restriction Id
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias("IpAddressRestrictionId")]
[int]
$Id
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $CheckVersion $TssSession '10.9.000064' $PSCmdlet.MyInvocation
foreach ($ipRestriction in $Id) {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'ipaddress-restrictions', $ipRestriction -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'DELETE'

if (-not $PSCmdlet.ShouldProcess("IP Restriction: $ipRestriction","$($invokeParams.Method) $($invokeParams.Uri)")) { return }
Write-Verbose "Performing the operation $($invokeParams.Method) $($invokeParams.Uri) with $body"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue removing IP Address restriction [$ipRestriction]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse) {
[Thycotic.PowerShell.Common.Delete]@{
Id = $restResponse.id
ObjectType = $restResponse.objectType
}
}
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/ipaddress-restrictions/Remove-TssIpRestriction.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession', 'Id'
[object[]]$currentParams = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')).Parameters.Keys
[object[]]$commandDetails = [System.Management.Automation.CommandInfo]$ExecutionContext.SessionState.InvokeCommand.GetCommand($commandName,'Function')
$unknownParameters = Compare-Object -ReferenceObject $knownParameters -DifferenceObject $currentParams -PassThru
}
Context "Verify parameters" -Foreach @{currentParams = $currentParams } {
It "$commandName should contain <_> parameter" -TestCases $knownParameters {
$_ -in $currentParams | Should -Be $true
}
It "$commandName should not contain parameter: <_>" -TestCases $unknownParameters {
$_ | Should -BeNullOrEmpty
}
}
Context "Command specific details" {
It "$commandName should set OutputType to Thycotic.PowerShell.Common.Delete" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Common.Delete'
}
}
}

0 comments on commit d63d657

Please sign in to comment.