Skip to content

Commit

Permalink
Add property check for class
Browse files Browse the repository at this point in the history
Should catch if endpoints get new properties that do not exist in the class
  • Loading branch information
wsmelton committed Dec 29, 2020
1 parent a73cf69 commit 244ac1d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
16 changes: 12 additions & 4 deletions .vscode/tss.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"\t\t\tPersonalAccessToken = $session.AccessToken",
"\t\t}",
"\t\t\\$getFolders = Invoke-TssRestApi @invokeParams",
"\t\t\\$tssSecretFolder = \\$getFolders.Where({\\$_.folderPath -match 'tss_module_testing\\\\GetTssSecret'})",
"\t\t\\$tssSecretFolder = \\$getFolders.Where({\\$_.folderPath -eq '\tss_module_testing'})",
"\t\t# Prep work",
"",
"\t\t\\$session.SessionExpire()",
Expand Down Expand Up @@ -155,9 +155,13 @@
"process {",
"\t\\$items = @()",
"\t\tforeach (\\$i in \\$Object.items) {",
"\t\t\t\\$item = [${1}]::new()",
"\t\t\t\\$item = [${3:Child class name}]::new()",
"\t\t\tforeach (\\$iProp in \\$itemProperties) {",
"\t\t\t\t\\$item.\\$iProp = \\$i.\\$iProp",
"\t\t\t\tif (\\$iProp -in \\$item.PSObject.Properties.Name) {",
"\t\t\t\t\t\\$item.\\$iProp = \\$i.\\$iProp",
"\t\t\t\t} else {",
"\t\t\t\t\tWrite-Warning \"Property \\$iProp does not exist in the ${3} class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose\"",
"\t\t\t\t}",
"\t\t\t\t\\$items += \\$item",
"\t\t\t}",
"\t\t}",
Expand All @@ -168,7 +172,11 @@
"\t\t\t\t\tif (\\$sProp -eq 'items') {",
"\t\t\t\t\t\t\\$outObject.Items = \\$items",
"\t\t\t\t\t}",
"\t\t\t\t\t\\$outObject.\\$sProp = \\$s.\\$sProp",
"\t\t\t\t\tif (\\$sProp -in \\$outObject.PSObject.Properties.Name) {",
"\t\t\t\t\t\t\\$outObject.\\$sProp = \\$s.\\$sProp",
"\t\t\t\t\t} else {",
"\t\t\t\t\t\tWrite-Warning \"Property \\$sProp does not exist in the ${1} class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose\"",
"\t\t\t\t\t}",
"\t\t\t\t}",
"\t\t}",
"\t\treturn \\$outObject",
Expand Down
18 changes: 15 additions & 3 deletions src/parts/GetTssFolderTemplateObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ process {
foreach ($ft in $FolderRecord.secretTemplates) {
$fTemplate = [TssFolderTemplate]::new()
foreach ($tProp in $folderTemplateProperties) {
$fTemplate.$tProp = $ft.$tProp
if ($tProp -in $fTemplate.PSObject.Properties.Name) {
$fTemplate.$tProp = $ft.$tProp
} else {
Write-warning "Property $tProp does not exist in the TssFOlderTemplate class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
$secretTemplates += $fTemplate
}
$childFolders = @()
foreach ($cf in $FolderRecord.childFolders) {
$cFolder = [TssFolder]::new()
foreach ($cProp in $folderChildrenProperties) {
$cFolder.$cProp = $cf.$cProp
if ($cProp -in $cFolder.PSObject.Properties.Name) {
$cFolder.$cProp = $cf.$cProp
} else {
Write-warning "Property $tProp does not exist in the TssFolder class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
$childFolders += $cFolder
}
Expand All @@ -49,7 +57,11 @@ process {
if ($fProp -eq 'SecretTemplates') {
$outFolder.SecretTemplates = $secretTemplates
}
$outFolder.$fProp = $f.$fProp
if ($fProp -in $outFolder.PSObject.Properties.Name) {
$outFolder.$fProp = $f.$fProp
} else {
Write-Warning "Property $fProp does not exist in the TssFolder class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
}
return $outFolder
Expand Down
12 changes: 10 additions & 2 deletions src/parts/GetTssSecretObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ process {
foreach ($i in $SecretRecord.items) {
$item = [TssSecretItem]::new()
foreach ($iProp in $itemProperties) {
$item.$iProp = $i.$iProp
if ($iProp -in $item.PSObject.Properties.Name) {
$item.$iProp = $i.$iProp
} else {
Write-Warning "Property $sProp does not exists on the TssSecret class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
$items += $item
}
Expand All @@ -29,7 +33,11 @@ process {
if ($sProp -eq 'items') {
$outSecret.Items = $items
}
$outSecret.$sProp = $s.$sProp
if ($sProp -in $outSecret.PSObject.Properties.Name) {
$outSecret.$sProp = $s.$sProp
} else {
Write-warning "Property $sProp does not exist in the TssSecret class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
}
return $outSecret
Expand Down
14 changes: 11 additions & 3 deletions src/parts/GetTssSecretSummaryObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ process {
foreach ($ef in $Object.extendedFields) {
$item = [TssSecretSummaryExtendedField]::new()
foreach ($iProp in $extFieldProperties) {
$item.$iProp = $ef.$iProp
if ($iProp -in $item.PSObject.Properties.Name) {
$item.$iProp = $ef.$iProp
} else {
Write-Warning "Property $iProp does not exist in the TssSecretSummaryExtendedField class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
$extFields += $item
}
}
Expand All @@ -33,8 +37,12 @@ process {
if ($sProp -eq 'extendedFields') {
$outObject.ExtendedFields = $extFields
}
if ($s.$sProp) {
$outObject.$sProp = $s.$sProp
if ($sProp -in $outObject.PSObject.Properties.Name) {
if ($s.$sProp) {
$outObject.$sProp = $s.$sProp
}
} else {
Write-Warning "Property $sProp does nto exist in the TssSecretSummary class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/parts/GetTssSecretTemplateObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ process {
foreach ($f in $Object.fields) {
$field = [TssSecretTemplateField]::new()
foreach ($fProp in $fieldProperties) {
$field.$fProp = $f.$fProp
if ($fProp -in $field.PSObject.Properties.Name) {
$field.$fProp = $f.$fProp
} else {
Write-Warning "Property $fProp does not exist in the TssSecretTempalteField class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
$fields += $field
}
}
Expand All @@ -29,7 +33,11 @@ process {
if ($sProp -eq 'fields') {
$outObject.Fields = $fields
}
$outObject.$sProp = $s.$sProp
if ($sProp -in $outObject.PSObject.Properties.Name) {
$outObject.$sProp = $s.$sProp
} else {
Write-Warning "Property $sProp does not exist in the TssSecretTempalte class. Please create a bug report at https://github.com/thycotic-ps/thycotic.secretserver/issues/new/choose"
}
}
}
return $outObject
Expand Down

0 comments on commit 244ac1d

Please sign in to comment.