Skip to content

Commit

Permalink
Module - implemented [Nullable[datetime]]
Browse files Browse the repository at this point in the history
Handles endpoints that return null for datetime properties
  • Loading branch information
wsmelton committed Jun 2, 2021
1 parent 458e56f commit 20a41e7
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/classes/distributed-engines/TssSiteSummary.class.ps1
Expand Up @@ -5,7 +5,7 @@ class TssSiteSummary {
[boolean]
$IsLocal

[datetime]
[Nullable[datetime]]
$LastActivity

[int]
Expand Down
4 changes: 2 additions & 2 deletions src/classes/groups/TssGroup.class.ps1
Expand Up @@ -5,8 +5,8 @@ class TssGroup {
[boolean]
$CanEditMembers

[datetime]
$Created = [datetime]::MinValue
[Nullable[datetime]]
$Created

[int]
$DomainId
Expand Down
2 changes: 1 addition & 1 deletion src/classes/secrets/TssSecretDetailSettings.class.ps1
@@ -1,5 +1,5 @@
class TssSecretDetailSettings {
[datetime]
[Nullable[datetime]]
$ExpirationDate

[int]
Expand Down
2 changes: 1 addition & 1 deletion src/classes/secrets/TssSecretHeartbeatStatus.class.ps1
Expand Up @@ -3,6 +3,6 @@ class TssSecretHeartbeatStatus {
[string]
$Status

[datetime]
[Nullable[datetime]]
$LastHeartbeatCheck
}
6 changes: 3 additions & 3 deletions src/classes/secrets/TssSecretSummary.class.ps1
Expand Up @@ -11,7 +11,7 @@ class TssSecretSummary {
[boolean]
$CheckOutEnabled

[datetime]
[Nullable[datetime]]
$CreateDate

[int]
Expand Down Expand Up @@ -44,14 +44,14 @@ class TssSecretSummary {
[boolean]
$IsRestricted

[datetime]
[Nullable[datetime]]
$LastAccessed

[ValidateSet('Failed','Success','Pending','Disabled','UnableToConnect','UnknownError','IncompatibleHost','AccountLockedOut','DnsMismatch','UnableToValidateServerPublicKey','Processing','ArgumentError','AccessDenied')]
[string]
$LastHeartbeatStatus

[datetime]
[Nullable[datetime]]
$LastPasswordChangeAttempt

[string]
Expand Down
14 changes: 7 additions & 7 deletions src/classes/users/TssUser.class.ps1
@@ -1,11 +1,11 @@
class TssUser {
[datetime]
[Nullable[datetime]]
$AdAccountExpires

[string]
$AdGuid

[datetime]
[Nullable[datetime]]
$Created

[int]
Expand Down Expand Up @@ -44,10 +44,10 @@ class TssUser {
[boolean]
$IsLockedOut

[datetime]
[Nullable[datetime]]
$LastLogin

[datetime]
[Nullable[datetime]]
$LastSessionActivity

[string]
Expand All @@ -68,7 +68,7 @@ class TssUser {
[boolean]
$OathVerified

[datetime]
[Nullable[datetime]]
$PasswordLastChanged

[boolean]
Expand All @@ -77,7 +77,7 @@ class TssUser {
[string]
$RadiusUserName

[datetime]
[Nullable[datetime]]
$ResetSessionStarted

[int]
Expand All @@ -96,6 +96,6 @@ class TssUser {
[string]
$Username

[datetime]
[Nullable[datetime]]
$VerifyEmailSentDate
}
Expand Up @@ -102,12 +102,7 @@ function Search-DistributedEngineSite {
Write-Warning 'No Distributed Engine Sites found'
}
if ($restResponse.records) {
foreach ($record in $restResponse.records) {
if (-not $record.lastActivity) {
$record.lastActivity = [datetime]::MinValue
}
[TssSiteSummary]$record
}
[TssSiteSummary[]]$record
}
} else {
Write-Warning 'No valid session found'
Expand Down
4 changes: 0 additions & 4 deletions src/functions/secrets/Get-SecretHeartbeatStatus.ps1
Expand Up @@ -59,10 +59,6 @@ function Get-SecretHeartbeatStatus {
. $ErrorHandling $err
}

if ($null -eq $restResponse.LastHeartbeatCheck) {
$restResponse.lastHeartbeatCheck = [datetime]::MinValue
}

if ($restResponse) {
[TssSecretHeartbeatStatus]$restResponse
}
Expand Down
4 changes: 0 additions & 4 deletions src/functions/secrets/Get-SecretSetting.ps1
Expand Up @@ -59,10 +59,6 @@ function Get-SecretSetting {
. $ErrorHandling $err
}

if (-not $restResponse.ExpirationDate) {
$restResponse.ExpirationDate = [datetime]::MinValue
}

if ($restResponse) {
[TssSecretDetailSettings]$restResponse
}
Expand Down
9 changes: 0 additions & 9 deletions src/functions/secrets/Get-SecretSummary.ps1
Expand Up @@ -60,15 +60,6 @@ function Get-SecretSummary {
}

if ($restResponse) {
if (-not $restResponse.lastPasswordChangeAttempt) {
$restResponse.lastPasswordChangeAttempt = [datetime]::MinValue
}
if (-not $restResponse.lastAccessed) {
$restResponse.lastAccessed = [datetime]::MinValue
}
if (-not $restResponse.createDate) {
$restResponse.createDate = [datetime]::MinValue
}
[TssSecretSummary]$restResponse
}
}
Expand Down
14 changes: 1 addition & 13 deletions src/functions/secrets/Search-Secret.ps1
Expand Up @@ -285,19 +285,7 @@ function Search-Secret {
}

if ($restResponse.records) {
foreach ($secret in $restResponse.records) {
if (-not $restResponse.lastPasswordChangeAttempt) {
$secret.lastPasswordChangeAttempt = [datetime]::MinValue
}
if (-not $restResponse.lastAccessed) {
$secret.lastAccessed = [datetime]::MinValue
}
if (-not $restResponse.createDate) {
$secret.createDate = [datetime]::MinValue
}

[TssSecretSummary]$secret
}
[TssSecretSummary[]]$secret
}
} else {
Write-Warning 'No valid session found'
Expand Down
18 changes: 0 additions & 18 deletions src/functions/users/Get-User.ps1
Expand Up @@ -62,24 +62,6 @@ function Get-User {
. $ErrorHandling $err
}

if (-not $restResponse.verifyEmailSentDate) {
$restResponse.verifyEmailSentDate = [datetime]::MinValue
}
if (-not $restResponse.passwordLastChanged) {
$restResponse.passwordLastChanged = [datetime]::MinValue
}
if (-not $restResponse.adAccountExpires) {
$restResponse.adAccountExpires = [datetime]::MinValue
}
if (-not $restResponse.resetSessionStarted) {
$restResponse.resetSessionStarted = [datetime]::MinValue
}
if (-not $restResponse.LastSessionActivity) {
$restResponse.LastSessionActivity = [datetime]::MinValue
}
if (-not $restResponse.lastLogin) {
$restResponse.LastLogin = [datetime]::MinValue
}
if ($restResponse) {
[TssUser]$restResponse
}
Expand Down
4 changes: 2 additions & 2 deletions src/functions/users/New-User.ps1
Expand Up @@ -117,10 +117,10 @@ function New-User {
}
}

$invokeParams.Body = ($newBody | ConvertTo-Json)
$invokeParams.Body = ($newBody | ConvertTo-Json -Depth 100)

Write-Verbose "Performing the operation $($invokeParams.Method) $uri with:`n $newBody"
if (-not $PSCmdlet.ShouldProcess('', "$($invokeParams.Method) $uri with $($invokeParams.Body)")) { return }
if (-not $PSCmdlet.ShouldProcess("User: $Username", "$($invokeParams.Method) $uri with $($invokeParams.Body)")) { return }
try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Expand Down
14 changes: 1 addition & 13 deletions src/parts/SearchSecrets.ps1
Expand Up @@ -44,18 +44,6 @@ process {
}

if ($restResponse.records) {
foreach ($secret in $restResponse.records) {
if (-not $restResponse.lastPasswordChangeAttempt) {
$secret.lastPasswordChangeAttempt = [datetime]::MinValue
}
if (-not $restResponse.lastAccessed) {
$secret.lastAccessed = [datetime]::MinValue
}
if (-not $restResponse.createDate) {
$secret.createDate = [datetime]::MinValue
}

[TssSecretSummary]$secret
}
[TssSecretSummary[]]$secret
}
}

0 comments on commit 20a41e7

Please sign in to comment.