Skip to content

Commit

Permalink
module - adjusting pattern for restricted params
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Mar 21, 2021
1 parent 0705a4d commit 1ea709b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/functions/secrets/Disable-SecretCheckout.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Disable-SecretCheckout {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession

$restrictedParamSet = . $ParameterSetParams 'Enable-TssSecretEmail' 'restricted'
$restrictedParamSet = . $ParameterSetParams 'Disable-TssSecretCheckout' 'restricted'
$restrictedParams = @()
foreach ($r in $restrictedParamSet) {
if ($tssParams.ContainsKey($r)) {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/secrets/Disable-SecretEmail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Disable-SecretEmail {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession

$restrictedParamSet = . $ParameterSetParams 'Enable-TssSecretEmail' 'restricted'
$restrictedParamSet = . $ParameterSetParams 'Disable-TssSecretEmail' 'restricted'
$restrictedParams = @()
foreach ($r in $restrictedParamSet) {
if ($tssParams.ContainsKey($r)) {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/secrets/Enable-SecretCheckout.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function Enable-SecretCheckout {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession

$restrictedParamSet = . $ParameterSetParams 'Enable-TssSecretEmail' 'restricted'
$restrictedParamSet = . $ParameterSetParams 'Enable-TssSecretCheckout' 'restricted'
$restrictedParams = @()
foreach ($r in $restrictedParamSet) {
if ($tssParams.ContainsKey($r)) {
Expand Down
38 changes: 18 additions & 20 deletions src/functions/secrets/Get-Secret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ function Get-Secret {
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession

$restrictedParamSet = . $ParameterSetParams 'Get-TssSecret' 'restricted'
$restrictedParams = @()
foreach ($r in $restrictedParamSet) {
if ($tssParams.ContainsKey($r)) {
$restrictedParams += $r
}
}
}

process {
Expand All @@ -102,34 +110,24 @@ function Get-Secret {
$restResponse = $null
$uri = $TssSession.ApiUrl, 'secrets', $secret -join '/'

$body = @{}
if ($PSCmdlet.ParameterSetName -eq 'restricted') {
$getBody = @{}
if ($restrictedParams.Count -gt 0) {
switch ($tssParams.Keys) {
'Comment' {
$body.Add('comment',$Comment)
}
'Comment' { $getBody.Add('comment', $Comment) }
'ForceCheckIn' { $getBody.Add('forceCheckIn', [boolean]$ForceCheckIn) }
'TicketNumber' { $getBody.Add('ticketNumber', $TicketNumber) }
'TicketSystemId' { $getBody.Add('ticketSystemId', $TicketSystemId) }
'DoublelockPassword' {
$passwd = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($DoublelockPassword))
$body.Add('doubleLockPassword',$passwd)
}
'ForceCheckIn' {
$body.Add('forceCheckIn',$ForceCheckIn)
}
'IncludeInactive' {
$body.Add('includeInactive',$IncludeInactive)
}
'TicketNumber' {
$body.Add('ticketNumber',$TicketNumber)
}
'TicketSystemId' {
$body.Add('ticketSystemId',$TicketSystemId)
$getBody.Add('doubleLockPassword',$passwd)
}
}

$uri = $uri, 'restricted' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'POST'
$invokeParams.Body = $body | ConvertTo-Json
} else {
$invokeParams.Body = $getBody | ConvertTo-Json
}else {
$uri = $uri
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'
Expand Down
19 changes: 9 additions & 10 deletions src/functions/secrets/Get-SecretSummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ function Get-SecretSummary {
. $ErrorHandling $err
}

if (-not $restResponse.lastPasswordChangeAttempt) {
$restResponse.lastPasswordChangeAttempt = [datetime]::MinValue
}
if (-not $restResponse.lastAccessed) {
$restResponse.lastAccessed = [datetime]::MinValue
}
if (-not $restResponse.createDate) {
$restResponse.createDate = [datetime]::MinValue
}

if ($restResponse) {
if (-not $restResponse.lastPasswordChangeAttempt) {
$restResponse.lastPasswordChangeAttempt = [datetime]::MinValue
}
if (-not $restResponse.lastAccessed) {
$restResponse.lastAccessed = [datetime]::MinValue
}
if (-not $restResponse.createDate) {
$restResponse.createDate = [datetime]::MinValue
}
[TssSecretSummary]$restResponse
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/functions/secrets/Set-SecretField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,22 @@ function Set-SecretField {
[int]
$TicketNumber,

#Associated Ticket System ID
# Associated Ticket System ID
[Parameter(ParameterSetName = 'restricted')]
[int]
$TicketSystemId
)
begin {
$setParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession

$restrictedParamSet = . $ParameterSetParams 'Set-TssSecretField' 'restricted'
$restrictedParams = @()
foreach ($r in $restrictedParamSet) {
if ($tssParams.ContainsKey($r)) {
$restrictedParams += $r
}
}
}
process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
Expand Down Expand Up @@ -133,7 +141,7 @@ function Set-SecretField {
}

if ($restrictedParams.Count -gt 0) {
switch ($restrictedParams) {
switch ($setParams.Keys) {
'Comment' { $fieldBody.Add('comment', $Comment) }
'ForceCheckIn' { $fieldBody.Add('forceCheckIn', [boolean]$ForceCheckIn) }
'TicketNumber' { $fieldBody.Add('ticketNumber', $TicketNumber) }
Expand Down

0 comments on commit 1ea709b

Please sign in to comment.