Updating SaltStackConfig module
Updated functions based on comments in PR502. Updated manifest to include Get-SscActivity (previously Get-SscCommand) and reference to new Format.ps1xml, which contains custom formatting for the Connect-SscServer output. Signed-off-by: Brian Wuchner <brian.wuchner@gmail.com>
This commit is contained in:
41
Modules/SaltStackConfig/SaltStackConfig.Format.ps1xml
Normal file
41
Modules/SaltStackConfig/SaltStackConfig.Format.ps1xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<Configuration>
|
||||||
|
<ViewDefinitions>
|
||||||
|
<View>
|
||||||
|
<Name>SscConnection</Name>
|
||||||
|
<ViewSelectedBy>
|
||||||
|
<TypeName>SscConnection</TypeName>
|
||||||
|
</ViewSelectedBy>
|
||||||
|
<TableControl>
|
||||||
|
<TableHeaders>
|
||||||
|
<TableColumnHeader>
|
||||||
|
<Width>25</Width>
|
||||||
|
<Label>Server Name</Label>
|
||||||
|
</TableColumnHeader>
|
||||||
|
<TableColumnHeader>
|
||||||
|
<Width>25</Width>
|
||||||
|
<Label>Connected As</Label>
|
||||||
|
</TableColumnHeader>
|
||||||
|
<TableColumnHeader>
|
||||||
|
<Label>Authenticated</Label>
|
||||||
|
</TableColumnHeader>
|
||||||
|
</TableHeaders>
|
||||||
|
<TableRowEntries>
|
||||||
|
<TableRowEntry>
|
||||||
|
<TableColumnItems>
|
||||||
|
<TableColumnItem>
|
||||||
|
<PropertyName>SscServer</PropertyName>
|
||||||
|
</TableColumnItem>
|
||||||
|
<TableColumnItem>
|
||||||
|
<ScriptBlock>$_.ConnectionDetail.attributes.config_name +'\'+ $_.ConnectionDetail.attributes.username</ScriptBlock>
|
||||||
|
</TableColumnItem>
|
||||||
|
<TableColumnItem>
|
||||||
|
<ScriptBlock>$_.ConnectionDetail.authenticated</ScriptBlock>
|
||||||
|
</TableColumnItem>
|
||||||
|
</TableColumnItems>
|
||||||
|
</TableRowEntry>
|
||||||
|
</TableRowEntries>
|
||||||
|
</TableControl>
|
||||||
|
</View>
|
||||||
|
</ViewDefinitions>
|
||||||
|
</Configuration>
|
||||||
@@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause
|
|||||||
RootModule = 'SaltStackConfig.psm1'
|
RootModule = 'SaltStackConfig.psm1'
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '0.0.3'
|
ModuleVersion = '0.0.4'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
# CompatiblePSEditions = @()
|
# CompatiblePSEditions = @()
|
||||||
@@ -68,13 +68,13 @@ PowerShellVersion = '4.0'
|
|||||||
# TypesToProcess = @()
|
# TypesToProcess = @()
|
||||||
|
|
||||||
# Format files (.ps1xml) to be loaded when importing this module
|
# Format files (.ps1xml) to be loaded when importing this module
|
||||||
# FormatsToProcess = @()
|
FormatsToProcess = @('SaltStackConfig.Format.ps1xml')
|
||||||
|
|
||||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||||
# NestedModules = @()
|
# NestedModules = @()
|
||||||
|
|
||||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||||
FunctionsToExport = @('Connect-SscServer', 'Disconnect-SscServer', 'Get-SscCommand', 'Get-SscData', 'Get-SscJob', 'Get-SscMaster', 'Get-SscMinionCache', 'Get-SscReturn', 'Get-SscSchedule')
|
FunctionsToExport = @('Connect-SscServer', 'Disconnect-SscServer', 'Get-SscActivity', 'Get-SscData', 'Get-SscJob', 'Get-SscMaster', 'Get-SscMinionCache', 'Get-SscReturn', 'Get-SscSchedule')
|
||||||
|
|
||||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||||
CmdletsToExport = @()
|
CmdletsToExport = @()
|
||||||
@@ -125,4 +125,3 @@ PrivateData = @{
|
|||||||
# DefaultCommandPrefix = ''
|
# DefaultCommandPrefix = ''
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,10 @@ Function Connect-SscServer {
|
|||||||
$ws.headers.Add('X-Xsrftoken', $webRequest.headers.'x-xsrftoken')
|
$ws.headers.Add('X-Xsrftoken', $webRequest.headers.'x-xsrftoken')
|
||||||
$webRequest = Invoke-WebRequest -Uri "https://$server/account/login" -WebSession $ws -method POST -body (ConvertTo-Json $loginBody)
|
$webRequest = Invoke-WebRequest -Uri "https://$server/account/login" -WebSession $ws -method POST -body (ConvertTo-Json $loginBody)
|
||||||
$webRequestJson = ConvertFrom-JSON $webRequest.Content
|
$webRequestJson = ConvertFrom-JSON $webRequest.Content
|
||||||
$global:DefaultSscConnection = New-Object psobject -property @{ "SscWebSession"=$ws; "SscServer"=$server; "ConnectionDetail"=$webRequestJson }
|
$global:DefaultSscConnection = New-Object psobject -property @{ "SscWebSession"=$ws; "SscServer"=$server; "ConnectionDetail"=$webRequestJson; PSTypeName='SscConnection' }
|
||||||
|
|
||||||
# Return a few grains, like the Salt server & version; this will prove the connection worked & provide some context
|
# Return the connection object
|
||||||
Get-SscMaster | Select-Object Host, NodeName, SaltVersion, @{N='Authenticated';E={$global:DefaultSscConnection.ConnectionDetail.authenticated}},
|
$global:DefaultSscConnection
|
||||||
@{N='AuthType';E={$global:DefaultSscConnection.ConnectionDetail.attributes.config_driver}}, @{N='AuthSource';E={$global:DefaultSscConnection.ConnectionDetail.attributes.config_name}},
|
|
||||||
@{N='UserName';E={$global:DefaultSscConnection.ConnectionDetail.attributes.username}}, @{N='Permissions';E={[string]::Join(', ', $global:DefaultSscConnection.ConnectionDetail.attributes.permissions)}}
|
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error ("Failure connecting to $server. " + $_)
|
Write-Error ("Failure connecting to $server. " + $_)
|
||||||
} # end try/catch block
|
} # end try/catch block
|
||||||
@@ -107,7 +105,12 @@ Function Get-SscData {
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
$output = Invoke-WebRequest -WebSession $global:DefaultSscConnection.SscWebSession -Method POST -Uri "https://$($global:DefaultSscConnection.SscServer)/rpc" -body $(ConvertTo-Json $body) -ContentType 'application/json'
|
$output = Invoke-WebRequest -WebSession $global:DefaultSscConnection.SscWebSession -Method POST -Uri "https://$($global:DefaultSscConnection.SscServer)/rpc" -body $(ConvertTo-Json $body) -ContentType 'application/json'
|
||||||
return (ConvertFrom-Json $output.Content)
|
$outputJson = (ConvertFrom-Json $output.Content)
|
||||||
|
|
||||||
|
if ($outputJson.error) { Write-Error $outputJson.error }
|
||||||
|
if ($outputJson.warnings) { Write-Warning $outputJson.warnings }
|
||||||
|
return $outputJson.ret
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
Write-Error $_.Exception.Message
|
Write-Error $_.Exception.Message
|
||||||
}
|
}
|
||||||
@@ -132,17 +135,7 @@ Function Get-SscMaster {
|
|||||||
PS C:\> Get-SscMaster
|
PS C:\> Get-SscMaster
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
(Get-SscData master get_master_grains).salt.grains
|
||||||
[ValidateSet('Json','Results')][string]$Output='Results'
|
|
||||||
)
|
|
||||||
|
|
||||||
$data = Get-SscData master get_master_grains
|
|
||||||
|
|
||||||
if ($Output -eq 'Results') {
|
|
||||||
$data.ret.salt.grains
|
|
||||||
} else {
|
|
||||||
$data
|
|
||||||
} # end if for results parameter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-SscMinionCache {
|
Function Get-SscMinionCache {
|
||||||
@@ -161,17 +154,8 @@ Function Get-SscMinionCache {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-SscMinion
|
PS C:\> Get-SscMinion
|
||||||
#>
|
#>
|
||||||
param(
|
|
||||||
[ValidateSet('Json','Results')][string]$Output='Results'
|
|
||||||
)
|
|
||||||
|
|
||||||
$data = Get-SscData minions get_minion_cache
|
(Get-SscData minions get_minion_cache).results
|
||||||
|
|
||||||
if ($Output -eq 'Results') {
|
|
||||||
$data.ret.results
|
|
||||||
} else {
|
|
||||||
$data
|
|
||||||
} # end if for results parameter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-SscJob {
|
Function Get-SscJob {
|
||||||
@@ -190,17 +174,8 @@ Function Get-SscJob {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-SscJob
|
PS C:\> Get-SscJob
|
||||||
#>
|
#>
|
||||||
param(
|
|
||||||
[ValidateSet('Json','Results')][string]$Output='Results'
|
|
||||||
)
|
|
||||||
|
|
||||||
$data = Get-SscData job get_jobs
|
(Get-SscData job get_jobs).results
|
||||||
|
|
||||||
if ($Output -eq 'Results') {
|
|
||||||
$data.ret.results
|
|
||||||
} else {
|
|
||||||
$data
|
|
||||||
} # end if for results parameter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-SscSchedule {
|
Function Get-SscSchedule {
|
||||||
@@ -219,17 +194,8 @@ Function Get-SscSchedule {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-SscSchedule
|
PS C:\> Get-SscSchedule
|
||||||
#>
|
#>
|
||||||
param(
|
|
||||||
[ValidateSet('Json','Results')][string]$Output='Results'
|
|
||||||
)
|
|
||||||
|
|
||||||
$data = Get-SscData schedule get
|
(Get-SscData schedule get).results
|
||||||
|
|
||||||
if ($Output -eq 'Results') {
|
|
||||||
$data.ret.results
|
|
||||||
} else {
|
|
||||||
$data
|
|
||||||
} # end if for results parameter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-SscReturn {
|
Function Get-SscReturn {
|
||||||
@@ -251,33 +217,22 @@ Function Get-SscReturn {
|
|||||||
PS C:\> Get-SscReturn -Jid '20211122160147314949'
|
PS C:\> Get-SscReturn -Jid '20211122160147314949'
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-SscReturn -MinionID 't147-win22-01.lab.enterpriseadmins.org'
|
PS C:\> Get-SscReturn -MinionID 't147-win22-01.lab.enterpriseadmins.org'
|
||||||
|
.EXAMPLE
|
||||||
|
PS C:\> Get-SscReturn -MinionID 't147-win22-01.lab.enterpriseadmins.org' -Jid '20211122160147314949'
|
||||||
#>
|
#>
|
||||||
param(
|
param(
|
||||||
[ValidateSet('Json','Results')][string]$Output='Results',
|
[string]$jid,
|
||||||
[string]$jid,
|
[string]$MinionID
|
||||||
[string]$minionid
|
|
||||||
)
|
)
|
||||||
# ToDo: This should be a parameterset, was having trouble with making the parameters optional. Use if statement for now
|
|
||||||
if ($jid -and $minionid) { Write-Warning 'Please only specify JID or MinionID, not both.'; return; }
|
|
||||||
|
|
||||||
if ($jid) {
|
$kwarg = @{}
|
||||||
$kwarg = @{'jid'=$jid}
|
if ($jid) { $kwarg += @{'jid'=$jid} }
|
||||||
} elseif ($minionid) {
|
if ($MinionID) { $kwarg += @{'minion_id'=$MinionID} }
|
||||||
$kwarg = @{'minion_id'=$minionid}
|
|
||||||
} else {
|
|
||||||
$kwarg = $null
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = Get-SscData ret get_returns $kwarg
|
(Get-SscData ret get_returns $kwarg).results
|
||||||
|
|
||||||
if ($Output -eq 'Results') {
|
|
||||||
$data.ret.results
|
|
||||||
} else {
|
|
||||||
$data
|
|
||||||
} # end if for results parameter
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Function Get-SscCommand {
|
Function Get-SscActivity {
|
||||||
<#
|
<#
|
||||||
.NOTES
|
.NOTES
|
||||||
===========================================================================
|
===========================================================================
|
||||||
@@ -288,20 +243,12 @@ Function Get-SscCommand {
|
|||||||
===========================================================================
|
===========================================================================
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
This wrapper function will return SaltStack Config commands that have been issued.
|
This wrapper function will return SaltStack Config commands that have been issued.
|
||||||
|
In the web interface this is similar to the Activity button.
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This wrapper function will call Get-SscData cmd.get_cmds.
|
This wrapper function will call Get-SscData cmd.get_cmds.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS C:\> Get-SscCommand
|
PS C:\> Get-SscActivity
|
||||||
#>
|
#>
|
||||||
param(
|
|
||||||
[ValidateSet('Json','Results')][string]$Output='Results'
|
|
||||||
)
|
|
||||||
|
|
||||||
$data = Get-SscData cmd get_cmds
|
(Get-SscData cmd get_cmds).results
|
||||||
|
|
||||||
if ($Output -eq 'Results') {
|
|
||||||
$data.ret.results
|
|
||||||
} else {
|
|
||||||
$data
|
|
||||||
} # end if for results parameter
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user