Skip to content

Commit

Permalink
Get-TssMetadataField - new command
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Aug 17, 2021
1 parent 586d684 commit cd12a48
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 20 deletions.
34 changes: 17 additions & 17 deletions .vscode/tss.code-snippets
Expand Up @@ -189,25 +189,25 @@
" ${2:Short of what command does}",
"",
" .DESCRIPTION",
" ${3:Longer of what command does}",
" ${2}",
"",
" .EXAMPLE",
" \\$session = New-TssSession -SecretServer https://alpha -Credential \\$ssCred",
" Get-Tss${1} -TssSession \\$session -${4} ${5:some test value}",
" Get-Tss${1} -TssSession \\$session -${3} ${4:some test value}",
"",
" ${6:Add minimum example for each parameter}",
" ${5:Add minimum example for each parameter}",
"",
" .LINK",
" https://thycotic-ps.github.io/thycotic.secretserver/commands/${9}/Get-Tss${1}",
" https://thycotic-ps.github.io/thycotic.secretserver/commands/${6:Folder Name}/Get-Tss${1}",
"",
" .LINK",
" https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/${9:Folder name}/Get-Tss${1}.ps1",
" https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/${6}/Get-Tss${1}.ps1",
"",
" .NOTES",
" Requires TssSession object returned by New-TssSession",
" #>",
" [CmdletBinding()]",
" [OutputType('Tss${1}')]",
" [OutputType('${7:Class name}')]",
" param (",
" # TssSession object created by New-TssSession for authentication",
" [Parameter(Mandatory,ValueFromPipeline,Position = 0)]",
Expand All @@ -216,8 +216,8 @@
"",
" # Short description for parameter",
" [Parameter(Mandatory,ValueFromPipelineByPropertyName)]",
" [Alias(\"${1}Id\")]",
" [int[]]",
" [Alias(\"${8:Alias if needed}\")]",
" [${9:Class type}]",
" \\$${4}",
" )",
" begin {",
Expand All @@ -228,24 +228,24 @@
" Write-Verbose \"Provided command parameters: \\$(. \\$GetInvocation \\$PSCmdlet.MyInvocation)\"",
" if (\\$tssParams.ContainsKey('TssSession') -and \\$TssSession.IsValidSession()) {",
" . \\$CheckVersion \\$TssSession '10.9.000000' \\$PSCmdlet.MyInvocation",
" foreach (\\$${7} in \\$${4}) {",
" \\$restResponse = \\$null",
" \\$uri = \\$TssSession.ApiUrl, '${1}', \\$${8} -join '/'",
" \\$invokeParams.Uri = \\$uri",
" \\$invokeParams.Method = 'GET'",
" foreach (\\$${10:var name} in \\$${4}) {",
" \\$restResponse = \\$null",
" \\$uri = \\$TssSession.ApiUrl, '${11:endpoint}', \\$${10} -join '/'",
" \\$invokeParams.Uri = \\$uri",
" \\$invokeParams.Method = 'GET'",
"",
" Write-Verbose \"Performing the operation \\$(\\$invokeParams.Method) \\$uri with \\$body\"",
" Write-Verbose \"Performing the operation \\$(\\$invokeParams.Method) \\$uri\"",
" try {",
" \\$apiResponse = Invoke-TssApi @invokeParams",
" \\$restResponse = . \\$ProcessResponse \\$apiResponse",
" } catch {",
" Write-Warning \"Issue getting ___ on [\\$${7}]\"",
" Write-Warning \"Issue getting ${12:reference name} on [\\$${10}]\"",
" \\$err = \\$_",
" . \\$ErrorHandling \\$err",
" }",
"",
" if (\\$restResponse) {",
" # Do any formatting or call object part",
" if (\\$restResponse.records) {",
" [${7}[]]\\$restResponse.records",
" }",
" }",
" } else {",
Expand Down
58 changes: 58 additions & 0 deletions docs/commands/metadata/Get-TssMetadataField.md
@@ -0,0 +1,58 @@
# Get-TssMetadataField

## SYNOPSIS
Get list of all metadata fields

## SYNTAX

```
Get-TssMetadataField [-TssSession] <Session> [<CommonParameters>]
```

## DESCRIPTION
Get list of all metadata fields

## EXAMPLES

### EXAMPLE 1
```
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssMetadataField -TssSession $session
```

Return list of all metadata fields that exists

