mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-20 00:02:19 +00:00
set/get state from powershell client (#4838)
* set/get state from powershell client * format * removing unneccessary arg
This commit is contained in:
@@ -8,148 +8,150 @@
|
||||
|
||||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'WindmillClient.psm1'
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'WindmillClient.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.434.2'
|
||||
# Version number of this module.
|
||||
ModuleVersion = '1.434.2'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '8a2396f8-2582-400c-a762-cdd6a0699b0b'
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '8a2396f8-2582-400c-a762-cdd6a0699b0b'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Windmill Labs'
|
||||
# Author of this module
|
||||
Author = 'Windmill Labs'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Windmill Labs, Inc'
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Windmill Labs, Inc'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) Windmill Labs, Inc 2022'
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) Windmill Labs, Inc 2022'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Client for the Windmill platform.'
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'Client for the Windmill platform.'
|
||||
|
||||
# Minimum version of the PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
# Minimum version of the PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
|
||||
# Name of the PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
# Name of the PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
|
||||
# Minimum version of the PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
# Minimum version of the PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
|
||||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# DotNetFrameworkVersion = ''
|
||||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# DotNetFrameworkVersion = ''
|
||||
|
||||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# ClrVersion = ''
|
||||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# ClrVersion = ''
|
||||
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
# ScriptsToProcess = @()
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
# ScriptsToProcess = @()
|
||||
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
# NestedModules = @()
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
# 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.
|
||||
FunctionsToExport = @(
|
||||
'Connect-Windmill',
|
||||
'Disconnect-Windmill',
|
||||
'New-WindmillToken',
|
||||
'Get-WindmillIdToken',
|
||||
'Get-WindmillWorkspace',
|
||||
'Get-WindmillVersion',
|
||||
'Get-WindmillUser',
|
||||
'Get-WindmillVariable',
|
||||
'New-WindmillVariable',
|
||||
'Set-WindmillVariable',
|
||||
'Remove-WindmillVariable',
|
||||
'Get-WindmillResource',
|
||||
'New-WindmillResource',
|
||||
'Set-WindmillResource',
|
||||
'Remove-WindmillResource',
|
||||
'Invoke-WindmillScript',
|
||||
'Start-WindmillScript',
|
||||
'Start-WindmillFlow',
|
||||
'Stop-WindmillJob',
|
||||
'Wait-WindmillJob',
|
||||
'Stop-WindmillExecution',
|
||||
'Get-WindmillJob',
|
||||
'Get-WindmillResult')
|
||||
# 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-Windmill',
|
||||
'Disconnect-Windmill',
|
||||
'New-WindmillToken',
|
||||
'Get-WindmillIdToken',
|
||||
'Get-WindmillWorkspace',
|
||||
'Get-WindmillVersion',
|
||||
'Get-WindmillUser',
|
||||
'Get-WindmillVariable',
|
||||
'New-WindmillVariable',
|
||||
'Set-WindmillVariable',
|
||||
'Remove-WindmillVariable',
|
||||
'Get-WindmillResource',
|
||||
'Get-WindmillState',
|
||||
'New-WindmillResource',
|
||||
'Set-WindmillResource',
|
||||
'Set-WindmillState',
|
||||
'Remove-WindmillResource',
|
||||
'Invoke-WindmillScript',
|
||||
'Start-WindmillScript',
|
||||
'Start-WindmillFlow',
|
||||
'Stop-WindmillJob',
|
||||
'Wait-WindmillJob',
|
||||
'Stop-WindmillExecution',
|
||||
'Get-WindmillJob',
|
||||
'Get-WindmillResult')
|
||||
|
||||
# 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 = @()
|
||||
# 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 = @()
|
||||
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
|
||||
# Aliases 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 aliases to export.
|
||||
AliasesToExport = @()
|
||||
# Aliases 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 aliases to export.
|
||||
AliasesToExport = @()
|
||||
|
||||
# DSC resources to export from this module
|
||||
# DscResourcesToExport = @()
|
||||
# DSC resources to export from this module
|
||||
# DscResourcesToExport = @()
|
||||
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
|
||||
PSData = @{
|
||||
PSData = @{
|
||||
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
|
||||
# A URL to the license for this module.
|
||||
LicenseUri = 'https://github.com/windmill-labs/windmill/tree/main/LICENSE'
|
||||
# A URL to the license for this module.
|
||||
LicenseUri = 'https://github.com/windmill-labs/windmill/tree/main/LICENSE'
|
||||
|
||||
# A URL to the main website for this project.
|
||||
ProjectUri = 'https://github.com/windmill-labs/windmill/tree/main/powershell-client'
|
||||
# A URL to the main website for this project.
|
||||
ProjectUri = 'https://github.com/windmill-labs/windmill/tree/main/powershell-client'
|
||||
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
|
||||
# Prerelease string of this module
|
||||
# Prerelease = ''
|
||||
# Prerelease string of this module
|
||||
# Prerelease = ''
|
||||
|
||||
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
|
||||
# RequireLicenseAcceptance = $false
|
||||
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
|
||||
# RequireLicenseAcceptance = $false
|
||||
|
||||
# External dependent modules of this module
|
||||
# ExternalModuleDependencies = @()
|
||||
# External dependent modules of this module
|
||||
# ExternalModuleDependencies = @()
|
||||
|
||||
} # End of PSData hashtable
|
||||
} # End of PSData hashtable
|
||||
|
||||
} # End of PrivateData hashtable
|
||||
} # End of PrivateData hashtable
|
||||
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ Sets the value of specified resource
|
||||
#>
|
||||
function Set-WindmillResource {
|
||||
param(
|
||||
[string] $Path,
|
||||
[string] $Path = $null,
|
||||
[Hashtable] $Value,
|
||||
[string] $ResourceType = $null
|
||||
)
|
||||
@@ -204,10 +204,33 @@ function Set-WindmillResource {
|
||||
if (-not $script:WindmillConnection) {
|
||||
throw "Windmill connection not established. Run Connect-Windmill first."
|
||||
}
|
||||
|
||||
$script:WindmillConnection.SetResource($Path, $Value, $ResourceType)
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sets the value of a resource with type "state".
|
||||
#>
|
||||
function Set-WindmillState {
|
||||
param(
|
||||
[Hashtable] $Value
|
||||
)
|
||||
|
||||
if (-not $script:WindmillConnection) {
|
||||
throw "Windmill connection not established. Run Connect-Windmill first."
|
||||
}
|
||||
|
||||
$script:WindmillConnection.SetResource($script:WindmillConnection.GetStatePath(), $Value, "state")
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the value of a resource with type "state".
|
||||
#>
|
||||
function Get-WindmillState {
|
||||
Get-WindmillResource -Path $script:WindmillConnection.GetStatePath()
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Deletes a resource
|
||||
@@ -502,14 +525,20 @@ class Windmill {
|
||||
return $response.Content | ConvertFrom-Json
|
||||
}
|
||||
|
||||
[void] SetResource([string] $Path, [Hashtable] $Value, [string] $ResourceType) {
|
||||
$response = $this.Get("/w/$($this.Workspace)/resources/get/$Path", $false)
|
||||
|
||||
if ($response.StatusCode -eq 404) {
|
||||
throw "Resource $Path not found"
|
||||
[void] SetResource([string] $Path, [Hashtable] $Value, [string] $ResourceType) {
|
||||
# Resolve the effective path
|
||||
$resolvedPath = if ($Path) { $Path } else { $script:WindmillConnection.GetStatePath() }
|
||||
|
||||
if ($this.Get("/w/$($this.Workspace)/resources/exists/$resolvedPath", $false).Content -eq "true") {
|
||||
$this.Post("/w/$($this.Workspace)/resources/update_value/$resolvedPath", @{ "value" = $Value }, $true)
|
||||
}
|
||||
|
||||
elseif ($ResourceType) {
|
||||
$this.CreateResource($resolvedPath, $Value, $ResourceType)
|
||||
}
|
||||
|
||||
else {
|
||||
$this.Post("/w/$($this.Workspace)/resources/update_value/$Path", @{ "value" = $Value }, $true)
|
||||
throw "Resource at path $resolvedPath does not exist and no type was provided to initialize it"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,30 +674,46 @@ class Windmill {
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
[string] GetStatePath() {
|
||||
$statePath = $env:WM_STATE_PATH_NEW
|
||||
|
||||
if (-not $statePath) {
|
||||
$statePath = $env:WM_STATE_PATH
|
||||
}
|
||||
|
||||
if (-not $statePath) {
|
||||
throw "State path not set"
|
||||
}
|
||||
|
||||
return $statePath
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function @(
|
||||
'Connect-Windmill',
|
||||
'Disconnect-Windmill',
|
||||
'New-WindmillToken',
|
||||
'Get-WindmillIdToken',
|
||||
'Get-WindmillWorkspace',
|
||||
'Get-WindmillVersion',
|
||||
'Get-WindmillUser',
|
||||
'Get-WindmillVariable',
|
||||
'New-WindmillVariable',
|
||||
'Set-WindmillVariable',
|
||||
'Remove-WindmillVariable',
|
||||
'Get-WindmillResource',
|
||||
'New-WindmillResource',
|
||||
'Set-WindmillResource',
|
||||
'Remove-WindmillResource',
|
||||
'Invoke-WindmillScript',
|
||||
'Start-WindmillScript',
|
||||
'Start-WindmillFlow',
|
||||
'Stop-WindmillJob',
|
||||
'Wait-WindmillJob',
|
||||
'Stop-WindmillExecution',
|
||||
'Get-WindmillJob',
|
||||
'Get-WindmillResult'
|
||||
'Connect-Windmill',
|
||||
'Disconnect-Windmill',
|
||||
'New-WindmillToken',
|
||||
'Get-WindmillIdToken',
|
||||
'Get-WindmillWorkspace',
|
||||
'Get-WindmillVersion',
|
||||
'Get-WindmillUser',
|
||||
'Get-WindmillVariable',
|
||||
'New-WindmillVariable',
|
||||
'Set-WindmillVariable',
|
||||
'Remove-WindmillVariable',
|
||||
'Get-WindmillResource',
|
||||
'Get-WindmillState',
|
||||
'New-WindmillResource',
|
||||
'Set-WindmillResource',
|
||||
'Set-WindmillState',
|
||||
'Remove-WindmillResource',
|
||||
'Invoke-WindmillScript',
|
||||
'Start-WindmillScript',
|
||||
'Start-WindmillFlow',
|
||||
'Stop-WindmillJob',
|
||||
'Wait-WindmillJob',
|
||||
'Stop-WindmillExecution',
|
||||
'Get-WindmillJob',
|
||||
'Get-WindmillResult'
|
||||
)
|
||||
Reference in New Issue
Block a user