Skip to content

Commit

Permalink
Get-TssSecret - TssSecret add GetValue() method
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Dec 30, 2020
1 parent 7d90182 commit b73deb9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/classes/TssSecret.class.ps1
@@ -1,15 +1,15 @@
class TssSecretItem {
[string]$fieldDescription
[int]$fieldId
[string]$fieldName
[int]$fileAttachmentId
[string]$filename
[boolean]$isFile
[boolean]$isNotes
[boolean]$isPassword
[int]$itemId
[string]$itemValue
[string]$slug
[string]$FieldDescription
[int]$FieldId
[string]$FieldName
[int]$FileAttachmentId
[string]$Filename
[boolean]$IsFile
[boolean]$IsNotes
[boolean]$IsPassword
[int]$ItemId
[string]$ItemValue
[string]$Slug
}

class TssSecret {
Expand Down Expand Up @@ -61,4 +61,9 @@ class TssSecret {
$passwd = ($this.Items | Where-Object IsPassword).ItemValue
return [pscredential]::new($username,(ConvertTo-SecureString -AsPlainText -Force -String $passwd))
}

[System.String] GetValue([string]$Slug) {
$value = $this.Items.Where({$_.Slug -eq $Slug}).ItemValue
return $value
}
}
5 changes: 4 additions & 1 deletion src/en-us/about_tsssecret.help.txt
Expand Up @@ -19,8 +19,11 @@ PROPERTIES
METHODS

[PSCredential] GetCredential()
Pulls the username field and the field flagged as the password (IsPassword = true).
Pulls the username field and the field flagged as the password (IsPassword = true)
Creates and will output a System.Management.Automation.PSCredential object

[System.String] GetValue(string Slug)
Pulls the ItemValue of the field based on the slug name

RELATED LINKS:
Get-TssSecret
10 changes: 10 additions & 0 deletions src/functions/Get-TssSecret.ps1
Expand Up @@ -25,6 +25,16 @@
Gets Secret ID 46 and then output a PSCredential to utilize in script workflow
.EXAMPLE
PS C:\> $session = New-TssSession -SecretServer https://alpha -Credential $ssCred
PS C:\> $secret = Search-TssSecret -TssSesion $session -FieldSlug server -FieldText 'sql1' | Get-TssSecret
PS C:\> $cred = $secret.GetCredential()
PS C:\> $serverName = $secret.GetValue('server')
Search for the secret with server value of sql1 and pull the secret details
Call GetCredential() method to get the PSCredential object with the username and password
Call GetValue() method passing the slug name to grab the ItemValue of the server field.
.NOTES
Requires TssSession object returned by New-TssSession
#>
Expand Down
3 changes: 3 additions & 0 deletions tests/functions/Get-TssSecret.Tests.ps1
Expand Up @@ -63,5 +63,8 @@ Describe "$commandName works" {
It "$commandName should return PSCredential with method: GetCredential" {
$secret.GetCredential() | Should -BeOfType System.Management.Automation.PSCredential
}
It "$commandName should return Username field value with method: GetValue" {
$secret.GetValue('username') | Should -Not -BeNullOrEmpty
}
}
}

0 comments on commit b73deb9

Please sign in to comment.