## 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
```

### 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.Metadata.FieldSummary
## NOTES
Requires TssSession object returned by New-TssSession

## RELATED LINKS

[https://thycotic-ps.github.io/thycotic.secretserver/commands/metadata/Get-TssMetadataField](https://thycotic-ps.github.io/thycotic.secretserver/commands/metadata/Get-TssMetadataField)

[https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/metadata/Get-TssMetadataField.ps1](https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/metadata/Get-TssMetadataField.ps1)

42 changes: 42 additions & 0 deletions src/Thycotic.SecretServer.Format.ps1xml
Expand Up @@ -2685,5 +2685,47 @@
</TableControl>
</View>

<!-- Thycotic.PowerShell.Metadata.FieldSummary -->
<View>
<Name>Metadata.FieldSummary</Name>
<ViewSelectedBy>
<TypeName>Thycotic.PowerShell.Metadata.FieldSummary</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>MetadataFieldSectionId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>MetadataFieldSectionName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>MetadataFieldId</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>MetadataFieldName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>MetadataFieldName</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>DefaultSortOrder</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>

</ViewDefinitions>
</Configuration>
7 changes: 4 additions & 3 deletions src/Thycotic.SecretServer.psd1
Expand Up @@ -84,9 +84,10 @@ FunctionsToExport = 'Add-TssEventPipeline', 'Add-TssFolderPermission',
'Get-TssEventPipelineRun', 'Get-TssFolder', 'Get-TssFolderAudit',
'Get-TssFolderPermission', 'Get-TssFolderState', 'Get-TssGroup',
'Get-TssGroupMember', 'Get-TssGroupRole', 'Get-TssGroupUser',
'Get-TssReport', 'Get-TssReportCategory', 'Get-TssReportParameter',
'Get-TssRpcAssociatedSecret', 'Get-TssRpcPasswordType',
'Get-TssScript', 'Get-TssSecret', 'Get-TssSecretAccessRequestOption',
'Get-TssMetadataField', 'Get-TssReport', 'Get-TssReportCategory',
'Get-TssReportParameter', 'Get-TssRpcAssociatedSecret',
'Get-TssRpcPasswordType', 'Get-TssScript', 'Get-TssSecret',
'Get-TssSecretAccessRequestOption',
'Get-TssSecretAccessRequestSecret', 'Get-TssSecretAttachment',
'Get-TssSecretAudit', 'Get-TssSecretDependency',
'Get-TssSecretDependencyGroup', 'Get-TssSecretDependencyRunStatus',
Expand Down
18 changes: 18 additions & 0 deletions src/Thycotic.SecretServer/classes/metadata/FieldSummary.cs
@@ -0,0 +1,18 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using Thycotic.PowerShell.Enums;

namespace Thycotic.PowerShell.Metadata
{
public class FieldSummary
{
public int DefaultSortOrder { get; set; }
public MetadataFieldDataType FieldDataType {get;set;}
public int MetadataFieldId { get; set; }
public string MetadataFieldName { get; set; }
public int MetadataFieldSectionId { get; set; }
public string MetadataFieldSectionName { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Thycotic.SecretServer/enums/MetadataFieldDataType.cs
@@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using System.Management.Automation;
using System.Management.Automation.Runspaces;

namespace Thycotic.PowerShell.Enums
{
public enum MetadataFieldDataType
{
String,
Boolean,
Number,
DateTime,
User
}
}
61 changes: 61 additions & 0 deletions src/functions/metadata/Get-TssMetadataField.ps1
@@ -0,0 +1,61 @@
function Get-TssMetadataField {
<#
.SYNOPSIS
Get list of all metadata fields
.DESCRIPTION
Get list of all metadata fields
.EXAMPLE
$session = New-TssSession -SecretServer https://alpha -Credential $ssCred
Get-TssMetadataField -TssSession $session
Return list of all metadata fields that exists
.LINK
https://thycotic-ps.github.io/thycotic.secretserver/commands/metadata/Get-TssMetadataField
.LINK
https://github.com/thycotic-ps/thycotic.secretserver/blob/main/src/functions/metadata/Get-TssMetadataField.ps1
.NOTES
Requires TssSession object returned by New-TssSession
#>
[CmdletBinding()]
[OutputType('Thycotic.PowerShell.Metadata.FieldSummary')]
param (
# TssSession object created by New-TssSession for authentication
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Thycotic.PowerShell.Authentication.Session]
$TssSession
)
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.000000' $PSCmdlet.MyInvocation
$uri = $TssSession.ApiUrl, 'metadata', 'fields' -join '/'
$invokeParams.Uri = $uri
$invokeParams.Method = 'GET'

Write-Verbose "Performing the operation $($invokeParams.Method) $uri"
try {
$apiResponse = Invoke-TssApi @invokeParams
$restResponse = . $ProcessResponse $apiResponse
} catch {
Write-Warning "Issue getting reference name on [$var name]"
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records) {
[Thycotic.PowerShell.Metadata.FieldSummary[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
}
}
}
24 changes: 24 additions & 0 deletions tests/metadata/Get-TssMetadataField.Tests.ps1
@@ -0,0 +1,24 @@
BeforeDiscovery {
$commandName = Split-Path ($PSCommandPath.Replace('.Tests.ps1','')) -Leaf
}
Describe "$commandName verify parameters" {
BeforeDiscovery {
[object[]]$knownParameters = 'TssSession'
[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.Metadata.FieldSummary" -TestCases $commandDetails {
$_.OutputType.Name | Should -Be 'Thycotic.PowerShell.Metadata.FieldSummary'
}
}
}

0 comments on commit cd12a48

Please sign in to comment.