Skip to content

Commit

Permalink
module - applying formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed May 29, 2021
1 parent 30be289 commit 71fa1f7
Show file tree
Hide file tree
Showing 95 changed files with 685 additions and 685 deletions.
2 changes: 1 addition & 1 deletion src/functions/Get-Version.ps1
Expand Up @@ -45,7 +45,7 @@ function Get-Version {
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $TssVersionObject -TssSession $TssSession -Invocation $PSCmdlet.MyInvocation
} else {
Write-Warning "No valid session found"
Write-Warning 'No valid session found'
}
}
}
124 changes: 62 additions & 62 deletions src/functions/Invoke-RestApi.ps1
Expand Up @@ -30,7 +30,7 @@ function Invoke-RestApi {
[Cmdletbinding()]
param(
# Secret Server REST API URL
[Parameter(Mandatory,ValueFromPipelineByPropertyName, Position = 0)]
[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position = 0)]
[Alias('Url')]
[uri]
$Uri,
Expand All @@ -43,7 +43,7 @@ function Invoke-RestApi {

# Method used for the web request, supported by Secret Server
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateSet('GET','DELETE', 'PATCH', 'POST', 'PUT')]
[ValidateSet('GET', 'DELETE', 'PATCH', 'POST', 'PUT')]
[string]
$Method,

Expand Down Expand Up @@ -142,72 +142,72 @@ function Invoke-RestApi {
# We call Invoke-RestMethod with the parameters we've passed in.
# It will take care of converting the results from JSON.
Invoke-RestMethod @irmSplat |
& { process {
$in = $_
# What it will not do is "unroll" them.
if ($in -eq 'null') {
return
}
if ($ExpandProperty) {
if ($in.$ExpandProperty) {
$in.$ExpandProperty
& { process {
$in = $_
# What it will not do is "unroll" them.
if ($in -eq 'null') {
return
}
} elseif ($in.PSObject.Properties['Value'] -and $in.Count) {
# If that's what we're dealing with
$_.Value # pass value down the pipe.
} elseif ($in.code -like '*API_*') {
$PSCmdlet.WriteError(
[Management.Automation.ErrorRecord]::new(
[Exception]::new("$($in.message)"),"$($in.code)","InvalidOperation",$in))
$PSCmdlet.WriteVerbose("$in")
return
} elseif ($in -notlike '*<html*') {
# Otherwise, As long as the value doesn't look like HTML,
$_ # pass it down the pipe.
} else {
# If it happened to look like HTML, write an error
$PSCmdlet.WriteError(
[Management.Automation.ErrorRecord]::new(
[Exception]::new("Response was HTML, Request Failed."),
"ResultWasHTML", "NotSpecified", $in))
$PSCmdlet.WriteVerbose("$in") # and write the full content to verbose.
return
}
# Redirect standard error (2) to same place as standard output (1)
} } 2>&1 |
& { process {
# One more step of the pipeline will unroll each of the values.
if ($_ -is [string]) { return $_ }
if ($null -ne $_.Count -and $_.Count -eq 0) { return }
if ($PSTypeName -and # If we have a PSTypeName (to apply formatting)
$_ -isnot [Management.Automation.ErrorRecord] # and it is not an error (which we do not want to format)
) {
$_.PSTypeNames.Clear() # then clear the existing typenames and decorate the object.
foreach ($t in $PSTypeName) {
$_.PSTypeNames.add($T)
if ($ExpandProperty) {
if ($in.$ExpandProperty) {
$in.$ExpandProperty
}
} elseif ($in.PSObject.Properties['Value'] -and $in.Count) {
# If that's what we're dealing with
$_.Value # pass value down the pipe.
} elseif ($in.code -like '*API_*') {
$PSCmdlet.WriteError(
[Management.Automation.ErrorRecord]::new(
[Exception]::new("$($in.message)"), "$($in.code)", 'InvalidOperation', $in))
$PSCmdlet.WriteVerbose("$in")
return
} elseif ($in -notlike '*<html*') {
# Otherwise, As long as the value doesn't look like HTML,
$_ # pass it down the pipe.
} else {
# If it happened to look like HTML, write an error
$PSCmdlet.WriteError(
[Management.Automation.ErrorRecord]::new(
[Exception]::new('Response was HTML, Request Failed.'),
'ResultWasHTML', 'NotSpecified', $in))
$PSCmdlet.WriteVerbose("$in") # and write the full content to verbose.
return
}
# Redirect standard error (2) to same place as standard output (1)
} } 2>&1 |
& { process {
# One more step of the pipeline will unroll each of the values.
if ($_ -is [string]) { return $_ }
if ($null -ne $_.Count -and $_.Count -eq 0) { return }
if ($PSTypeName -and # If we have a PSTypeName (to apply formatting)
$_ -isnot [Management.Automation.ErrorRecord] # and it is not an error (which we do not want to format)
) {
$_.PSTypeNames.Clear() # then clear the existing typenames and decorate the object.
foreach ($t in $PSTypeName) {
$_.PSTypeNames.add($T)
}
}
}

if ($Property) {
foreach ($propKeyValue in $Property.GetEnumerator()) {
if ($_.PSObject.Properties[$propKeyValue.Key]) {
$_.PSObject.Properties.Remove($propKeyValue.Key)
if ($Property) {
foreach ($propKeyValue in $Property.GetEnumerator()) {
if ($_.PSObject.Properties[$propKeyValue.Key]) {
$_.PSObject.Properties.Remove($propKeyValue.Key)
}
$_.PSObject.Properties.Add($(
if ($propKeyValue.Value -as [ScriptBlock[]]) {
[PSScriptProperty]::new.Invoke(@($propKeyValue.Key) + $propKeyValue.Value)
} else {
[PSNoteProperty]::new($propKeyValue.Key, $propKeyValue.Value)
}))
}
$_.PSObject.Properties.Add($(
if ($propKeyValue.Value -as [ScriptBlock[]]) {
[PSScriptProperty]::new.Invoke(@($propKeyValue.Key) + $propKeyValue.Value)
} else {
[PSNoteProperty]::new($propKeyValue.Key, $propKeyValue.Value)
}))
}
}
if ($RemoveProperty) {
foreach ($propToRemove in $RemoveProperty) {
$_.PSObject.Properties.Remove($propToRemove)
if ($RemoveProperty) {
foreach ($propToRemove in $RemoveProperty) {
$_.PSObject.Properties.Remove($propToRemove)
}
}
}
return $_ # output the object and we're done.
} }
return $_ # output the object and we're done.
} }
#endregion Call Invoke-RestMethod
}
}
2 changes: 1 addition & 1 deletion src/functions/Test-Version.ps1
Expand Up @@ -39,7 +39,7 @@ function Test-Version {
if ($tssParams.ContainsKey('TssSession') -and $TssSession.IsValidSession()) {
. $TssVersionObject -TssSession $TssSession -Invocation $PSCmdlet.MyInvocation
} else {
Write-Warning "No valid session found"
Write-Warning 'No valid session found'
}
}
}
6 changes: 3 additions & 3 deletions src/functions/auth/Initialize-SdkClient.ps1
Expand Up @@ -60,7 +60,7 @@ function Initialize-SdkClient {
$tssExe = [IO.Path]::Combine([string]$PSModuleRoot, 'bin', 'tss.exe')

if ($IsLinux) {
Write-Verbose "SDK Client, tss utility, has some dependencies required on certain Linux distributions, more details: https://docs.thycotic.com/ss/10.9.0/api-scripting/sdk-cli#task_2__installing_the_sdk_client"
Write-Verbose 'SDK Client, tss utility, has some dependencies required on certain Linux distributions, more details: https://docs.thycotic.com/ss/10.9.0/api-scripting/sdk-cli#task_2__installing_the_sdk_client'
}
}
process {
Expand All @@ -85,7 +85,7 @@ function Initialize-SdkClient {

Write-Verbose "SDK Client raw output: $tssRmOutput"
if ($tssRmOutput -match 'Your configuration settings have been removed.') {
Write-Verbose "SDK Client configuration has been removed"
Write-Verbose 'SDK Client configuration has been removed'
} else {
Write-Waring "Issue removing configuration files for [$SecretServer]: $tssRmProcessOutput"
return
Expand Down Expand Up @@ -126,7 +126,7 @@ function Initialize-SdkClient {
Write-Host 'SDK Client initialization completed successfully'
}
if ($tssInitOutput -match 'This machine is already initialized. Remove the configuration settings.') {
Write-Warning "Initialization has already been run for this host, include -Force parameter if you want to drop and reinitialize"
Write-Warning 'Initialization has already been run for this host, include -Force parameter if you want to drop and reinitialize'
}
} catch {
Write-Warning "Issue initializing SDK Client (tss) for [$SecretServer]"
Expand Down
30 changes: 15 additions & 15 deletions src/functions/auth/New-Session.ps1
Expand Up @@ -57,35 +57,35 @@ function New-Session {
[OutputType('TssSession')]
param(
# Secret Server URL
[Parameter(Mandatory,ParameterSetName = 'new', Position = 0)]
[Parameter(Mandatory,ParameterSetName = 'sdk', Position = 0)]
[Parameter(Mandatory,ParameterSetName = 'winauth', Position = 0)]
[Parameter(Mandatory,ParameterSetName = 'clientSdk')]
[Parameter(Mandatory, ParameterSetName = 'new', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'sdk', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'winauth', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'clientSdk')]
[uri]
$SecretServer,

# Specify a Secret Server user account.
[Parameter(Mandatory,ParameterSetName = 'new', Position = 1)]
[Parameter(Mandatory, ParameterSetName = 'new', Position = 1)]
[PSCredential]
[Management.Automation.CredentialAttribute()]
$Credential,

# Specify Access Token
[Parameter(Mandatory,ParameterSetName = 'sdk')]
[Parameter(Mandatory, ParameterSetName = 'sdk')]
$AccessToken,

# Utilize Windows Authentication (IWA)
[Parameter(Mandatory,ParameterSetName = 'winauth')]
[Parameter(Mandatory, ParameterSetName = 'winauth')]
[switch]
$UseWindowsAuth,

# Utilize SDK Client
[Parameter(Mandatory,ParameterSetName = 'clientSdk')]
[Parameter(Mandatory, ParameterSetName = 'clientSdk')]
[switch]
$UseSdkClient,

# Config path for the key/config files
[Parameter(ParameterSetName = 'clientSdk',Mandatory)]
[Parameter(ParameterSetName = 'clientSdk', Mandatory)]
[ValidateScript( { Test-Path $_ -PathType Container })]
[string]
$ConfigPath
Expand All @@ -96,8 +96,8 @@ function New-Session {

$outputTssSession = [TssSession]::new()

if ($SecretServer -match "(?:\/api\/v1)|(?:\/oauth2\/token)") {
throw "Invalid argument on parameter SecretServer. Please ensure [/api/v1] or [/oauth2/token] are not provided"
if ($SecretServer -match '(?:\/api\/v1)|(?:\/oauth2\/token)') {
throw 'Invalid argument on parameter SecretServer. Please ensure [/api/v1] or [/oauth2/token] are not provided'
return
} else {
$outputTssSession.SecretServer = $SecretServer
Expand Down Expand Up @@ -140,7 +140,7 @@ function New-Session {
if ($err.Length -gt 0) {
throw $err
} elseif ($_ -like '*<html*') {
$PSCmdlet.WriteError([Management.Automation.ErrorRecord]::new([Exception]::new("Response was HTML, Request Failed."),"ResultWasHTML", "NotSpecified", $invokeParams.Uri))
$PSCmdlet.WriteError([Management.Automation.ErrorRecord]::new([Exception]::new('Response was HTML, Request Failed.'), 'ResultWasHTML', 'NotSpecified', $invokeParams.Uri))
} else {
throw $_.Exception
}
Expand Down Expand Up @@ -177,7 +177,7 @@ function New-Session {
$tssStatusOutput += $tssProcess.StandardError.ReadToEnd()

Write-Verbose "SDK Client raw response: $tssStatusOutput"
$sdkEndpoint = $tssStatusOutput.Trim("Connected to endpoint ")
$sdkEndpoint = $tssStatusOutput.Trim('Connected to endpoint ')
} catch {
Write-Warning "Issue capturing status of current SDK Client (tss) config for [$SecretServer]"
$err = $_
Expand Down Expand Up @@ -207,7 +207,7 @@ function New-Session {
$sdkToken = $tssTokenOutput
Write-Verbose "SDK Client token value: $sdkToken"
} catch {
Write-Warning "Issue obtaining token via SDK Client (tss) config"
Write-Warning 'Issue obtaining token via SDK Client (tss) config'
$err = $_
. $ErrorHandling $err
}
Expand All @@ -232,7 +232,7 @@ function New-Session {
}
return $outputTssSession
} else {
Write-Warning "SecretServer argument not found"
Write-Warning 'SecretServer argument not found'
}
}
}
24 changes: 12 additions & 12 deletions src/functions/configurations/Get-Configuration.ps1
Expand Up @@ -25,12 +25,12 @@ function Get-Configuration {
[OutputType('TssConfigurationGeneral')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[TssSession]
$TssSession,

# Configuration type (Application, Email, Folders, Launcher, LocalUserPasswords, PermissionOptions, UserExperience, UserInterface)
[ValidateSet('All','Application', 'Email', 'Folders', 'Launcher', 'LocalUserPasswords', 'PermissionOptions', 'UserExperience', 'UserInterface')]
[ValidateSet('All', 'Application', 'Email', 'Folders', 'Launcher', 'LocalUserPasswords', 'PermissionOptions', 'UserExperience', 'UserInterface')]
[string]
$Type = 'All'
)
Expand All @@ -48,17 +48,17 @@ function Get-Configuration {

$uriParams = @()
if ($Type -eq 'All') {
$params = "loadAll=true"
$params = 'loadAll=true'
} else {
switch ($Type) {
'Application' { $uriParams += "loadApplicationSettings=true" }
'Email' { $uriParams += "loadEmail=true" }
'Folders' { $uriParams += "loadFolders=true" }
'Launcher' { $uriParams += "loadLauncherSettings=true" }
'LocalUserPasswords' { $uriParams += "loadLocalUserPasswords=true" }
'PermissionOptions' { $uriParams += "loadPermissionOptions=true" }
'UserExperience' { $uriParams += "loadUserExperience=true" }
'UserInterface' { $uriParams += "loadUserInterface=true" }
'Application' { $uriParams += 'loadApplicationSettings=true' }
'Email' { $uriParams += 'loadEmail=true' }
'Folders' { $uriParams += 'loadFolders=true' }
'Launcher' { $uriParams += 'loadLauncherSettings=true' }
'LocalUserPasswords' { $uriParams += 'loadLocalUserPasswords=true' }
'PermissionOptions' { $uriParams += 'loadPermissionOptions=true' }
'UserExperience' { $uriParams += 'loadUserExperience=true' }
'UserInterface' { $uriParams += 'loadUserInterface=true' }
}
$params = $uriParams -join '&'
}
Expand All @@ -78,7 +78,7 @@ function Get-Configuration {
[TssConfigurationGeneral]$restResponse
}
} else {
Write-Warning "No valid session found"
Write-Warning 'No valid session found'
}
}
}
Expand Up @@ -25,12 +25,12 @@ function Search-DirectoryServiceDomain {
[OutputType('TssDomainSummary')]
param (
# TssSession object created by New-TssSession for auth
[Parameter(Mandatory,ValueFromPipeline,Position = 0)]
[Parameter(Mandatory, ValueFromPipeline, Position = 0)]
[TssSession]
$TssSession,

# Domain Name
[Alias("Domain")]
[Alias('Domain')]
[int]
$DomainName,

Expand Down Expand Up @@ -74,19 +74,19 @@ function Search-DirectoryServiceDomain {
try {
$restResponse = . $InvokeApi @invokeParams
} catch {
Write-Warning "Issue on search request"
Write-Warning 'Issue on search request'
$err = $_
. $ErrorHandling $err
}

if ($restResponse.records.Count -le 0 -and $restResponse.records.Length -eq 0) {
Write-Warning "No Directory Domain found"
Write-Warning 'No Directory Domain found'
}
if ($restResponse.records) {
[TssDomainSummary[]]$restResponse.records
}
} else {
Write-Warning "No valid session found"
Write-Warning 'No valid session found'
}
}
}

0 comments on commit 71fa1f7

Please sign in to comment.