From eaa963b519ccc842b697193dfafb83d7f7488e45 Mon Sep 17 00:00:00 2001 From: Dennis Hanuska Date: Mon, 14 Feb 2022 17:46:20 -0400 Subject: [PATCH 1/3] Support for identity/get-members --- VenafiPS/Public/Get-TppIdentity.ps1 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/VenafiPS/Public/Get-TppIdentity.ps1 b/VenafiPS/Public/Get-TppIdentity.ps1 index f52557bd..d098bcad 100644 --- a/VenafiPS/Public/Get-TppIdentity.ps1 +++ b/VenafiPS/Public/Get-TppIdentity.ps1 @@ -11,6 +11,9 @@ The individual identity, group identity, or distribution group prefixed universa .PARAMETER IncludeAssociated Include all associated identity groups and folders +.PARAMETER IncludeMembers +Include all individual members if the ID is a group + .PARAMETER Me Returns the identity of the authenticated user @@ -26,11 +29,16 @@ PSCustomObject with the following properties: ID Path Associated (if -IncludeAssociated provided) + Members (if -IncludeMembers provided) .EXAMPLE Get-TppIdentity -ID 'AD+myprov:asdfgadsf9g87df98g7d9f8g7' Get identity details from an id +.EXAMPLE +Get-TppIdentity -ID 'AD+myprov:asdfgadsf9g87df98g7d9f8g7' -IncludeMembers + +Get identity details and if the identity is a group it will also return the members .EXAMPLE Get-TppIdentity -ID 'AD+myprov:asdfgadsf9g87df98g7d9f8g7' -IncludeAssociated @@ -56,6 +64,10 @@ https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-GET-Identit .LINK https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-POST-Identity-GetAssociatedEntries.php + +.LINK +https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-POST-Identity-GetMembers.php + #> function Get-TppIdentity { @@ -70,6 +82,10 @@ function Get-TppIdentity { [Parameter(ParameterSetName = 'Id')] [Switch] $IncludeAssociated, + [Parameter(ParameterSetName = 'Id')] + [Switch] $IncludeMembers, + + [Parameter(Mandatory, ParameterSetName = 'Me')] [Switch] $Me, @@ -121,6 +137,14 @@ function Get-TppIdentity { $response | Add-Member @{ 'Associated' = $associated.Identities } } + if (($response.IsGroup) -and ($IncludeMembers)) { + $assocParams = $params.Clone() + $assocParams.UriLeaf = 'Identity/GetMembers' + $assocParams.Body.Add("ResolveNested","1"); + $members = Invoke-VenafiRestMethod @assocParams + $response | Add-Member @{ 'Members' = $members.Identities} + } + $response } } From 621e39d1590eb0a1319ae9b1f6f83c478bb93a5d Mon Sep 17 00:00:00 2001 From: Dennis Hanuska Date: Tue, 15 Feb 2022 17:19:24 -0400 Subject: [PATCH 2/3] Edits based on feedback --- VenafiPS/Public/Get-TppIdentity.ps1 | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/VenafiPS/Public/Get-TppIdentity.ps1 b/VenafiPS/Public/Get-TppIdentity.ps1 index d098bcad..7baf9d26 100644 --- a/VenafiPS/Public/Get-TppIdentity.ps1 +++ b/VenafiPS/Public/Get-TppIdentity.ps1 @@ -93,6 +93,8 @@ function Get-TppIdentity { [VenafiSession] $VenafiSession = $script:VenafiSession ) + + begin { $VenafiSession.Validate('TPP') @@ -134,15 +136,16 @@ function Get-TppIdentity { $assocParams = $params.Clone() $assocParams.UriLeaf = 'Identity/GetAssociatedEntries' $associated = Invoke-VenafiRestMethod @assocParams - $response | Add-Member @{ 'Associated' = $associated.Identities } + $response | Add-Member @{ 'Associated' = $associated.Identities | script:Format-Output } } if (($response.IsGroup) -and ($IncludeMembers)) { $assocParams = $params.Clone() $assocParams.UriLeaf = 'Identity/GetMembers' - $assocParams.Body.Add("ResolveNested","1"); + $assocParams.Body.ResolveNested="1" $members = Invoke-VenafiRestMethod @assocParams - $response | Add-Member @{ 'Members' = $members.Identities} + $response | Add-Member @{ 'Members' = $members.Identities | script:Format-Output } + } $response @@ -157,15 +160,24 @@ function Get-TppIdentity { } if ( $idOut ) { - $idOut | Select-Object ` - @{ - n = 'ID' - e = { $_.PrefixedUniversal } - }, - @{ - n = 'Path' - e = { $_.FullName } - }, * -ExcludeProperty PrefixedUniversal, FullName, Prefix, PrefixedName, Type, Universal + $idOut | script:Format-Output } } + } +filter script:Format-Output +{ + + + $_ | Select-Object ` + @{ + n = 'ID' + e = { $_.PrefixedUniversal } + }, + @{ + n = 'Path' + e = { $_.FullName } + }, * -ExcludeProperty PrefixedUniversal, FullName, Prefix, PrefixedName, Type, Universal + + +} \ No newline at end of file From fd979edd71a8a3208f36d6d8da0ca17edc440886 Mon Sep 17 00:00:00 2001 From: Greg Brownstein Date: Wed, 16 Feb 2022 12:19:31 -0500 Subject: [PATCH 3/3] ensure params always show --- VenafiPS/Public/Get-TppIdentity.ps1 | 57 +++++++++++++++++------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/VenafiPS/Public/Get-TppIdentity.ps1 b/VenafiPS/Public/Get-TppIdentity.ps1 index 7baf9d26..f9b163be 100644 --- a/VenafiPS/Public/Get-TppIdentity.ps1 +++ b/VenafiPS/Public/Get-TppIdentity.ps1 @@ -94,7 +94,7 @@ function Get-TppIdentity { ) - + begin { $VenafiSession.Validate('TPP') @@ -136,16 +136,19 @@ function Get-TppIdentity { $assocParams = $params.Clone() $assocParams.UriLeaf = 'Identity/GetAssociatedEntries' $associated = Invoke-VenafiRestMethod @assocParams - $response | Add-Member @{ 'Associated' = $associated.Identities | script:Format-Output } + $response | Add-Member @{ 'Associated' = $null } + $response.Associated = $associated.Identities | script:Format-Output } - if (($response.IsGroup) -and ($IncludeMembers)) { - $assocParams = $params.Clone() - $assocParams.UriLeaf = 'Identity/GetMembers' - $assocParams.Body.ResolveNested="1" - $members = Invoke-VenafiRestMethod @assocParams - $response | Add-Member @{ 'Members' = $members.Identities | script:Format-Output } - + if ( $IncludeMembers ) { + $response | Add-Member @{ 'Members' = $null } + if ( $response.IsGroup ) { + $assocParams = $params.Clone() + $assocParams.UriLeaf = 'Identity/GetMembers' + $assocParams.Body.ResolveNested = "1" + $members = Invoke-VenafiRestMethod @assocParams + $response.Members = $members.Identities | script:Format-Output + } } $response @@ -165,19 +168,25 @@ function Get-TppIdentity { } } -filter script:Format-Output -{ - - - $_ | Select-Object ` - @{ - n = 'ID' - e = { $_.PrefixedUniversal } - }, - @{ - n = 'Path' - e = { $_.FullName } - }, * -ExcludeProperty PrefixedUniversal, FullName, Prefix, PrefixedName, Type, Universal - - +filter script:Format-Output { + $_ | Select-Object ` + @{ + n = 'ID' + e = { $_.PrefixedUniversal } + }, + @{ + n = 'Path' + e = { $_.FullName } + }, + @{ + n = 'IsGroup' + e = { + if ( $_.IsGroup) { + $_.IsGroup + } + else { + $false + } + } + }, * -ExcludeProperty PrefixedUniversal, FullName, Prefix, PrefixedName, Type, Universal, IsGroup } \ No newline at end of file