Skip to content

Commit

Permalink
Remove-TssIpRestrictionUser - new command to remove IP restriction fr…
Browse files Browse the repository at this point in the history
…om Users
  • Loading branch information
wsmelton committed Oct 1, 2021
1 parent b41b8e6 commit 6edf4bb
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 0 deletions.
128 changes: 128 additions & 0 deletions docs/commands/ipaddress-restrictions/Remove-TssIpRestrictionUser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Remove-TssIpRestrictionUser

## SYNOPSIS
Remove a User IP Address restriction by ID

## SYNTAX

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

## DESCRIPTION
Remove a User IP Address restriction by ID

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45 -UserId 98
```

Remove IP Address restriction 45 from User ID 98

### EXAMPLE 2
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45 -UserId 98, 54, 164, 4254
```

Remove IP Address Restriction 45 from each User

### EXAMPLE 3
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45, 98, 12 -UserId 98, 54, 164, 4254
```

Remove each IP Address Restriction from each User

### EXAMPLE 4
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45, 98, 12 -UserId 98, 54, 164, 4254 -WhatIf
```

Verbose output of actions to be performed.

## 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: None
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-TssIpRestrictionUser](https://thycotic-ps.github.io/thycotic.secretserver/commands/ipaddress-restrictions/Remove-TssIpRestrictionUser)
[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/ipaddress-restrictions/Remove-TssIpRestrictionUser.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/ipaddress-restrictions/Remove-TssIpRestrictionUser.ps1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
function Remove-TssIpRestrictionUser {
<#
.SYNOPSIS
Remove a User IP Address restriction by ID
.DESCRIPTION
Remove a User IP Address restriction by ID
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45 -UserId 98
Remove IP Address restriction 45 from User ID 98
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45 -UserId 98, 54, 164, 4254
Remove IP Address Restriction 45 from each User
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45, 98, 12 -UserId 98, 54, 164, 4254
Remove each IP Address Restriction from each User
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Remove-TssIpRestrictionUser -TssSession $session -Id 45, 98, 12 -UserId 98, 54, 164, 4254 -WhatIf
Verbose output of actions to be performed.
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/ipaddress-restrictions/Remove-TssIpRestrictionUser
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/ipaddress-restrictions/Remove-TssIpRestrictionUser.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 ($user in $UserId) {
foreach ($restriction in $Id) {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'ipaddress-restrictions', $restriction, 'users', $user -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'DELETE'

if (-not $PSCmdlet.ShouldProcess("IP Restriction: $restriction","$($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 Restriction [$restriction] from User [$user]"
$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-TssIpRestrictionUser.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', 'UserId'
[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 6edf4bb

Please sign in to comment.