Skip to content

Commit

Permalink
Secrets commands - convert to internal cmdlet Invoke-TssApi
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Aug 5, 2021
1 parent da45da6 commit c86ab78
Show file tree
Hide file tree
Showing 39 changed files with 121 additions and 292 deletions.
5 changes: 3 additions & 2 deletions src/functions/secrets/Close-TssSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function Close-TssSecret {
)
begin {
$protectParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession

$restrictedParamSet = . $ParameterSetParams $PSCmdlet.MyInvocation.MyCommand.Name 'restricted'
$restrictedParams = @()
Expand Down Expand Up @@ -112,7 +112,8 @@ function Close-TssSecret {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n"
try {
. $InvokeApi @invokeParams >$null
$apiResponse = Invoke-TssApi @invokeParams
. $ProcessResponse $apiResponse >$null
} catch {
Write-Warning "Issue checking in Secret [$secret]"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Disable-TssSecretCheckout.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Disable-TssSecretCheckout {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession

$restrictedParamSet = . $ParameterSetParams $PSCmdlet.MyInvocation.MyCommand.Name 'restricted'
$restrictedParams = @()
Expand Down Expand Up @@ -91,7 +91,8 @@ function Disable-TssSecretCheckout {
if ($PSCmdlet.ShouldProcess("SecretId: $secret", "$($invokeParams.Method) $($invokeParams.Uri) with:`n$($invokeParams.Body)`n")) {
Write-Verbose "$($invokeParams.Method) $($invokeParams.Uri) with:`n$($invokeParams.Body)`n"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue configuring [$secret] Checkout settings"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Disable-TssSecretEmail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Disable-TssSecretEmail {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession

$restrictedParamSet = . $ParameterSetParams $PSCmdlet.MyInvocation.MyCommand.Name 'restricted'
$restrictedParams = @()
Expand Down Expand Up @@ -125,7 +125,8 @@ function Disable-TssSecretEmail {
if ($PSCmdlet.ShouldProcess("SecretId: $secret", "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n")) {
Write-Verbose "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue configuring [$secret] email settings, verify Email Server is configured in Secret Server"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Enable-TssSecretCheckout.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Enable-TssSecretCheckout {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession

$restrictedParamSet = . $ParameterSetParams $PSCmdlet.MyInvocation.MyCommand.Name 'restricted'
$restrictedParams = @()
Expand Down Expand Up @@ -110,7 +110,8 @@ function Enable-TssSecretCheckout {
if ($PSCmdlet.ShouldProcess("SecretId: $secret", "$($invokeParams.Method) $($invokeParams.Uri) with:`n$($invokeParams.Body)`n")) {
Write-Verbose "$($invokeParams.Method) $($invokeParams.Uri) with:`n$($invokeParams.Body)`n"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue configuring [$secret] Checkout settings"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Enable-TssSecretEmail.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function Enable-TssSecretEmail {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession

$restrictedParamSet = . $ParameterSetParams $PSCmdlet.MyInvocation.MyCommand.Name 'restricted'
$restrictedParams = @()
Expand Down Expand Up @@ -125,7 +125,8 @@ function Enable-TssSecretEmail {
if ($PSCmdlet.ShouldProcess("SecretId: $secret", "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n")) {
Write-Verbose "$($invokeParams.Method) $uri with:`n$($invokeParams.Body)`n"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue configuring [$secret] email settings, verify Email Server is configured in Secret Server"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Find-TssSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function Find-TssSecret {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand Down Expand Up @@ -245,7 +245,8 @@ function Find-TssSecret {
$invokeParams.Method = 'GET'
Write-Verbose "$($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning 'Issue on search request'
$err = $_
Expand Down
12 changes: 7 additions & 5 deletions src/functions/secrets/Get-TssSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ function Get-TssSecret {
Get Secret via absolute path.
.EXAMPLE
$session = tssnts https://alpha $ssCred
(tssgts $session 330).GetCredential($null,'username','password')
$session = nts https://alpha $ssCred
(gts $session 330).GetCredential($null,'username','password')
Get PSCredential object for Secret ID 330, using alias for the function names
.EXAMPLE
$session = tssnts https://alpha $ssCred
$session = nts https://alpha $ssCred
$secret = Get-TssSecret $session 330
$secret.GetFileFields().Foreach({Get-TssSecretField -Id $secret.Id -Slug $_.SlugName})
Expand Down Expand Up @@ -142,7 +142,8 @@ function Get-TssSecret {
$pathLeaf = Split-Path (Split-Path $Path -Parent) -Leaf
$folderFound = . $SearchFolders $TssSession $pathLeaf | Where-Object FolderPath -EQ $Path
$folderId = $folderFound.Id
$Id = (. $SearchSecrets $TssSession $folderId $secretName | Where-Object Name -EQ $secretName).Id
$searchSecret = Search-TssSecret $TssSession -FolderId $folderId -SearchText $secretName
$Id = $searchSecret.Where({ $_.Name -eq $secretName }).Id

if (-not $Id) {
Write-Verbose "No secret found at path [$Path]"
Expand Down Expand Up @@ -180,7 +181,8 @@ function Get-TssSecret {

Write-Verbose "$($invokeParams.Method) $uri with:`t$($invokeParams.Body)`n"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting secret [$secret]"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Get-TssSecretAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function Get-TssSecretAudit {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
Expand All @@ -64,7 +64,8 @@ function Get-TssSecretAudit {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting audits for [$secret]"
$err = $_
Expand Down
9 changes: 3 additions & 6 deletions src/functions/secrets/Get-TssSecretField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Get-TssSecretField {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand All @@ -98,7 +98,6 @@ function Get-TssSecretField {
. $CheckVersion $TssSession '10.9.000000' $PSCmdlet.MyInvocation
foreach ($secret in $Id) {
$uri = $TssSession.ApiUrl, 'secrets', $secret -join '/'
$restResponse = $null

$body = @{}
if ($PSCmdlet.ParameterSetName -eq 'restricted') {
Expand Down Expand Up @@ -146,15 +145,13 @@ function Get-TssSecretField {
}
Write-Verbose "$($invokeParams.Method) $uri $(if ($body) {"with:`n$($invokeParams.Body)"})"
try {
$script:noIrm = $true
$restResponse = . $InvokeApiWeb @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
. $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting field [$Slug] on secret [$secret]"
$err = $_
. $ErrorHandling $err
}

$restResponse
}
} else {
Write-Warning 'No valid session found'
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Get-TssSecretHeartbeatStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Get-TssSecretHeartbeatStatus {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}
process {
. $InternalEndpointUsed $PSCmdlet.MyInvocation
Expand All @@ -52,7 +52,8 @@ function Get-TssSecretHeartbeatStatus {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting heartbeat status on Secret [$secret]"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Get-TssSecretPasswordStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Get-TssSecretPasswordStatus {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand All @@ -53,7 +53,8 @@ function Get-TssSecretPasswordStatus {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse @apiResponse
} catch {
Write-Warning "Issue getting password status on Secret [$secret]"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Get-TssSecretSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Get-TssSecretSetting {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand All @@ -52,7 +52,8 @@ function Get-TssSecretSetting {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting settings for Secret [$secret]"
$err = $_
Expand Down
7 changes: 4 additions & 3 deletions src/functions/secrets/Get-TssSecretState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ function Get-TssSecretState {
$TssSession,

# Secret ID
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position = 1)]
[Alias('SecretId')]
[int[]]
$Id
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand All @@ -52,7 +52,8 @@ function Get-TssSecretState {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting state for secret [$secret]"
$err = $_
Expand Down
3 changes: 2 additions & 1 deletion src/functions/secrets/Get-TssSecretStub.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function Get-TssSecretStub {

Write-Verbose "$($invokeParams.Method) $uri"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $InvokeApi $apiResponse
} catch {
Write-Warning "Issue getting secret stub template [$SecretTemplateId]"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/Get-TssSecretSummary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Get-TssSecretSummary {
)
begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand All @@ -52,7 +52,8 @@ function Get-TssSecretSummary {

Write-Verbose "Performing the operation $($invokeParams.Method) $uri with $body"
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $InvokeApi $apiResponse
} catch {
Write-Warning "Issue getting summary for Secret [$secret]"
$err = $_
Expand Down
10 changes: 6 additions & 4 deletions src/functions/secrets/Invoke-TssSecretGeneratePassword.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function Invoke-TssSecretGeneratePassword {
$Slug
)
begin {
$invokeGenerateParams = . $GetInvokeTssParams $TssSession
$invokeGenerateParams = . $GetInvokeApiParams $TssSession

$invokeValidateParams = . $GetInvokeTssParams $TssSession
$invokeValidateParams = . $GetInvokeApiParams $TssSession
}
process {
. $InternalEndpointUsed $PSCmdlet.MyInvocation
Expand All @@ -57,7 +57,8 @@ function Invoke-TssSecretGeneratePassword {

Write-Verbose "Performing the operation $($invokeGenerateParams.Method) $uri"
try {
$restGeneratedPassword = . $InvokeApi @invokeGenerateParams
$apiResponse = Invoke-TssApi @invokeGenerateParams
$restGeneratedPassword = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting generated password for Secret [$Id] and Field Slug [$Slug]"
$err = $_
Expand All @@ -74,7 +75,8 @@ function Invoke-TssSecretGeneratePassword {

Write-Verbose "Performing the operation $($invokeValidateParams.Method) $uri"
try {
$restValidateResponse = . $InvokeApi @invokeValidateParams
$apiResponse = Invoke-TssApi @invokeValidateParams
$restValidateResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue validating generated password for Secret [$Id] and Field Slug [$Slug]"
$err = $_
Expand Down
5 changes: 3 additions & 2 deletions src/functions/secrets/New-TssSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function New-TssSecret {

begin {
$tssParams = $PSBoundParameters
$invokeParams = . $GetInvokeTssParams $TssSession
$invokeParams = . $GetInvokeApiParams $TssSession
}

process {
Expand All @@ -76,7 +76,8 @@ function New-TssSecret {
Write-Verbose "$($invokeParams.Method) $uri with:`n $SecretStub"
if (-not $PSCmdlet.ShouldProcess($SecretStub.Name, "$($invokeParams.Method) $uri with $($invokeParams.Body)")) { return }
try {
$restResponse = . $InvokeApi @invokeParams
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue creating secret [$($SecretStub.Name)]"
$err = $_
Expand Down
10 changes: 6 additions & 4 deletions src/functions/secrets/Open-TssSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ function Open-TssSecret {
)
begin {
$tssParams = $PSBoundParameters
$invokeViewCommentParams = . $GetInvokeTssParams $TssSession
$invokeCheckoutParams = . $GetInvokeTssParams $TssSession
$invokeViewCommentParams = . $GetInvokeApiParams $TssSession
$invokeCheckoutParams = . $GetInvokeApiParams $TssSession
}
process {
Write-Verbose "Provided command parameters: $(. $GetInvocation $PSCmdlet.MyInvocation)"
Expand All @@ -87,7 +87,8 @@ function Open-TssSecret {
if ($PSCmdlet.ShouldProcess("Secret ID: $secret", "$($invokeViewCommentParams.Method) $uriViewComment with: `n$($invokeViewCommentParams.Body)`n")) {
Write-Verbose "Performing the operation $($invokeViewCommentParams.Method) $uriViewComment with:`n$($invokeViewCommentParams.Body)`n"
try {
. $InvokeApi @invokeViewCommentParams >$null
$apiResponse = Invoke-TssApi @invokeViewCommentParams
. $ProcessResponse $apiResponse >$null
} catch {
Write-Warning "Issue adding view comment for Secret [$secret]"
$err = $_
Expand All @@ -102,7 +103,8 @@ function Open-TssSecret {
if ($PSCmdlet.ShouldProcess("Secret ID: $secret", "$($invokeCheckoutParams.Method) $uriCheckout")) {
Write-Verbose "Performing the operation $($invokeCheckoutParams.Method) $uriCheckout"
try {
. $InvokeApi @invokeCheckoutParams >$null
$apiResponse = Invoke-TssApi @invokeCheckoutParams
. $ProcessResponse $apiResponse >$null
} catch {
Write-Warning "Issue checking out Secret [$secret]"
$err = $_
Expand Down
Loading

0 comments on commit c86ab78

Please sign in to comment.