├── .gitignore ├── DocumentPowerShell.ps1 ├── Get-HelpByMarkdown.ps1 ├── LICENSE ├── README.md ├── St2.Client.PowerShell ├── BaseClientCmdlet.cs ├── GetActionsCmdlet.cs ├── GetExecutionsCmdlet.cs ├── GetPacksCmdlet.cs ├── GetRulesCmdlet.cs ├── InstallPackCmdlet.cs ├── InvokeActionCmdlet.cs ├── NewActionCmdlet.cs ├── NewActionParameterCmdlet.cs ├── NewSt2ClientConnection.cs ├── Properties │ └── AssemblyInfo.cs ├── RemoveActionCmdlet.cs ├── RemoveRuleCmdlet.cs ├── SessionStateExtensions.cs ├── St2.Client.Help.pshproj ├── St2.Client.PowerShell.csproj ├── St2.Client.PowerShell.csproj.user ├── St2.Client.PowerShell.dll-Help.xml ├── St2.Client.PowerShell.nuspec ├── St2.Client.psd1 └── St2ClientConnection.cs ├── St2.Client.sln ├── St2.Client ├── Apis │ ├── ActionsApi.cs │ ├── ExecutionsApi.cs │ ├── IActionsApi.cs │ ├── IExecutionsApi.cs │ ├── IPacksApi.cs │ ├── IRulesApi.cs │ ├── PacksApi.cs │ └── RulesApi.cs ├── AuthExtensions.cs ├── Exceptions │ ├── ExceptionFactory.cs │ ├── FailedRequestException.cs │ └── InvalidTokenException.cs ├── ISt2Client.cs ├── Models │ ├── Action.cs │ ├── ActionParameter.cs │ ├── CreateAction.cs │ ├── ExecuteActionRequest.cs │ ├── Execution.cs │ ├── ExecutionContext.cs │ ├── NamedActionParameter.cs │ ├── Pack.cs │ ├── ParameterType.cs │ ├── PayloadSchema.cs │ ├── Rule.cs │ ├── RuleAction.cs │ ├── RuleType.cs │ ├── Runner.cs │ ├── RunnerEnvironment.cs │ ├── RunnerParameter.cs │ ├── RunnerType.cs │ ├── TokenResponse.cs │ ├── Trigger.cs │ ├── TriggerInstance.cs │ └── TriggerType.cs ├── Properties │ └── AssemblyInfo.cs ├── St2.Client.csproj ├── St2.Client.nuspec ├── St2Client.cs └── packages.config ├── appveyor.yml ├── docs ├── St2.Client.md ├── index.md └── powershell │ ├── Get-St2Actions.md │ ├── Get-St2Executions.md │ ├── Get-St2Packs.md │ ├── Get-St2Rules.md │ ├── Install-St2Pack.md │ ├── Invoke-St2Action.md │ ├── New-St2Action.md │ ├── New-St2ActionParameter.md │ ├── New-St2ClientConnection.md │ ├── Remove-St2Action.md │ ├── Remove-St2Rule.md │ └── index.md ├── nuget ├── NuGet.exe ├── nuget-anycpu.exe └── pack.ps1 └── xmldoc2md ├── App.config ├── LICENSE ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── README.md ├── XmlDoc2MD.csproj ├── XmlDoc2MD.sln ├── xmldoc2md.md ├── xmldoc2md.ps1 └── xmldoc2md.xsl /.gitignore: -------------------------------------------------------------------------------- 1 | packages/ 2 | St2.Client/obj/ 3 | St2.Client.PowerShell/bin/ 4 | St2.Client.PowerShell/obj/ 5 | St2.Client/bin/ 6 | *.suo 7 | *.Cache 8 | -------------------------------------------------------------------------------- /DocumentPowerShell.ps1: -------------------------------------------------------------------------------- 1 | param ( 2 | [string] $apiKey 3 | ) 4 | 5 | Import-Module .\St2.Client.PowerShell\bin\Release\St2.Client.psd1 6 | $commands = Get-Command -Module St2.Client 7 | 8 | if((Test-Path ".\docs\powershell\") -eq 0){ 9 | mkdir ".\docs\powershell\"} 10 | foreach ($command in $commands){ 11 | .\Get-HelpByMarkdown.ps1 $command.name | Set-Content -Encoding utf8 .\docs\powershell\$command.md 12 | } 13 | $modPath = $Env:PSModulePath.split(';')[1] 14 | mkdir "$($modPath)\St2.Client" 15 | # Install the module 16 | Copy-Item .\St2.Client.PowerShell\bin\Release\*.* "$($modPath)\St2.Client" -Verbose 17 | 18 | # publish the module 19 | Publish-Module -NuGetApiKey $apiKey -Path "$($modPath)\St2.Client" -------------------------------------------------------------------------------- /Get-HelpByMarkdown.ps1: -------------------------------------------------------------------------------- 1 | # 2 | # File: Get-HelpByMarkdown.ps1 3 | # 4 | # Author: Akira Sugiura (urasandesu@gmail.com) 5 | # 6 | # 7 | # Copyright (c) 2014 Akira Sugiura 8 | # 9 | # This software is MIT License. 10 | # 11 | # Permission is hereby granted, free of charge, to any person obtaining a copy 12 | # of this software and associated documentation files (the "Software"), to deal 13 | # in the Software without restriction, including without limitation the rights 14 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | # copies of the Software, and to permit persons to whom the Software is 16 | # furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included in 19 | # all copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | # THE SOFTWARE. 28 | # 29 | 30 | <# 31 | .SYNOPSIS 32 | Gets the comment-based help and converts to GitHub Flavored Markdown. 33 | 34 | .PARAMETER Name 35 | A command name to get comment-based help. 36 | 37 | .EXAMPLE 38 | & .\Get-HelpByMarkdown.ps1 Select-Object > .\Select-Object.md 39 | 40 | DESCRIPTION 41 | ----------- 42 | This example gets comment-based help of `Select-Object` command, and converts GitHub Flavored Markdown format, then saves it to `Select-Object.md` in current directory. 43 | 44 | .INPUTS 45 | System.String 46 | 47 | .OUTPUTS 48 | System.String 49 | 50 | #> 51 | 52 | [CmdletBinding()] 53 | param ( 54 | [Parameter(Mandatory = $True)] 55 | $Name 56 | ) 57 | 58 | function EncodePartOfHtml { 59 | param ( 60 | [string] 61 | $Value 62 | ) 63 | 64 | ($Value -replace '<', '<') -replace '>', '>' 65 | } 66 | 67 | function GetCode { 68 | param ( 69 | $Example 70 | ) 71 | $codeAndRemarks = (($Example | Out-String) -replace ($Example.title), '').Trim() -split "`r`n" 72 | 73 | $code = New-Object "System.Collections.Generic.List[string]" 74 | for ($i = 0; $i -lt $codeAndRemarks.Length; $i++) { 75 | if ($codeAndRemarks[$i] -eq 'DESCRIPTION' -and $codeAndRemarks[$i + 1] -eq '-----------') { 76 | break 77 | } 78 | if (1 -le $i -and $i -le 2) { 79 | continue 80 | } 81 | $code.Add($codeAndRemarks[$i]) 82 | } 83 | 84 | $code -join "`r`n" 85 | } 86 | 87 | function GetRemark { 88 | param ( 89 | $Example 90 | ) 91 | $codeAndRemarks = (($Example | Out-String) -replace ($Example.title), '').Trim() -split "`r`n" 92 | 93 | $isSkipped = $false 94 | $remark = New-Object "System.Collections.Generic.List[string]" 95 | for ($i = 0; $i -lt $codeAndRemarks.Length; $i++) { 96 | if (!$isSkipped -and $codeAndRemarks[$i - 2] -ne 'DESCRIPTION' -and $codeAndRemarks[$i - 1] -ne '-----------') { 97 | continue 98 | } 99 | $isSkipped = $true 100 | $remark.Add($codeAndRemarks[$i]) 101 | } 102 | 103 | $remark -join "`r`n" 104 | } 105 | 106 | try { 107 | if ($Host.UI.RawUI) { 108 | $rawUI = $Host.UI.RawUI 109 | $oldSize = $rawUI.BufferSize 110 | $typeName = $oldSize.GetType().FullName 111 | $newSize = New-Object $typeName (500, $oldSize.Height) 112 | $rawUI.BufferSize = $newSize 113 | } 114 | 115 | $full = Get-Help $Name -Full 116 | 117 | @" 118 | $($full.Name) 119 | =================== 120 | 121 | ## SYNOPSIS 122 | $($full.Synopsis) 123 | 124 | ## SYNTAX 125 | ``````powershell 126 | $((($full.syntax | Out-String) -replace "`r`n", "`r`n`r`n").Trim()) 127 | `````` 128 | 129 | ## DESCRIPTION 130 | $(($full.description | Out-String).Trim()) 131 | 132 | ## PARAMETERS 133 | "@ + $(foreach ($parameter in $full.parameters.parameter) { 134 | @" 135 | 136 | ### -$($parameter.name) <$($parameter.type.name)> 137 | $(($parameter.description | Out-String).Trim()) 138 | `````` 139 | $(((($parameter | Out-String).Trim() -split "`r`n")[-5..-1] | % { $_.Trim() }) -join "`r`n") 140 | `````` 141 | 142 | "@ 143 | }) + @" 144 | 145 | ## INPUTS 146 | $($full.inputTypes.inputType.type.name) 147 | 148 | ## OUTPUTS 149 | $($full.returnValues.returnValue[0].type.name) 150 | 151 | ## NOTES 152 | $(($full.alertSet.alert | Out-String).Trim()) 153 | 154 | ## EXAMPLES 155 | "@ + $(foreach ($example in $full.examples.example) { 156 | @" 157 | 158 | ### $(($example.title -replace '-*', '').Trim()) 159 | ``````powershell 160 | $(GetCode $example) 161 | `````` 162 | $(GetRemark $example) 163 | 164 | "@ 165 | }) + @" 166 | 167 | "@ 168 | 169 | } finally { 170 | if ($Host.UI.RawUI) { 171 | $rawUI = $Host.UI.RawUI 172 | $rawUI.BufferSize = $oldSize 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # St2Client 2 | 3 | [![Build status](https://ci.appveyor.com/api/projects/status/y7rueuv6m1v0g7p8?svg=true)](https://ci.appveyor.com/project/tonybaloney/st2client) 4 | [![NuGet](https://img.shields.io/nuget/dt/St2.Client.svg)](https://www.nuget.org/packages/St2.Client/) 5 | 6 | A StackStorm API client for C#.NET including a PowerShell module 7 | 8 | ## Using the C#.NET client 9 | 10 | ### Documentation 11 | 12 | The docs are available on readthedocs.org 13 | [![RTD](https://readthedocs.org/projects/st2client/badge/?version=latest)](http://st2client.readthedocs.org/en/latest/) 14 | 15 | ### Download packages 16 | The .NET client is available on nuget.org 17 | * Release - [![NuGet](https://img.shields.io/nuget/v/St2.Client.svg)](https://www.nuget.org/packages/St2.Client/) 18 | The PowerShell module is available on nuget.org 19 | * Release - [![NuGet](https://img.shields.io/nuget/v/St2.Client.PowerShell.svg)](https://www.nuget.org/packages/St2.Client.PowerShell/) 20 | 21 | ### Example 22 | 23 | ```csharp 24 | St2Client apiClient = new St2Client("http://12.3.2.3:9100", "http://12.3.2.3:9101", "testu", "testp"); 25 | // login and get a token 26 | await apiClient.RefreshTokenAsync(); 27 | 28 | var actions = await apiClient.Actions.GetActionsAsync(); 29 | ``` 30 | 31 | ## Using the PowerShell module 32 | 33 | The PowerShell Module includes the following commands: 34 | 35 | * New-St2ClientConnection - Creates a new connection object 36 | * Get-St2Actions - Get the actions (can filter by pack name) 37 | * Get-St2Packs - Get the packs available 38 | * Get-St2Executions - Get the executions 39 | * Remove-St2Action - Delete an Action 40 | * Invoke-St2Action - Invoke an Action 41 | 42 | ```powershell 43 | Import-Module .\St2.Client.Powershell.dll 44 | $conn = New-St2ClientConnection -Username testu -Password testp -ApiUrl "http://12.3.2.3:9101" -AuthApiUrl "http://12.3.2.3:9100" 45 | 46 | $MyPack = Get-St2Packs -Name "example" 47 | 48 | $actions = Get-St2Actions -Pack $MyPack 49 | 50 | foreach($action in $actions){ 51 | Write-Output "Getting executions for action $action.name" 52 | Get-St2Executions -Action $action -Connection $conn 53 | } 54 | 55 | $action = Get-St2Actions -PackName "st2_dimensiondata" -Name "list_locations" 56 | Invoke-St2Action -Action $action -Parameters @{"region"="dd-au"} 57 | 58 | ``` 59 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/BaseClientCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System.Management.Automation; 2 | using System.Security.Authentication; 3 | 4 | namespace TonyBaloney.St2.Client.PowerShell 5 | { 6 | public abstract class BaseClientCmdlet 7 | : PSCmdlet 8 | { 9 | [Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, 10 | HelpMessage = "The StackStorm Connection created by New-St2ClientConnection")] 11 | public St2ClientConnection Connection { get; set; } 12 | 13 | /// 14 | /// The begin processing. 15 | /// 16 | protected override void BeginProcessing() 17 | { 18 | base.BeginProcessing(); 19 | 20 | // If CaaS connection is NOT set via parameter, get it from the PS session 21 | if (Connection == null) 22 | { 23 | Connection = SessionState.GetDefaultServiceConnection(); 24 | if (Connection == null) 25 | ThrowTerminatingError( 26 | new ErrorRecord( 27 | new AuthenticationException( 28 | "Cannot find a valid connection. Use New-St2ClientConnection to create or Set-St2ActiveConnection to set a valid connection"), 29 | "-1", 30 | ErrorCategory.AuthenticationError, 31 | this)); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/GetActionsCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | using Action = Models.Action; 9 | 10 | [Cmdlet(VerbsCommon.Get, "St2Actions")] 11 | public class GetActionsCmdlet 12 | : BaseClientCmdlet 13 | { 14 | [Parameter(Mandatory = false, HelpMessage = "Actions for a particular pack")] public Pack Pack; 15 | 16 | [Parameter(Mandatory = false, HelpMessage = "Actions for a particular pack")] public string PackName; 17 | 18 | [Parameter(Mandatory = false, HelpMessage = "Actions with name")] public string Name; 19 | 20 | protected override void ProcessRecord() 21 | { 22 | base.ProcessRecord(); 23 | 24 | try 25 | { 26 | IList actions; 27 | if (Pack != null) 28 | PackName = Pack.name; 29 | 30 | if (!String.IsNullOrWhiteSpace(PackName)) 31 | { 32 | if (!String.IsNullOrWhiteSpace(Name)) 33 | actions = Connection.ApiClient.Actions.GetActionsForPackByNameAsync(PackName, Name).Result; 34 | else 35 | { 36 | actions = Connection.ApiClient.Actions.GetActionsForPackByNameAsync(PackName, Name).Result; 37 | } 38 | } 39 | else if (!String.IsNullOrWhiteSpace(Name)) 40 | actions = Connection.ApiClient.Actions.GetActionsByNameAsync(Name).Result; 41 | else 42 | { 43 | actions = Connection.ApiClient.Actions.GetActionsAsync().Result; 44 | } 45 | 46 | foreach (var action in actions) 47 | { 48 | WriteObject(action); 49 | } 50 | } 51 | catch (AggregateException ae) 52 | { 53 | ae.Handle( 54 | e => 55 | { 56 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 57 | 58 | return true; 59 | }); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/GetExecutionsCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | using Action = Models.Action; 9 | 10 | [Cmdlet(VerbsCommon.Get, "St2Executions")] 11 | public class GetExecutionsCmdlet 12 | : BaseClientCmdlet 13 | { 14 | [Parameter(Mandatory = false, HelpMessage = "Limit the number of results")] public int Limit=5; 15 | 16 | [Parameter(Mandatory = false, HelpMessage = "Show executions for a particular action")] public string ActionName; 17 | 18 | [Parameter(Mandatory = false, HelpMessage = "Show executions for a particular action")] public Action Action; 19 | 20 | protected override void ProcessRecord() 21 | { 22 | base.ProcessRecord(); 23 | 24 | try 25 | { 26 | IList executions; 27 | 28 | if (Action != null) 29 | { 30 | executions = Connection.ApiClient.Executions.GetExecutionsForActionAsync(Action.name, Limit).Result; 31 | } 32 | else if (!string.IsNullOrWhiteSpace(ActionName)) 33 | executions = Connection.ApiClient.Executions.GetExecutionsForActionAsync(ActionName).Result; 34 | else 35 | { 36 | executions = Connection.ApiClient.Executions.GetExecutionsAsync(Limit).Result; 37 | } 38 | 39 | 40 | foreach (var exec in executions) 41 | { 42 | WriteObject(exec); 43 | } 44 | } 45 | catch (AggregateException ae) 46 | { 47 | ae.Handle( 48 | e => 49 | { 50 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 51 | 52 | return true; 53 | }); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/GetPacksCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | [Cmdlet(VerbsCommon.Get, "St2Packs")] 9 | public class GetPacksCmdlet 10 | : BaseClientCmdlet 11 | { 12 | [Parameter(Mandatory = false, HelpMessage = "Packs with ID")] 13 | public string Id; 14 | 15 | [Parameter(Mandatory = false, HelpMessage = "Packs with name")] 16 | public string Name; 17 | 18 | protected override void ProcessRecord() 19 | { 20 | base.ProcessRecord(); 21 | try 22 | { 23 | IList packs; 24 | 25 | if (!string.IsNullOrWhiteSpace(Name)) 26 | packs = Connection.ApiClient.Packs.GetPacksByNameAsync(Name).Result; 27 | else if (!string.IsNullOrWhiteSpace(Id)) 28 | packs = Connection.ApiClient.Packs.GetPacksByIdAsync(Id).Result; 29 | else 30 | packs = Connection.ApiClient.Packs.GetPacksAsync().Result; 31 | 32 | foreach (var pack in packs) 33 | { 34 | WriteObject(pack); 35 | } 36 | } 37 | catch (AggregateException ae) 38 | { 39 | ae.Handle( 40 | e => 41 | { 42 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 43 | 44 | return true; 45 | }); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/GetRulesCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | [Cmdlet(VerbsCommon.Get, "St2Rules")] 9 | public class GetRulesCmdlet 10 | : BaseClientCmdlet 11 | { 12 | [Parameter(Mandatory = false, HelpMessage = "Show rules for a particular pack")] public string PackName; 13 | 14 | [Parameter(Mandatory = false, HelpMessage = "Show rules for a particular pack")] public Pack Pack; 15 | 16 | protected override void ProcessRecord() 17 | { 18 | base.ProcessRecord(); 19 | 20 | try 21 | { 22 | IList rules; 23 | 24 | if (Pack != null) 25 | { 26 | rules = Connection.ApiClient.Rules.GetRulesForPackAsync(Pack.name).Result; 27 | } 28 | else if (!string.IsNullOrWhiteSpace(PackName)) 29 | rules = Connection.ApiClient.Rules.GetRulesForPackAsync(PackName).Result; 30 | else 31 | { 32 | rules = Connection.ApiClient.Rules.GetRulesAsync().Result; 33 | } 34 | 35 | 36 | foreach (var exec in rules) 37 | { 38 | WriteObject(exec); 39 | } 40 | } 41 | catch (AggregateException ae) 42 | { 43 | ae.Handle( 44 | e => 45 | { 46 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 47 | 48 | return true; 49 | }); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/InstallPackCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | [Cmdlet(VerbsLifecycle.Install, "St2Pack")] 9 | public class InstallPackCmdlet 10 | : BaseClientCmdlet 11 | { 12 | [Parameter(Mandatory = true, HelpMessage = "Name of the pack to install")] 13 | public string Name; 14 | 15 | [Parameter(Mandatory = false, HelpMessage = "URL of the repository")] 16 | public string RepoUrl; 17 | 18 | [Parameter(Mandatory = false, HelpMessage = "Branch of the repository")] 19 | public string Branch; 20 | 21 | protected override void ProcessRecord() 22 | { 23 | base.ProcessRecord(); 24 | 25 | try 26 | { 27 | Dictionary parameters = new Dictionary(); 28 | 29 | string[] pack_names = {Name}; 30 | parameters.Add("packs", pack_names); 31 | 32 | if (!string.IsNullOrWhiteSpace(RepoUrl)) 33 | parameters.Add("repo_url", RepoUrl); 34 | 35 | if (!string.IsNullOrWhiteSpace(Branch)) 36 | parameters.Add("branch", Branch); 37 | 38 | Execution result = Connection.ApiClient.Executions.ExecuteActionAsync("packs.install", parameters).Result; 39 | WriteObject(result); 40 | } 41 | catch (AggregateException ae) 42 | { 43 | ae.Handle( 44 | e => 45 | { 46 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 47 | 48 | return true; 49 | }); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/InvokeActionCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using TonyBaloney.St2.Client.Models; 7 | 8 | namespace TonyBaloney.St2.Client.PowerShell 9 | { 10 | using Action = Models.Action; 11 | 12 | /// An invoke action cmdlet. 13 | /// 14 | [Cmdlet(VerbsLifecycle.Invoke, "St2Action")] 15 | public class InvokeActionCmdlet 16 | : BaseClientCmdlet 17 | { 18 | [Parameter(Mandatory = true, HelpMessage = "Action execution parameters")] 19 | public Hashtable Parameters; 20 | 21 | [Parameter(Mandatory = true, HelpMessage = "The name of the action to execute", ParameterSetName = "byName")] 22 | public string ActionName; 23 | 24 | [Parameter(Mandatory = true, HelpMessage = "The action to execute", ParameterSetName = "byObj")] 25 | public Action Action; 26 | 27 | protected override void ProcessRecord() 28 | { 29 | base.ProcessRecord(); 30 | 31 | try 32 | { 33 | Execution result; 34 | 35 | Dictionary parameters = 36 | Parameters.Keys.Cast().ToDictionary(key => key, key => Parameters[key].ToString()); 37 | 38 | if (!string.IsNullOrWhiteSpace(ActionName)) 39 | result = Connection.ApiClient.Executions.ExecuteActionAsync(ActionName, parameters).Result; 40 | else 41 | { 42 | result = Connection.ApiClient.Executions.ExecuteActionAsync(Action.@ref, parameters).Result; 43 | } 44 | 45 | WriteObject(result); 46 | } 47 | catch (AggregateException ae) 48 | { 49 | ae.Handle( 50 | e => 51 | { 52 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 53 | 54 | return true; 55 | }); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/NewActionCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | [Cmdlet(VerbsCommon.New, "St2Action")] 9 | public class NewActionCmdlet 10 | : BaseClientCmdlet 11 | { 12 | [Parameter(Mandatory = true, HelpMessage = "Name of the action")] 13 | public string Name; 14 | 15 | [Parameter(Mandatory = true, HelpMessage = "Description of the action")] 16 | public string Description; 17 | 18 | [Parameter(Mandatory = true, HelpMessage = "Entry point (script to run)")] 19 | public string EntryPoint; 20 | 21 | [Parameter(Mandatory = true, HelpMessage = "Collection of parameters for the action")] 22 | public NamedActionParameter[] Parameters { get; set; } 23 | 24 | [Parameter(Mandatory = true, HelpMessage = "The target pack", ParameterSetName = "ByObj")] 25 | public Pack Pack; 26 | 27 | [Parameter(Mandatory = true, HelpMessage = "Name of the target pack", ParameterSetName = "ByName")] 28 | public string PackName; 29 | 30 | [Parameter(Mandatory = true, HelpMessage = "Type of runner for the action")] 31 | public RunnerType RunnerType { get; set; } 32 | 33 | protected override void ProcessRecord() 34 | { 35 | base.ProcessRecord(); 36 | 37 | try 38 | { 39 | if (Pack != null) 40 | PackName = Pack.name; 41 | 42 | var Action = Connection.ApiClient.Actions.CreateActionAsync(new CreateAction 43 | { 44 | description = Description, 45 | enabled = true, 46 | entry_point = EntryPoint, 47 | name = Name, 48 | pack = PackName, 49 | parameters = Parameters.ToDictionary(item => item.name, item => (ActionParameter)item), 50 | runner_type = Enum.GetName(typeof(RunnerType), RunnerType) 51 | }).Result; 52 | 53 | WriteObject(Action); 54 | } 55 | catch (AggregateException ae) 56 | { 57 | ae.Handle( 58 | e => 59 | { 60 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 61 | 62 | return true; 63 | }); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/NewActionParameterCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System.Management.Automation; 2 | using TonyBaloney.St2.Client.Models; 3 | 4 | namespace TonyBaloney.St2.Client.PowerShell 5 | { 6 | [Cmdlet(VerbsCommon.New, "St2ActionParameter")] 7 | public class NewActionParameterCmdlet 8 | : PSCmdlet 9 | { 10 | [Parameter(Mandatory = true, HelpMessage = "The name of the parameter")] 11 | public string Name { get; set; } 12 | 13 | [Parameter(Mandatory = true, HelpMessage = "The type of the parameter")] 14 | public ParameterType Type { get; set; } 15 | 16 | [Parameter(Mandatory = true, HelpMessage = "Description of the parameter")] 17 | public string Description { get; set; } 18 | 19 | [Parameter(Mandatory = true, HelpMessage = "Is immutable")] 20 | public bool Immutable { get; set; } 21 | 22 | [Parameter(Mandatory = true, HelpMessage = "Is immutable")] 23 | public bool Required { get; set; } 24 | 25 | [Parameter(Mandatory = true, HelpMessage = "The name of the parameter")] 26 | public object DefaultValue { get; set; } 27 | 28 | protected override void ProcessRecord() 29 | { 30 | base.ProcessRecord(); 31 | 32 | WriteObject(new NamedActionParameter 33 | { 34 | @default = DefaultValue, 35 | description = Description, 36 | required = Required, 37 | type = Type.ToString(), 38 | immutable = Immutable 39 | }); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/NewSt2ClientConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Management.Automation; 4 | using TonyBaloney.St2.Client.Exceptions; 5 | 6 | namespace TonyBaloney.St2.Client.PowerShell 7 | { 8 | /// 9 | /// The "New-CaasConnection" Cmdlet. 10 | /// 11 | /// 12 | /// Used to create a new connection to the CaaS API. 13 | /// 14 | [Cmdlet(VerbsCommon.New, "St2ClientConnection")] 15 | [OutputType(typeof (St2ClientConnection))] 16 | public class NewSt2ClientConnectionCmdlet : PSCmdlet 17 | { 18 | /// 19 | /// The credentials used to connect to the API. 20 | /// 21 | [Parameter(Mandatory = true)] 22 | [ValidateNotNullOrEmpty] 23 | public string Username { get; set; } 24 | 25 | [Parameter(Mandatory = true)] 26 | [ValidateNotNullOrEmpty] 27 | public string Password { get; set; } 28 | 29 | /// 30 | /// Name for this connection 31 | /// 32 | [Parameter(Mandatory = false, HelpMessage = "Name to identify this connection")] 33 | public string Name { get; set; } 34 | 35 | /// 36 | /// The base uri of the REST API 37 | /// 38 | [Parameter(Mandatory = true, HelpMessage = "The URL of the API")] 39 | public string ApiUrl { get; set; } 40 | 41 | /// 42 | /// The base uri of the auth API 43 | /// 44 | [Parameter(Mandatory = true, HelpMessage = "The URL of the Auth API")] 45 | public string AuthApiUrl { get; set; } 46 | 47 | [Parameter(Mandatory = false, HelpMessage = "Ignore certificate validation errors")] 48 | public SwitchParameter IgnoreCertificateValidation { get; set; } 49 | 50 | /// 51 | /// Process the record 52 | /// 53 | protected override void ProcessRecord() 54 | { 55 | base.ProcessRecord(); 56 | 57 | St2Client apiClient = new St2Client(AuthApiUrl, ApiUrl, Username, Password, IgnoreCertificateValidation.ToBool()); 58 | 59 | St2ClientConnection st2ClientConnection = new St2ClientConnection(apiClient); 60 | 61 | 62 | WriteDebug("Trying to login to the REST API"); 63 | 64 | try 65 | { 66 | st2ClientConnection.ApiClient.RefreshTokenAsync().Wait(TimeSpan.FromSeconds(15)); 67 | 68 | if (st2ClientConnection != null) 69 | { 70 | if (!st2ClientConnection.ApiClient.HasToken()) 71 | ThrowTerminatingError(new ErrorRecord(new Exception("Could not login, check credentials and access to the API"), "100", ErrorCategory.AuthenticationError, st2ClientConnection )); 72 | 73 | WriteDebug(string.Format("connection created successfully: {0}", st2ClientConnection)); 74 | if (string.IsNullOrEmpty(Name)) 75 | { 76 | Name = Guid.NewGuid().ToString(); 77 | } 78 | 79 | if (!SessionState.GetServiceConnections().Any()) 80 | WriteDebug("This is the first connection and will be the default connection."); 81 | SessionState.AddServiceConnection(Name, st2ClientConnection); 82 | if (SessionState.GetServiceConnections().Count > 1) 83 | WriteWarning( 84 | "You have created more than one connection on this session, please use the cmdlet Set-St2ActiveConnection -Name to change the active/default connection"); 85 | 86 | SessionState.AddServiceConnection(Name, st2ClientConnection); 87 | WriteObject(st2ClientConnection); 88 | } 89 | } 90 | catch (FailedRequestException fre) 91 | { 92 | ThrowTerminatingError(new ErrorRecord(fre, "-1", ErrorCategory.AuthenticationError, null)); 93 | } 94 | catch (AggregateException ae) 95 | { 96 | ae.Handle( 97 | e => 98 | { 99 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.AuthenticationError, null)); 100 | return true; 101 | }); 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("St2.Client.PowerShell")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("St2.Client.PowerShell")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("289a8947-797a-4b1b-988c-fc0c89be2566")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/RemoveActionCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Management.Automation; 3 | 4 | namespace TonyBaloney.St2.Client.PowerShell 5 | { 6 | using Action = Models.Action; 7 | 8 | [Cmdlet(VerbsCommon.Remove, "St2Action")] 9 | public class RemoveActionCmdlet 10 | : BaseClientCmdlet 11 | { 12 | [Parameter(Mandatory = true, HelpMessage = "Actions Id", ParameterSetName = "ById")] public string Id; 13 | 14 | [Parameter(Mandatory = true, HelpMessage = "Action", ParameterSetName = "ByObj")] 15 | public Action Action; 16 | 17 | protected override void ProcessRecord() 18 | { 19 | base.ProcessRecord(); 20 | 21 | try 22 | { 23 | if (!String.IsNullOrWhiteSpace(Id)) 24 | Connection.ApiClient.Actions.DeleteActionAsync(Id); 25 | else 26 | { 27 | Connection.ApiClient.Actions.DeleteActionAsync(Action.id); 28 | } 29 | } 30 | catch (AggregateException ae) 31 | { 32 | ae.Handle( 33 | e => 34 | { 35 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 36 | 37 | return true; 38 | }); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/RemoveRuleCmdlet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Management.Automation; 3 | using TonyBaloney.St2.Client.Models; 4 | 5 | namespace TonyBaloney.St2.Client.PowerShell 6 | { 7 | [Cmdlet(VerbsCommon.Remove, "St2Rule")] 8 | public class RemoveRuleCmdlet 9 | : BaseClientCmdlet 10 | { 11 | [Parameter(Mandatory = true, HelpMessage = "Rule Id", ParameterSetName = "ById")] 12 | public string Id; 13 | 14 | [Parameter(Mandatory = true, HelpMessage = "Rule", ParameterSetName = "ByObj")] 15 | public Rule Rule; 16 | 17 | protected override void ProcessRecord() 18 | { 19 | base.ProcessRecord(); 20 | 21 | try 22 | { 23 | if (!String.IsNullOrWhiteSpace(Id)) 24 | Connection.ApiClient.Rules.DeleteRuleAsync(Id); 25 | else 26 | { 27 | Connection.ApiClient.Rules.DeleteRuleAsync(Rule.id); 28 | } 29 | } 30 | catch (AggregateException ae) 31 | { 32 | ae.Handle( 33 | e => 34 | { 35 | ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection)); 36 | 37 | return true; 38 | }); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/SessionStateExtensions.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // 4 | // 5 | // 6 | // Extension methods for working with PowerShell . 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Management.Automation; 14 | 15 | namespace TonyBaloney.St2.Client.PowerShell 16 | { 17 | /// 18 | /// Extension methods for working with PowerShell . 19 | /// 20 | /// 21 | /// TODO: Add getter / setter for default connection. 22 | /// 23 | public static class SessionStateExtensions 24 | { 25 | #region Constants 26 | 27 | /// 28 | /// Statically-cached empty list of compute service connections. 29 | /// 30 | /// 31 | /// Returned when there are no active compute service connections. 32 | /// 33 | private static readonly IReadOnlyDictionary EmptyConnectionList = 34 | new Dictionary(); 35 | 36 | /// 37 | /// Variable name constants. 38 | /// 39 | public static class VariableNames 40 | { 41 | /// 42 | /// The name of the PowerShell variable in which active cloud-compute sessions are stored. 43 | /// 44 | public static readonly string ServiceSessions = "_St2ServiceComputeSessions"; 45 | } 46 | 47 | #endregion // Constants 48 | 49 | /// 50 | /// The _default compute service connection name. 51 | /// 52 | private static string _defaultComputeServiceConnectionName; 53 | 54 | /// Gets service connections from session. 55 | /// Thrown when one or more required arguments are null. 56 | /// . 57 | /// The service connections from session. 58 | private static Dictionary GetServiceConnectionsFromSession( 59 | SessionState sessionState) 60 | { 61 | if (sessionState == null) 62 | throw new ArgumentNullException("sessionState"); 63 | 64 | PSVariable connectionsVariable = sessionState.PSVariable.Get(VariableNames.ServiceSessions); 65 | if (connectionsVariable == null) 66 | return null; 67 | 68 | var connections = (Dictionary)connectionsVariable.Value; 69 | return connections; 70 | } 71 | 72 | /// A SessionState extension method that gets service connections. 73 | /// . 74 | /// The service connections. 75 | public static IReadOnlyDictionary GetServiceConnections( 76 | this SessionState sessionState) 77 | { 78 | Dictionary connections = GetServiceConnectionsFromSession(sessionState); 79 | if (connections == null || connections.Count == 0) 80 | return EmptyConnectionList; 81 | 82 | return connections; 83 | } 84 | 85 | /// A SessionState extension method that gets service connection by name. 86 | /// Thrown when one or more required arguments are null. 87 | /// . 88 | /// The name. 89 | /// The service connection by name. 90 | public static St2ClientConnection GetServiceConnectionByName(this SessionState sessionState, string name) 91 | { 92 | if (string.IsNullOrEmpty(name)) 93 | throw new ArgumentNullException("name"); 94 | 95 | Dictionary connections = GetServiceConnectionsFromSession(sessionState); 96 | if (connections == null || connections.Count == 0) 97 | return null; 98 | if (connections.ContainsKey(name)) 99 | return connections[name]; 100 | 101 | return null; 102 | } 103 | 104 | /// A SessionState extension method that gets default service connection. 105 | /// . 106 | /// The default service connection. 107 | public static St2ClientConnection GetDefaultServiceConnection(this SessionState sessionState) 108 | { 109 | Dictionary connections = GetServiceConnectionsFromSession(sessionState); 110 | if (connections == null) 111 | return null; 112 | 113 | if (!connections.ContainsKey(_defaultComputeServiceConnectionName)) 114 | return null; 115 | 116 | return connections[_defaultComputeServiceConnectionName]; 117 | } 118 | 119 | /// A SessionState extension method that sets default service connection. 120 | /// Thrown when the index is outside the required 121 | /// range. 122 | /// . 123 | /// The connection Name. 124 | public static void SetDefaultServiceConnection(this SessionState sessionState, string connectionName) 125 | { 126 | Dictionary connections = GetServiceConnectionsFromSession(sessionState); 127 | if (!connections.ContainsKey(connectionName)) 128 | throw new IndexOutOfRangeException("connectionName does not exisits"); 129 | _defaultComputeServiceConnectionName = connectionName; 130 | } 131 | 132 | /// A SessionState extension method that adds a service connection. 133 | /// Thrown when one or more required arguments are null. 134 | /// . 135 | /// The connection Name. 136 | /// The connection. 137 | /// A St2ClientConnection. 138 | public static St2ClientConnection AddServiceConnection(this SessionState sessionState, 139 | string connectionName, St2ClientConnection connection) 140 | { 141 | if (sessionState == null) 142 | throw new ArgumentNullException("sessionState"); 143 | 144 | if (connection == null) 145 | throw new ArgumentNullException("connection"); 146 | 147 | 148 | if (string.IsNullOrEmpty(connectionName)) 149 | throw new ArgumentNullException("connectionName"); 150 | 151 | 152 | Dictionary connections; 153 | PSVariable connectionsVariable = sessionState.PSVariable.Get(VariableNames.ServiceSessions); 154 | if (connectionsVariable == null) 155 | { 156 | connectionsVariable = new PSVariable( 157 | VariableNames.ServiceSessions, connections = new Dictionary(), 158 | ScopedItemOptions.AllScope 159 | ); 160 | sessionState.PSVariable.Set(connectionsVariable); 161 | } 162 | else 163 | { 164 | connections = (Dictionary)connectionsVariable.Value; 165 | if (connections == null) 166 | { 167 | connectionsVariable.Value = connections = new Dictionary(); 168 | sessionState.PSVariable.Set(connectionsVariable); 169 | } 170 | } 171 | 172 | if (!connections.ContainsKey(connectionName)) 173 | connections.Add(connectionName, connection); 174 | else 175 | connections[connectionName] = connection; 176 | 177 | if (string.IsNullOrEmpty(_defaultComputeServiceConnectionName) || connections.Count().Equals(1)) 178 | _defaultComputeServiceConnectionName = connectionName; 179 | 180 | return connection; 181 | } 182 | 183 | /// A SessionState extension method that removes the service connection. 184 | /// Thrown when one or more required arguments are null. 185 | /// . 186 | /// The connection Name. 187 | /// true if it succeeds, false if it fails. 188 | public static bool RemoveServiceConnection(this SessionState sessionState, string connectionName) 189 | { 190 | if (sessionState == null) 191 | throw new ArgumentNullException("sessionState"); 192 | 193 | if (string.IsNullOrEmpty(connectionName)) 194 | throw new ArgumentNullException("connectionName"); 195 | 196 | PSVariable connectionsVariable = sessionState.PSVariable.Get(VariableNames.ServiceSessions); 197 | if (connectionsVariable == null) 198 | return false; 199 | 200 | var connections = (Dictionary)connectionsVariable.Value; 201 | if (connections == null) 202 | return false; 203 | 204 | return connections.Remove(connectionName); 205 | } 206 | } 207 | } -------------------------------------------------------------------------------- /St2.Client.PowerShell/St2.Client.PowerShell.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4B6DEAC5-2B3B-4E30-B538-AD7ECD96DCCF} 8 | Library 9 | Properties 10 | TonyBaloney.St2.Client.PowerShell 11 | St2.Client.PowerShell 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | ..\..\DimensionData.ComputeClient\CaaS_PS.ruleset 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | false 35 | 36 | 37 | 38 | 39 | 40 | False 41 | ..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | {1c36dc71-36d3-4e2f-978d-7f6b2cc3d3ab} 69 | St2.Client 70 | 71 | 72 | 73 | 74 | Always 75 | 76 | 77 | Always 78 | 79 | 80 | 81 | 82 | 83 | Designer 84 | 85 | 86 | 87 | 94 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/St2.Client.PowerShell.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Program 5 | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 6 | -noexit -command "&{ import-module .\St2.Client.PowerShell.dll -verbose}" 7 | 8 | 9 | ShowAllFiles 10 | 11 | 12 | -noexit -command "&{ import-module .\St2.Client.PowerShell.dll -verbose}" 13 | Program 14 | C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 15 | 16 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/St2.Client.PowerShell.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | St2.Client.PowerShell 5 | $version$ 6 | StackStorm API PowerShell module 7 | Anthony Shaw 8 | https://github.com/tonybaloney/St2Client 9 | false 10 | Provides a client to talk to a StackStorm API via PowerShell. 11 | Provides a client to talk to a StackStorm API. 12 | . 13 | Copyright Dimension Data 2015 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /St2.Client.PowerShell/St2.Client.psd1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonybaloney/St2Client/6d6fa592bbb444aed3711a1fdf0633bcec8d62c3/St2.Client.PowerShell/St2.Client.psd1 -------------------------------------------------------------------------------- /St2.Client.PowerShell/St2ClientConnection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TonyBaloney.St2.Client.PowerShell 4 | { 5 | public sealed class St2ClientConnection 6 | : IDisposable 7 | { 8 | public St2ClientConnection(ISt2Client apiClient) 9 | { 10 | if (apiClient == null) 11 | throw new ArgumentNullException("apiClient"); 12 | 13 | ApiClient = apiClient; 14 | } 15 | 16 | /// 17 | /// The API client represented by the connection. 18 | /// 19 | internal ISt2Client ApiClient { get; private set; } 20 | 21 | /// 22 | /// Dispose of resources being used by the CaaS API connection. 23 | /// 24 | public void Dispose() 25 | { 26 | if (ApiClient != null) 27 | { 28 | ApiClient.Dispose(); 29 | ApiClient = null; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /St2.Client.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "St2.Client", "St2.Client\St2.Client.csproj", "{1C36DC71-36D3-4E2F-978D-7F6B2CC3D3AB}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "St2.Client.PowerShell", "St2.Client.PowerShell\St2.Client.PowerShell.csproj", "{4B6DEAC5-2B3B-4E30-B538-AD7ECD96DCCF}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1C36DC71-36D3-4E2F-978D-7F6B2CC3D3AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {1C36DC71-36D3-4E2F-978D-7F6B2CC3D3AB}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {1C36DC71-36D3-4E2F-978D-7F6B2CC3D3AB}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {1C36DC71-36D3-4E2F-978D-7F6B2CC3D3AB}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {4B6DEAC5-2B3B-4E30-B538-AD7ECD96DCCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {4B6DEAC5-2B3B-4E30-B538-AD7ECD96DCCF}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {4B6DEAC5-2B3B-4E30-B538-AD7ECD96DCCF}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {4B6DEAC5-2B3B-4E30-B538-AD7ECD96DCCF}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /St2.Client/Apis/ActionsApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.Apis 7 | { 8 | using Action = Models.Action; 9 | 10 | /// The actions api. 11 | public class ActionsApi : IActionsApi 12 | { 13 | private ISt2Client _host; 14 | 15 | /// 16 | /// Initializes a new instance of the TonyBaloney.St2.Client.Apis.ActionsApi class. 17 | /// 18 | /// Thrown when one or more required arguments are null. 19 | /// The host. 20 | public ActionsApi(ISt2Client host) 21 | { 22 | if (host == null) 23 | throw new ArgumentNullException("host"); 24 | _host = host; 25 | } 26 | 27 | /// Get all available Actions. 28 | /// A List of Actions. 29 | /// 30 | public async Task> GetActionsAsync() 31 | { 32 | return await _host.GetApiRequestAsync>("/v1/actions"); 33 | } 34 | 35 | /// Gets actions for pack. 36 | /// The pack name. 37 | /// A List of Actions. 38 | /// 39 | public async Task> GetActionsForPackAsync(string pack) 40 | { 41 | return await _host.GetApiRequestAsync>("/v1/actions?pack=" + pack); 42 | } 43 | 44 | public async Task> GetActionsForPackByNameAsync(string pack, string name) 45 | { 46 | return await _host.GetApiRequestAsync>("/v1/actions?pack=" + pack + "&name=" + name); 47 | } 48 | 49 | /// Gets actions by name. 50 | /// The action name. 51 | /// A List of Actions. 52 | /// 53 | public async Task> GetActionsByNameAsync(string name) 54 | { 55 | return await _host.GetApiRequestAsync>("/v1/actions?name=" + name); 56 | } 57 | 58 | /// Deletes the action described by actionId. 59 | /// can be either the ID (e.g. 1 or the ref e.g. mypack.myaction). 60 | /// 61 | public async Task DeleteActionAsync(string actionId) 62 | { 63 | await _host.DeleteApiRequestAsync("/v1/actions/" + actionId); 64 | } 65 | 66 | /// Creates a new action. 67 | /// The to create. 68 | /// The new action asynchronous. 69 | /// 70 | public async Task CreateActionAsync(CreateAction action) 71 | { 72 | return await _host.PostApiRequestAsync("/v1/actions/", action); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /St2.Client/Apis/ExecutionsApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.Apis 7 | { 8 | /// The executions API. 9 | /// 10 | public class ExecutionsApi : IExecutionsApi 11 | { 12 | private ISt2Client _host; 13 | 14 | /// 15 | /// Initializes a new instance of the TonyBaloney.St2.Client.Apis.ExecutionsApi class. 16 | /// 17 | /// Thrown when one or more required arguments are null. 18 | /// The host. 19 | public ExecutionsApi(ISt2Client host) 20 | { 21 | if (host == null) 22 | throw new ArgumentNullException("host"); 23 | _host = host; 24 | } 25 | 26 | /// Gets execution. 27 | /// The identifier. 28 | /// The execution. 29 | /// 30 | public async Task GetExecutionAsync(string id) 31 | { 32 | return await _host.GetApiRequestAsync("/v1/executions/"+id); 33 | } 34 | 35 | /// Gets a list of executions. 36 | /// The number of items to return (default 5). 37 | /// A list of . 38 | /// 39 | public async Task> GetExecutionsAsync(int limit = 5) 40 | { 41 | return await _host.GetApiRequestAsync>("/v1/executions?limit="+limit); 42 | } 43 | 44 | /// Gets executions for action. 45 | /// Name of the action. 46 | /// The number of items to return (default 5). 47 | /// A list of . 48 | /// 49 | public async Task> GetExecutionsForActionAsync(string actionName, int limit = 5) 50 | { 51 | return await _host.GetApiRequestAsync>("/v1/executions?action="+actionName +"&limit="+limit); 52 | } 53 | 54 | /// Executes the action. 55 | /// Name of the action. 56 | /// The parameters for the given action. 57 | /// The resulting execution; 58 | /// 59 | public async Task ExecuteActionAsync(string actionName, Dictionary parameters) 60 | { 61 | ExecuteActionRequest request = new ExecuteActionRequest 62 | { 63 | action = actionName, 64 | parameters = parameters 65 | }; 66 | return await _host.PostApiRequestAsync("/v1/executions/", request); 67 | } 68 | 69 | /// Executes the action. 70 | /// Name of the action. 71 | /// The parameters for the given action. 72 | /// The resulting execution; 73 | /// 74 | public async Task ExecuteActionAsync(string actionName, Dictionary parameters) 75 | { 76 | ExecuteComplexActionRequest request = new ExecuteComplexActionRequest 77 | { 78 | action = actionName, 79 | parameters = parameters 80 | }; 81 | return await _host.PostApiRequestAsync("/v1/executions/", request); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /St2.Client/Apis/IActionsApi.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using TonyBaloney.St2.Client.Models; 4 | 5 | namespace TonyBaloney.St2.Client.Apis 6 | { 7 | using Action = Models.Action; 8 | 9 | /// Interface for actions API. 10 | public interface IActionsApi 11 | { 12 | /// Get all available Actions. 13 | /// A List of . 14 | Task> GetActionsAsync(); 15 | 16 | /// Gets actions for pack. 17 | /// The pack name. 18 | /// A List of . 19 | Task> GetActionsForPackAsync(string pack); 20 | 21 | Task> GetActionsForPackByNameAsync(string pack, string name); 22 | 23 | /// Gets actions by name. 24 | /// The action name. 25 | /// A List of . 26 | Task> GetActionsByNameAsync(string name); 27 | 28 | /// Deletes the action described by actionId. 29 | /// can be either the ID (e.g. 1 or the ref e.g. mypack.myaction). 30 | Task DeleteActionAsync(string actionId); 31 | 32 | /// Creates a new action. 33 | /// The to create. 34 | Task CreateActionAsync(CreateAction action); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /St2.Client/Apis/IExecutionsApi.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using TonyBaloney.St2.Client.Models; 4 | 5 | namespace TonyBaloney.St2.Client.Apis 6 | { 7 | /// Interface for executions API. 8 | public interface IExecutionsApi 9 | { 10 | /// Gets execution. 11 | /// The identifier. 12 | /// The execution. 13 | Task GetExecutionAsync(string id); 14 | 15 | /// Gets a list of executions. 16 | /// The number of items to return (default 5). 17 | /// A list of . 18 | Task> GetExecutionsAsync(int limit=5); 19 | 20 | /// Gets executions for action. 21 | /// Name of the action. 22 | /// The number of items to return (default 5). 23 | /// A list of . 24 | Task> GetExecutionsForActionAsync(string actionName, int limit=5); 25 | 26 | /// Executes the action. 27 | /// Name of the action. 28 | /// The parameters for the given action. 29 | /// The resulting execution; 30 | Task ExecuteActionAsync(string actionName, Dictionary parameters); 31 | 32 | /// Executes the action. 33 | /// Name of the action. 34 | /// The parameters for the given action. 35 | /// The resulting execution; 36 | Task ExecuteActionAsync(string actionName, Dictionary parameters); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /St2.Client/Apis/IPacksApi.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using TonyBaloney.St2.Client.Models; 4 | 5 | namespace TonyBaloney.St2.Client.Apis 6 | { 7 | /// Interface for packs API. 8 | public interface IPacksApi 9 | { 10 | /// Get a list of packs. 11 | /// A List of . 12 | Task> GetPacksAsync(); 13 | 14 | /// Gets packs by name. 15 | /// Name of the pack. 16 | /// A List of . 17 | Task> GetPacksByNameAsync(string packName); 18 | 19 | /// Gets packs by identifier. 20 | /// Identifier for the pack. 21 | /// A List of . 22 | Task> GetPacksByIdAsync(string packId); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /St2.Client/Apis/IRulesApi.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using TonyBaloney.St2.Client.Models; 4 | 5 | namespace TonyBaloney.St2.Client.Apis 6 | { 7 | /// Interface for rules API. 8 | public interface IRulesApi 9 | { 10 | /// Gets rules. 11 | /// The rules. 12 | Task> GetRulesAsync(); 13 | 14 | /// Gets rules for pack. 15 | /// Name of the pack. 16 | /// The rules for pack. 17 | Task> GetRulesForPackAsync(string packName); 18 | 19 | /// Gets rules by name. 20 | /// The name. 21 | /// The rules by name. 22 | Task> GetRulesByNameAsync(string name); 23 | 24 | /// Deletes the rule described by ruleId. 25 | /// Identifier for the rule. 26 | /// A Task. 27 | Task DeleteRuleAsync(string ruleId); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /St2.Client/Apis/PacksApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.Apis 7 | { 8 | /// The packs api. 9 | /// 10 | public class PacksApi : IPacksApi 11 | { 12 | private ISt2Client _host; 13 | 14 | /// 15 | /// Initializes a new instance of the TonyBaloney.St2.Client.Apis.PacksApi class. 16 | /// 17 | /// Thrown when one or more required arguments are null. 18 | /// The host. 19 | public PacksApi(ISt2Client host) 20 | { 21 | if (host == null) 22 | throw new ArgumentNullException("host"); 23 | _host = host; 24 | } 25 | 26 | /// Get a list of packs. 27 | /// A List of . 28 | /// 29 | public async Task> GetPacksAsync() 30 | { 31 | return await _host.GetApiRequestAsync>("/v1/packs"); 32 | } 33 | 34 | /// Gets packs by name. 35 | /// Name of the pack. 36 | /// A List of . 37 | /// 38 | public async Task> GetPacksByNameAsync(string packName) 39 | { 40 | return await _host.GetApiRequestAsync>("/v1/packs?name=" + packName); 41 | } 42 | 43 | /// Gets packs by identifier. 44 | /// Identifier for the pack. 45 | /// A List of . 46 | /// 47 | public async Task> GetPacksByIdAsync(string packId) 48 | { 49 | return await _host.GetApiRequestAsync>("/v1/packs?ref=" + packId); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /St2.Client/Apis/RulesApi.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using TonyBaloney.St2.Client.Models; 5 | 6 | namespace TonyBaloney.St2.Client.Apis 7 | { 8 | /// The rules api. 9 | /// 10 | public class RulesApi : 11 | IRulesApi 12 | { 13 | /// The host process. 14 | private ISt2Client _host; 15 | 16 | /// 17 | /// Initializes a new instance of the TonyBaloney.St2.Client.Apis.RulesApi class. 18 | /// 19 | /// Thrown when one or more required arguments are null. 20 | /// The host. 21 | public RulesApi(ISt2Client host) 22 | { 23 | if (host == null) 24 | throw new ArgumentNullException("host"); 25 | _host = host; 26 | } 27 | 28 | /// Gets rules . 29 | /// The rules . 30 | public async Task> GetRulesAsync() 31 | { 32 | return await _host.GetApiRequestAsync>("/v1/rules/"); 33 | } 34 | 35 | /// Gets rules for pack . 36 | /// Name of the pack. 37 | /// The rules for pack . 38 | public async Task> GetRulesForPackAsync(string packName) 39 | { 40 | return await _host.GetApiRequestAsync>("/v1/rules?pack=" + packName); 41 | } 42 | 43 | /// Gets rules by name . 44 | /// The rule name. 45 | /// The rules by name . 46 | public async Task> GetRulesByNameAsync(string name) 47 | { 48 | return await _host.GetApiRequestAsync>("/v1/rules?name=" + name); 49 | } 50 | 51 | /// Deletes the rule described by ruleId. 52 | /// Identifier for the rule. 53 | /// A Task. 54 | /// 55 | public async Task DeleteRuleAsync(string ruleId) 56 | { 57 | await _host.DeleteApiRequestAsync("/v1/rules/" + ruleId); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /St2.Client/AuthExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using TonyBaloney.St2.Client.Exceptions; 3 | using TonyBaloney.St2.Client.Models; 4 | 5 | namespace TonyBaloney.St2.Client 6 | { 7 | /// An authentication extensions. 8 | public static class AuthExtensions 9 | { 10 | /// 11 | /// A HttpClient extension method that adds an x-auth-token to the client headers 12 | /// 13 | /// The client to act on. 14 | /// The token. 15 | public static void AddXAuthToken(this HttpClient client, TokenResponse token) 16 | { 17 | if (token == null) 18 | throw new InvalidTokenException("Please login first, or could not find a login token."); 19 | 20 | client.DefaultRequestHeaders.Add("x-auth-token", token.token); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /St2.Client/Exceptions/ExceptionFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | 4 | namespace TonyBaloney.St2.Client.Exceptions 5 | { 6 | public static class ExceptionFactory 7 | { 8 | public static FailedRequestException FailedPostRequest(HttpResponseMessage response) 9 | { 10 | return new FailedRequestException("POST Request failed", response.RequestMessage.RequestUri, response.StatusCode, (response.Content != null ? response.Content.ToString() : "")); 11 | } 12 | 13 | public static FailedRequestException FailedGetRequest(HttpResponseMessage response) 14 | { 15 | return new FailedRequestException("GET Request failed", response.RequestMessage.RequestUri, response.StatusCode, (response.Content != null ? response.Content.ToString() : "")); 16 | } 17 | 18 | public static FailedRequestException FailedTokenException(HttpResponseMessage response) 19 | { 20 | return new FailedRequestException("Token Auth Request failed", response.RequestMessage.RequestUri, response.StatusCode, (response.Content != null ? response.Content.ToString() : "")); 21 | } 22 | 23 | public static FailedRequestException FailedDeleteRequest(HttpResponseMessage response) 24 | { 25 | return new FailedRequestException("DELETE Request failed", response.RequestMessage.RequestUri, response.StatusCode, (response.Content != null ? response.Content.ToString() : "")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /St2.Client/Exceptions/FailedRequestException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace TonyBaloney.St2.Client.Exceptions 5 | { 6 | /// Exception for signalling failed request errors. 7 | /// 8 | public class FailedRequestException 9 | : Exception 10 | { 11 | public string FailureMessage; 12 | 13 | public Uri RequestUri; 14 | 15 | public HttpStatusCode StatusCode; 16 | 17 | public string ResponseMessage; 18 | 19 | /// 20 | /// Initializes a new instance of the 21 | /// TonyBaloney.St2.Client.Exceptions.FailedRequestException class. 22 | /// 23 | /// The message. 24 | public FailedRequestException(string message) : 25 | base(message) 26 | { 27 | } 28 | 29 | /// 30 | /// Initializes a new instance of the 31 | /// FailedRequestException class. 32 | /// 33 | /// Message describing the failure. 34 | /// URI of the request. 35 | /// The status code. 36 | /// Message describing the response. 37 | public FailedRequestException(string failureMessage, Uri requestUri, HttpStatusCode statusCode, string responseMessage) 38 | : base(String.Format("{3}, Request to {0} failed with status '{1}', response was {2}", requestUri, statusCode, 39 | responseMessage, failureMessage)) 40 | { 41 | FailureMessage = failureMessage; 42 | RequestUri = requestUri; 43 | StatusCode = statusCode; 44 | ResponseMessage = responseMessage; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /St2.Client/Exceptions/InvalidTokenException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace TonyBaloney.St2.Client.Exceptions 4 | { 5 | /// Exception for signalling invalid token errors. 6 | /// 7 | public class InvalidTokenException 8 | : Exception 9 | { 10 | /// 11 | /// Initializes a new instance of the TonyBaloney.St2.Client.Exceptions.InvalidTokenException 12 | /// class. 13 | /// 14 | /// The message. 15 | public InvalidTokenException(string message) : 16 | base(message) 17 | { 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /St2.Client/ISt2Client.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using TonyBaloney.St2.Client.Apis; 3 | 4 | namespace TonyBaloney.St2.Client 5 | { 6 | /// Interface for StackStorm API client. 7 | public interface ISt2Client 8 | { 9 | /// Refresh the auth token. 10 | Task RefreshTokenAsync(); 11 | 12 | /// Make an asynchronous GET request to the API. 13 | /// Expected Type of the response. 14 | /// URL of the GET request. 15 | /// The Typed response. 16 | Task GetApiRequestAsync(string url); 17 | 18 | /// Make an asynchronous POST request to the API. 19 | /// Expected Type of the response. 20 | /// Expected Type of of the request message. 21 | /// URL of the POST request. 22 | /// The request. 23 | /// The Typed response. 24 | Task PostApiRequestAsync(string url, TRequestType request); 25 | 26 | /// Make a DELETE request to the API. 27 | /// URL of the request. 28 | Task DeleteApiRequestAsync(string url); 29 | 30 | /// Accessor for the Actions related methods 31 | /// The actions accessor. 32 | IActionsApi Actions { get; } 33 | 34 | /// Accessor for the Packs related methods. 35 | /// The Packs accessor. 36 | IPacksApi Packs { get; } 37 | 38 | /// Accessor for the Executions related methods. 39 | /// The Executions accessor. 40 | IExecutionsApi Executions { get; } 41 | 42 | /// Accessor for the Rules related methods. 43 | /// The Rules accessor. 44 | IRulesApi Rules { get; } 45 | 46 | void Dispose(); 47 | 48 | /// Query if this object has a token. 49 | /// true if token, false if not. 50 | bool HasToken(); 51 | } 52 | } -------------------------------------------------------------------------------- /St2.Client/Models/Action.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class Action 6 | { 7 | public string description { get; set; } 8 | public string runner_type { get; set; } 9 | public bool enabled { get; set; } 10 | public string pack { get; set; } 11 | public string entry_point { get; set; } 12 | public string uid { get; set; } 13 | public Dictionary parameters { get; set; } 14 | public string @ref { get; set; } 15 | public string id { get; set; } 16 | public string name { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /St2.Client/Models/ActionParameter.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class ActionParameter 4 | { 5 | public string type; 6 | public string description; 7 | public object @default; 8 | public bool required; 9 | public int order; 10 | public bool immutable=false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /St2.Client/Models/CreateAction.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class CreateAction 6 | { 7 | public string description { get; set; } 8 | public string runner_type { get; set; } 9 | public bool enabled { get; set; } 10 | public string pack { get; set; } 11 | public string entry_point { get; set; } 12 | public Dictionary parameters { get; set; } 13 | public string name { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /St2.Client/Models/ExecuteActionRequest.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class ExecuteActionRequest 6 | { 7 | public string action; 8 | public Dictionary parameters; 9 | } 10 | 11 | public class ExecuteComplexActionRequest 12 | { 13 | public string action; 14 | public Dictionary parameters; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /St2.Client/Models/Execution.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class Execution 4 | { 5 | public string status { get; set; } 6 | public string start_timestamp { get; set; } 7 | public TriggerType trigger_type { get; set; } 8 | public Runner runner { get; set; } 9 | public Rule rule { get; set; } 10 | public Trigger trigger { get; set; } 11 | public ExecutionContext context { get; set; } 12 | public Action action { get; set; } 13 | public string id { get; set; } 14 | public string end_timestamp { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /St2.Client/Models/ExecutionContext.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class ExecutionContext 4 | { 5 | public TriggerInstance trigger_instance { get; set; } 6 | public Rule rule { get; set; } 7 | public string user { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /St2.Client/Models/NamedActionParameter.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class NamedActionParameter 4 | : ActionParameter 5 | { 6 | public string name; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /St2.Client/Models/Pack.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class Pack 6 | { 7 | public List files { get; set; } 8 | public string description { get; set; } 9 | public string name { get; set; } 10 | public string author { get; set; } 11 | public string id { get; set; } 12 | public string version { get; set; } 13 | public List keywords { get; set; } 14 | public string @ref { get; set; } 15 | public string email { get; set; } 16 | public string uid { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /St2.Client/Models/ParameterType.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public enum ParameterType 4 | { 5 | @string, 6 | @int, 7 | @bool 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /St2.Client/Models/PayloadSchema.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class PayloadSchema 4 | { 5 | public string type { get; set; } 6 | public dynamic properties { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /St2.Client/Models/Rule.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class Rule 6 | { 7 | public string uid { get; set; } 8 | public List tags { get; set; } 9 | public string @ref { get; set; } 10 | public bool enabled { get; set; } 11 | public Trigger trigger { get; set; } 12 | public object criteria { get; set; } 13 | public RuleAction action { get; set; } 14 | public string pack { get; set; } 15 | public RuleType type { get; set; } 16 | public string id { get; set; } 17 | public string name { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /St2.Client/Models/RuleAction.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class RuleAction 6 | { 7 | public Dictionary parameters { get; set; } 8 | public string @ref { get; set; } 9 | } 10 | } -------------------------------------------------------------------------------- /St2.Client/Models/RuleType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class RuleType 6 | { 7 | public string @ref { get; set; } 8 | public Dictionary parameters { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /St2.Client/Models/Runner.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class Runner 6 | { 7 | public string runner_module { get; set; } 8 | public string description { get; set; } 9 | public bool enabled { get; set; } 10 | public Dictionary runner_parameters { get; set; } 11 | public string id { get; set; } 12 | public string name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /St2.Client/Models/RunnerEnvironment.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class RunnerEnvironment 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /St2.Client/Models/RunnerParameter.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class RunnerParameter 4 | { 5 | public string type; 6 | public string description; 7 | public object @default; 8 | public bool required; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /St2.Client/Models/RunnerType.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public enum RunnerType 6 | { 7 | [Description("local-shell-cmd")] 8 | LocalShellCmd, 9 | 10 | [Description("local-shell-script")] 11 | LocalShellScript, 12 | 13 | [Description("remote-shell-cmd")] 14 | RemoteShellCmd, 15 | 16 | [Description("python-script")] 17 | PythonScript, 18 | 19 | [Description("http-request")] 20 | HttpRequest, 21 | 22 | [Description("action-chain")] 23 | ActionChain, 24 | 25 | [Description("mistral-v2")] 26 | MistralV2, 27 | 28 | [Description("cloud-slang")] 29 | CloudSlang 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /St2.Client/Models/TokenResponse.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class TokenResponse 4 | { 5 | public string user { get; set; } 6 | public string token { get; set; } 7 | public string expiry { get; set; } 8 | public string id { get; set; } 9 | public object metadata { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /St2.Client/Models/Trigger.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class Trigger 6 | { 7 | public string type { get; set; } 8 | public string @ref { get; set; } 9 | public Dictionary parameters { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /St2.Client/Models/TriggerInstance.cs: -------------------------------------------------------------------------------- 1 | namespace TonyBaloney.St2.Client.Models 2 | { 3 | public class TriggerInstance 4 | { 5 | public string id { get; set; } 6 | public object name { get; set; } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /St2.Client/Models/TriggerType.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace TonyBaloney.St2.Client.Models 4 | { 5 | public class TriggerType 6 | { 7 | public string description { get; set; } 8 | public dynamic parameters_schema { get; set; } 9 | public List tags { get; set; } 10 | public string name { get; set; } 11 | public PayloadSchema payload_schema { get; set; } 12 | public string pack { get; set; } 13 | public string id { get; set; } 14 | public string uid { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /St2.Client/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("St2.Client")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("St2.Client")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("501b8443-a422-4233-9de6-5b77294522cd")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /St2.Client/St2.Client.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1C36DC71-36D3-4E2F-978D-7F6B2CC3D3AB} 8 | Library 9 | Properties 10 | TonyBaloney.St2.Client 11 | St2.Client 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | ..\..\CaaS.OpenStack-Facade\src\Aperture.ruleset 25 | bin\Debug\St2.Client.XML 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | bin\Release\St2.Client.XML 35 | 36 | 37 | 38 | False 39 | ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll 40 | 41 | 42 | 43 | 44 | 45 | False 46 | ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 104 | -------------------------------------------------------------------------------- /St2.Client/St2.Client.nuspec: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | St2.Client 5 | $version$ 6 | StackStorm API client 7 | Anthony Shaw 8 | https://github.com/tonybaloney/St2Client 9 | false 10 | Provides a client to talk to a StackStorm API. 11 | Provides a client to talk to a StackStorm API. 12 | . 13 | Copyright Dimension Data 2015 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /St2.Client/St2Client.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Net.Http.Formatting; 4 | using System.Net.Http.Headers; 5 | using System.Threading.Tasks; 6 | using TonyBaloney.St2.Client.Apis; 7 | using TonyBaloney.St2.Client.Models; 8 | using TonyBaloney.St2.Client.Exceptions; 9 | 10 | namespace TonyBaloney.St2.Client 11 | { 12 | /// StackStorm API Client. 13 | public class St2Client : ISt2Client, IDisposable 14 | { 15 | /// The username. 16 | private string _username; 17 | 18 | /// The password. 19 | private string _password; 20 | 21 | /// URL of the authentication endpoint. 22 | private Uri _authUrl; 23 | 24 | /// URL of the API. 25 | private Uri _apiUrl; 26 | 27 | /// The token. 28 | private TokenResponse _token; 29 | 30 | /// Initializes a new instance of the TonyBaloney.St2.Client.St2Client class. 31 | /// Thrown when one or more arguments have unsupported or 32 | /// illegal values. 33 | /// URL of the authentication endpoint. 34 | /// URL of the API. 35 | /// The username. 36 | /// The password. 37 | /// true to ignore certificate validation. 38 | public St2Client(string authUrl, string apiUrl, string username, string password, bool ignoreCertificateValidation = false) 39 | { 40 | if (String.IsNullOrWhiteSpace(authUrl)) 41 | throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'authUrl'.", 42 | "authUrl"); 43 | 44 | if (String.IsNullOrWhiteSpace(apiUrl)) 45 | throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'apiUrl'.", 46 | "apiUrl"); 47 | 48 | if (String.IsNullOrWhiteSpace(password)) 49 | throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'password'.", 50 | "password"); 51 | 52 | if (String.IsNullOrWhiteSpace(username)) 53 | throw new ArgumentException("Argument cannot be null, empty, or composed entirely of whitespace: 'username'.", 54 | "username"); 55 | 56 | _apiUrl = new Uri(apiUrl); 57 | _authUrl = new Uri(authUrl); 58 | _password = password; 59 | _username = username; 60 | 61 | if (ignoreCertificateValidation) 62 | System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return true; }; 63 | 64 | Actions = new ActionsApi(this); 65 | Packs = new PacksApi(this); 66 | Executions = new ExecutionsApi(this); 67 | Rules = new RulesApi(this); 68 | } 69 | 70 | /// Refresh the auth token. 71 | /// A Task. 72 | /// 73 | public async Task RefreshTokenAsync() 74 | { 75 | using (var client = new HttpClient()) 76 | { 77 | client.BaseAddress = _authUrl; 78 | client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( 79 | "Basic", 80 | Convert.ToBase64String( 81 | System.Text.ASCIIEncoding.ASCII.GetBytes( 82 | string.Format("{0}:{1}", _username, _password)))); 83 | 84 | try 85 | { 86 | var response = await client.PostAsync("/tokens", new StringContent(String.Empty)); 87 | 88 | if (response.IsSuccessStatusCode) 89 | _token = await response.Content.ReadAsAsync(); 90 | else 91 | throw ExceptionFactory.FailedTokenException(response); 92 | } 93 | catch (HttpRequestException hre) 94 | { 95 | throw new FailedRequestException(hre.Message); 96 | } 97 | } 98 | } 99 | 100 | /// Make an asynchronous GET request to the API. 101 | /// Expected Type of the response. 102 | /// URL of the GET request. 103 | /// The Typed response. 104 | /// 105 | public async Task GetApiRequestAsync(string url) 106 | { 107 | using (var client = new HttpClient()) 108 | { 109 | client.BaseAddress = _apiUrl; 110 | client.AddXAuthToken(_token); 111 | 112 | try 113 | { 114 | var response = await client.GetAsync(url); 115 | if (response.IsSuccessStatusCode) 116 | return await response.Content.ReadAsAsync(); 117 | 118 | throw ExceptionFactory.FailedGetRequest(response); 119 | } 120 | catch (HttpRequestException hre) 121 | { 122 | throw new FailedRequestException(hre.Message); 123 | } 124 | } 125 | } 126 | 127 | /// Make an asynchronous POST request to the API. 128 | /// Expected Type of the response. 129 | /// Expected Type of of the request message. 130 | /// URL of the POST request. 131 | /// The request. 132 | /// The Typed response. 133 | /// 134 | public async Task PostApiRequestAsync(string url, TRequestType request) 135 | { 136 | using (var client = new HttpClient()) 137 | { 138 | client.BaseAddress = _apiUrl; 139 | client.AddXAuthToken(_token); 140 | 141 | try 142 | { 143 | var response = await client.PostAsync(url, request, new JsonMediaTypeFormatter()); 144 | if (response.IsSuccessStatusCode) 145 | return await response.Content.ReadAsAsync(); 146 | 147 | throw ExceptionFactory.FailedPostRequest(response); 148 | } 149 | catch (HttpRequestException hre) 150 | { 151 | throw new FailedRequestException(hre.Message); 152 | } 153 | } 154 | } 155 | 156 | /// Make a DELETE request to the API. 157 | /// URL of the request. 158 | /// A Task. 159 | /// 160 | public async Task DeleteApiRequestAsync(string url) 161 | { 162 | using (var client = new HttpClient()) 163 | { 164 | client.BaseAddress = _apiUrl; 165 | client.AddXAuthToken(_token); 166 | 167 | try 168 | { 169 | var response = await client.DeleteAsync(url); 170 | if (!response.IsSuccessStatusCode) 171 | throw ExceptionFactory.FailedDeleteRequest(response); 172 | } 173 | catch (HttpRequestException hre) 174 | { 175 | throw new FailedRequestException(hre.Message); 176 | } 177 | } 178 | } 179 | 180 | /// Accessor for the Actions related methods. 181 | /// The actions accessor. 182 | /// 183 | public IActionsApi Actions { get; private set; } 184 | 185 | /// Accessor for the Packs related methods. 186 | /// The Packs accessor. 187 | /// 188 | public IPacksApi Packs { get; private set; } 189 | 190 | /// Accessor for the Executions related methods. 191 | /// The Executions accessor. 192 | /// 193 | public IExecutionsApi Executions { get; private set; } 194 | 195 | /// Accessor for the Rules related methods. 196 | /// The Rules accessor. 197 | public IRulesApi Rules { get; private set; } 198 | 199 | public void Dispose() 200 | { 201 | // cleanup 202 | } 203 | 204 | public bool HasToken() 205 | { 206 | return _token != null; 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /St2.Client/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.1.{build} 2 | os: Unstable 3 | branches: 4 | only: 5 | - master 6 | install: 7 | - ps: Get-PackageProvider -Name NuGet -Force 8 | assembly_info: 9 | patch: true 10 | file: AssemblyInfo.* 11 | assembly_version: "{version}" 12 | assembly_file_version: "{version}" 13 | assembly_informational_version: "{version}" 14 | 15 | configuration: Release 16 | 17 | build: 18 | project: St2.Client.sln 19 | publish_nuget: true 20 | before_build: 21 | - ps: | 22 | # Update Manifest File 23 | $stagingDirectory = (Resolve-Path ..).Path 24 | $manifest = Join-Path $pwd 'St2.Client.PowerShell\St2.Client.psd1' 25 | (Get-Content $manifest -Raw).Replace("1.0.0", $env:APPVEYOR_BUILD_VERSION) | Set-Content $manifest 26 | after_build: 27 | - ps: .\xmldoc2md\xmldoc2md.ps1 -xml "C:\projects\st2client\St2.Client\bin\Release\St2.Client.xml" -xsl "C:\projects\st2client\xmldoc2md\xmldoc2md.xsl" -output "C:\projects\st2client\docs\St2.Client.md" 28 | - ps: .\DocumentPowerShell.ps1 $($env:powershell_key) 29 | after_test: 30 | - ps: .\nuget\pack.ps1 31 | 32 | artifacts: 33 | - path: St2.Client\bin\Release\St2.Client.dll 34 | name: St2.Client.dll 35 | - path: '**\*.nupkg' 36 | - path: St2.Client\bin\Release\St2.Client.xml 37 | name: St2.Client.xml 38 | 39 | deploy: 40 | - provider: NuGet 41 | api_key: 42 | secure: qJZSv8NQtZWzFP++jAFq1/5abEpcDjW8Wl8rKNwleadnejoLwpdg1+3rUpSG38SN 43 | artifact: /.*\.nupkg/ 44 | 45 | environment: 46 | access_token: 47 | secure: O/sXyJYB0lM0WHQmuoG1LjfB/w9pwx8Pt3HmS13N9MXP7UqbY4/aJvJwemP0tlp2 48 | powershell_key: 49 | secure: kfybY3JPmM+VtiK6Uqb0EAhuKVycs7Wa3oaYLLZswT9XfPN34210+FJ7yCuWE7mT 50 | 51 | on_success: 52 | - git config --global user.email "anthony.p.shaw@gmail.com" 53 | - git config --global user.name "Anthony Shaw" 54 | - git config --global credential.helper store 55 | - git config --global push.default simple 56 | - ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n" 57 | - git add docs/ 58 | - git commit -m "Updated docs [skip appveyor]" --allow-empty 59 | - git push origin HEAD:master 60 | - ps: Invoke-WebRequest -Uri "https://readthedocs.org/build/st2client" -Method Post 61 | -------------------------------------------------------------------------------- /docs/St2.Client.md: -------------------------------------------------------------------------------- 1 | #St2.Client 2 | 3 | 4 | ##St2.Client.Apis.ActionsApi 5 | 6 | The actions api. 7 | 8 | ###Methods 9 | 10 | 11 | ####Constructor 12 | Initializes a new instance of the TonyBaloney.St2.Client.Apis.ActionsApi class. 13 | > #####Parameters 14 | > **host:** The host. 15 | 16 | > #####Exceptions 17 | > **System.ArgumentNullException:** Thrown when one or more required arguments are null. 18 | 19 | 20 | ####GetActionsAsync 21 | Get all available Actions. 22 | > #####Return value 23 | > A List of Actions. 24 | 25 | ####GetActionsForPackAsync(System.String) 26 | Gets actions for pack. 27 | > #####Parameters 28 | > **pack:** The pack name. 29 | 30 | > #####Return value 31 | > A List of Actions. 32 | 33 | ####GetActionsByNameAsync(System.String) 34 | Gets actions by name. 35 | > #####Parameters 36 | > **name:** The action name. 37 | 38 | > #####Return value 39 | > A List of Actions. 40 | 41 | ####DeleteActionAsync(System.String) 42 | Deletes the action described by actionId. 43 | > #####Parameters 44 | > **actionId:** can be either the ID (e.g. 1 or the ref e.g. mypack.myaction). 45 | 46 | 47 | ####CreateActionAsync(TonyBaloney.St2.Client.Models.CreateAction) 48 | Creates a new action. 49 | > #####Parameters 50 | > **action:** The to create. 51 | 52 | > #####Return value 53 | > The new action asynchronous. 54 | 55 | ##St2.Client.Apis.IActionsApi 56 | 57 | Interface for actions API. 58 | 59 | ###Methods 60 | 61 | 62 | ####GetActionsAsync 63 | Get all available Actions. 64 | > #####Return value 65 | > A List of . 66 | 67 | ####GetActionsForPackAsync(System.String) 68 | Gets actions for pack. 69 | > #####Parameters 70 | > **pack:** The pack name. 71 | 72 | > #####Return value 73 | > A List of . 74 | 75 | ####GetActionsByNameAsync(System.String) 76 | Gets actions by name. 77 | > #####Parameters 78 | > **name:** The action name. 79 | 80 | > #####Return value 81 | > A List of . 82 | 83 | ####DeleteActionAsync(System.String) 84 | Deletes the action described by actionId. 85 | > #####Parameters 86 | > **actionId:** can be either the ID (e.g. 1 or the ref e.g. mypack.myaction). 87 | 88 | 89 | ####CreateActionAsync(TonyBaloney.St2.Client.Models.CreateAction) 90 | Creates a new action. 91 | > #####Parameters 92 | > **action:** The to create. 93 | 94 | 95 | ##St2.Client.Apis.ExecutionsApi 96 | 97 | The executions API. 98 | 99 | > *See also: T:TonyBaloney.St2.Client.Apis.IExecutionsApi 100 | 101 | ###Methods 102 | 103 | 104 | ####Constructor 105 | Initializes a new instance of the TonyBaloney.St2.Client.Apis.ExecutionsApi class. 106 | > #####Parameters 107 | > **host:** The host. 108 | 109 | > #####Exceptions 110 | > **System.ArgumentNullException:** Thrown when one or more required arguments are null. 111 | 112 | 113 | ####GetExecutionAsync(System.String) 114 | Gets execution. 115 | > #####Parameters 116 | > **id:** The identifier. 117 | 118 | > #####Return value 119 | > The execution. 120 | 121 | ####GetExecutionsAsync(System.Int32) 122 | Gets a list of executions. 123 | > #####Parameters 124 | > **limit:** The number of items to return (default 5). 125 | 126 | > #####Return value 127 | > A list of . 128 | 129 | ####GetExecutionsForActionAsync(System.String,System.Int32) 130 | Gets executions for action. 131 | > #####Parameters 132 | > **actionName:** Name of the action. 133 | 134 | > **limit:** The number of items to return (default 5). 135 | 136 | > #####Return value 137 | > A list of . 138 | 139 | ####ExecuteActionAsync(System.String,System.Collections.Generic.Dictionary{System.String,System.String}) 140 | Executes the action. 141 | > #####Parameters 142 | > **actionName:** Name of the action. 143 | 144 | > **parameters:** The parameters for the given action. 145 | 146 | > #####Return value 147 | > The resulting execution; 148 | 149 | ####ExecuteActionAsync(System.String,System.Collections.Generic.Dictionary{System.String,System.Object}) 150 | Executes the action. 151 | > #####Parameters 152 | > **actionName:** Name of the action. 153 | 154 | > **parameters:** The parameters for the given action. 155 | 156 | > #####Return value 157 | > The resulting execution; 158 | 159 | ##St2.Client.Apis.IExecutionsApi 160 | 161 | Interface for executions API. 162 | 163 | ###Methods 164 | 165 | 166 | ####GetExecutionAsync(System.String) 167 | Gets execution. 168 | > #####Parameters 169 | > **id:** The identifier. 170 | 171 | > #####Return value 172 | > The execution. 173 | 174 | ####GetExecutionsAsync(System.Int32) 175 | Gets a list of executions. 176 | > #####Parameters 177 | > **limit:** The number of items to return (default 5). 178 | 179 | > #####Return value 180 | > A list of . 181 | 182 | ####GetExecutionsForActionAsync(System.String,System.Int32) 183 | Gets executions for action. 184 | > #####Parameters 185 | > **actionName:** Name of the action. 186 | 187 | > **limit:** The number of items to return (default 5). 188 | 189 | > #####Return value 190 | > A list of . 191 | 192 | ####ExecuteActionAsync(System.String,System.Collections.Generic.Dictionary{System.String,System.String}) 193 | Executes the action. 194 | > #####Parameters 195 | > **actionName:** Name of the action. 196 | 197 | > **parameters:** The parameters for the given action. 198 | 199 | > #####Return value 200 | > The resulting execution; 201 | 202 | ####ExecuteActionAsync(System.String,System.Collections.Generic.Dictionary{System.String,System.Object}) 203 | Executes the action. 204 | > #####Parameters 205 | > **actionName:** Name of the action. 206 | 207 | > **parameters:** The parameters for the given action. 208 | 209 | > #####Return value 210 | > The resulting execution; 211 | 212 | ##St2.Client.Apis.IPacksApi 213 | 214 | Interface for packs API. 215 | 216 | ###Methods 217 | 218 | 219 | ####GetPacksAsync 220 | Get a list of packs. 221 | > #####Return value 222 | > A List of . 223 | 224 | ####GetPacksByNameAsync(System.String) 225 | Gets packs by name. 226 | > #####Parameters 227 | > **packName:** Name of the pack. 228 | 229 | > #####Return value 230 | > A List of . 231 | 232 | ####GetPacksByIdAsync(System.String) 233 | Gets packs by identifier. 234 | > #####Parameters 235 | > **packId:** Identifier for the pack. 236 | 237 | > #####Return value 238 | > A List of . 239 | 240 | ##St2.Client.Apis.IRulesApi 241 | 242 | Interface for rules API. 243 | 244 | ###Methods 245 | 246 | 247 | ####GetRulesAsync 248 | Gets rules. 249 | > #####Return value 250 | > The rules. 251 | 252 | ####GetRulesForPackAsync(System.String) 253 | Gets rules for pack. 254 | > #####Parameters 255 | > **packName:** Name of the pack. 256 | 257 | > #####Return value 258 | > The rules for pack. 259 | 260 | ####GetRulesByNameAsync(System.String) 261 | Gets rules by name. 262 | > #####Parameters 263 | > **name:** The name. 264 | 265 | > #####Return value 266 | > The rules by name. 267 | 268 | ####DeleteRuleAsync(System.String) 269 | Deletes the rule described by ruleId. 270 | > #####Parameters 271 | > **ruleId:** Identifier for the rule. 272 | 273 | > #####Return value 274 | > A Task. 275 | 276 | ##St2.Client.Apis.PacksApi 277 | 278 | The packs api. 279 | 280 | > *See also: T:TonyBaloney.St2.Client.Apis.IPacksApi 281 | 282 | ###Methods 283 | 284 | 285 | ####Constructor 286 | Initializes a new instance of the TonyBaloney.St2.Client.Apis.PacksApi class. 287 | > #####Parameters 288 | > **host:** The host. 289 | 290 | > #####Exceptions 291 | > **System.ArgumentNullException:** Thrown when one or more required arguments are null. 292 | 293 | 294 | ####GetPacksAsync 295 | Get a list of packs. 296 | > #####Return value 297 | > A List of . 298 | 299 | ####GetPacksByNameAsync(System.String) 300 | Gets packs by name. 301 | > #####Parameters 302 | > **packName:** Name of the pack. 303 | 304 | > #####Return value 305 | > A List of . 306 | 307 | ####GetPacksByIdAsync(System.String) 308 | Gets packs by identifier. 309 | > #####Parameters 310 | > **packId:** Identifier for the pack. 311 | 312 | > #####Return value 313 | > A List of . 314 | 315 | ##St2.Client.Apis.RulesApi 316 | 317 | The rules api. 318 | 319 | > *See also: T:TonyBaloney.St2.Client.Apis.IRulesApi 320 | 321 | ###Fields 322 | 323 | ####_host 324 | The host process. 325 | ###Methods 326 | 327 | 328 | ####Constructor 329 | Initializes a new instance of the TonyBaloney.St2.Client.Apis.RulesApi class. 330 | > #####Parameters 331 | > **host:** The host. 332 | 333 | > #####Exceptions 334 | > **System.ArgumentNullException:** Thrown when one or more required arguments are null. 335 | 336 | 337 | ####GetRulesAsync 338 | Gets rules . 339 | > #####Return value 340 | > The rules . 341 | 342 | ####GetRulesForPackAsync(System.String) 343 | Gets rules for pack . 344 | > #####Parameters 345 | > **packName:** Name of the pack. 346 | 347 | > #####Return value 348 | > The rules for pack . 349 | 350 | ####GetRulesByNameAsync(System.String) 351 | Gets rules by name . 352 | > #####Parameters 353 | > **name:** The rule name. 354 | 355 | > #####Return value 356 | > The rules by name . 357 | 358 | ####DeleteRuleAsync(System.String) 359 | Deletes the rule described by ruleId. 360 | > #####Parameters 361 | > **ruleId:** Identifier for the rule. 362 | 363 | > #####Return value 364 | > A Task. 365 | 366 | ##St2.Client.Exceptions.FailedRequestException 367 | 368 | Exception for signalling failed request errors. 369 | 370 | > *See also: T:System.Exception 371 | 372 | ###Methods 373 | 374 | 375 | ####Constructor 376 | Initializes a new instance of the TonyBaloney.St2.Client.Exceptions.FailedRequestException class. 377 | > #####Parameters 378 | > **message:** The message. 379 | 380 | 381 | ####Constructor 382 | Initializes a new instance of the FailedRequestException class. 383 | > #####Parameters 384 | > **failureMessage:** Message describing the failure. 385 | 386 | > **requestUri:** URI of the request. 387 | 388 | > **statusCode:** The status code. 389 | 390 | > **responseMessage:** Message describing the response. 391 | 392 | 393 | ##St2.Client.Exceptions.InvalidTokenException 394 | 395 | Exception for signalling invalid token errors. 396 | 397 | > *See also: T:System.Exception 398 | 399 | ###Methods 400 | 401 | 402 | ####Constructor 403 | Initializes a new instance of the TonyBaloney.St2.Client.Exceptions.InvalidTokenException class. 404 | > #####Parameters 405 | > **message:** The message. 406 | 407 | 408 | ##St2.Client.AuthExtensions 409 | 410 | An authentication extensions. 411 | 412 | ###Methods 413 | 414 | 415 | ####AddXAuthToken(System.Net.Http.HttpClient,TonyBaloney.St2.Client.Models.TokenResponse) 416 | A HttpClient extension method that adds an x-auth-token to the client headers 417 | > #####Parameters 418 | > **client:** The client to act on. 419 | 420 | > **token:** The token. 421 | 422 | 423 | ##St2.Client.ISt2Client 424 | 425 | Interface for StackStorm API client. 426 | 427 | ###Properties 428 | 429 | ####Actions 430 | Accessor for the Actions related methods The actions accessor. 431 | ####Packs 432 | Accessor for the Packs related methods. The Packs accessor. 433 | ####Executions 434 | Accessor for the Executions related methods. The Executions accessor. 435 | ####Rules 436 | Accessor for the Rules related methods. The Rules accessor. 437 | ###Methods 438 | 439 | 440 | ####RefreshTokenAsync 441 | Refresh the auth token. 442 | 443 | ####GetApiRequestAsync``1(System.String) 444 | Make an asynchronous GET request to the API. 445 | > #####Parameters 446 | > **url:** URL of the GET request. 447 | 448 | > #####Return value 449 | > The Typed response. 450 | 451 | ####PostApiRequestAsync``2(System.String,``1) 452 | Make an asynchronous POST request to the API. 453 | > #####Parameters 454 | > **url:** URL of the POST request. 455 | 456 | > **request:** The request. 457 | 458 | > #####Return value 459 | > The Typed response. 460 | 461 | ####DeleteApiRequestAsync(System.String) 462 | Make a DELETE request to the API. 463 | > #####Parameters 464 | > **url:** URL of the request. 465 | 466 | 467 | ####HasToken 468 | Query if this object has a token. 469 | > #####Return value 470 | > true if token, false if not. 471 | 472 | ##St2.Client.St2Client 473 | 474 | StackStorm API Client. 475 | 476 | ###Fields 477 | 478 | ####_username 479 | The username. 480 | ####_password 481 | The password. 482 | ####_authUrl 483 | URL of the authentication endpoint. 484 | ####_apiUrl 485 | URL of the API. 486 | ####_token 487 | The token. 488 | ###Properties 489 | 490 | ####Actions 491 | Accessor for the Actions related methods. The actions accessor. 492 | ####Packs 493 | Accessor for the Packs related methods. The Packs accessor. 494 | ####Executions 495 | Accessor for the Executions related methods. The Executions accessor. 496 | ####Rules 497 | Accessor for the Rules related methods. The Rules accessor. 498 | ###Methods 499 | 500 | 501 | ####Constructor 502 | Initializes a new instance of the TonyBaloney.St2.Client.St2Client class. 503 | > #####Parameters 504 | > **authUrl:** URL of the authentication endpoint. 505 | 506 | > **apiUrl:** URL of the API. 507 | 508 | > **username:** The username. 509 | 510 | > **password:** The password. 511 | 512 | > **ignoreCertificateValidation:** true to ignore certificate validation. 513 | 514 | > #####Exceptions 515 | > **System.ArgumentException:** Thrown when one or more arguments have unsupported or illegal values. 516 | 517 | 518 | ####RefreshTokenAsync 519 | Refresh the auth token. 520 | > #####Return value 521 | > A Task. 522 | 523 | ####GetApiRequestAsync``1(System.String) 524 | Make an asynchronous GET request to the API. 525 | > #####Parameters 526 | > **url:** URL of the GET request. 527 | 528 | > #####Return value 529 | > The Typed response. 530 | 531 | ####PostApiRequestAsync``2(System.String,``1) 532 | Make an asynchronous POST request to the API. 533 | > #####Parameters 534 | > **url:** URL of the POST request. 535 | 536 | > **request:** The request. 537 | 538 | > #####Return value 539 | > The Typed response. 540 | 541 | ####DeleteApiRequestAsync(System.String) 542 | Make a DELETE request to the API. 543 | > #####Parameters 544 | > **url:** URL of the request. 545 | 546 | > #####Return value 547 | > A Task. -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # St2Client 2 | 3 | A client for the [StackStorm](http://stackstorm.com) API to get actions, packs and execute actions from C#.NET 4 | 5 | [![Build status](https://ci.appveyor.com/api/projects/status/y7rueuv6m1v0g7p8?svg=true)](https://ci.appveyor.com/project/tonybaloney/st2client) 6 | 7 | 8 | ## Using the C#.NET client 9 | 10 | ### Download packages 11 | The .NET client is available on nuget.org 12 | * Release - [![NuGet](https://img.shields.io/nuget/v/St2.Client.svg)](https://www.nuget.org/packages/St2.Client/) 13 | 14 | ### Example 15 | 16 | ```csharp 17 | St2Client apiClient = new St2Client("http://12.3.2.3:9100", "http://12.3.2.3:9101", "testu", "testp"); 18 | // login and get a token 19 | await apiClient.RefreshTokenAsync(); 20 | 21 | var actions = await apiClient.Actions.GetActionsAsync(); 22 | ``` -------------------------------------------------------------------------------- /docs/powershell/Get-St2Actions.md: -------------------------------------------------------------------------------- 1 | Get-St2Actions 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Get the available actions in a pack 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Get-St2Actions [-Connection ] [-Pack ] [-PackName ] [-Name ] [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | 14 | 15 | ## PARAMETERS 16 | ### -Connection <St2ClientConnection> 17 | The connection object (defaults to the one stored in the session) 18 | ``` 19 | Required? false 20 | Position? named 21 | Default value 22 | Accept pipeline input? true (ByPropertyName) 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -Pack <Pack> 27 | The pack object, returned by Get-St2Packs 28 | ``` 29 | Required? false 30 | Position? named 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -PackName <String> 37 | The name of the pack 38 | ``` 39 | Required? false 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -Name <String> 47 | 48 | ``` 49 | Required? false 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -InformationAction <ActionPreference> 57 | 58 | ``` 59 | Required? false 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ### -InformationVariable <String> 67 | 68 | ``` 69 | Required? false 70 | Position? named 71 | Default value 72 | Accept pipeline input? false 73 | Accept wildcard characters? false 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | 79 | ## OUTPUTS 80 | 81 | 82 | ## NOTES 83 | 84 | 85 | ## EXAMPLES 86 | ### Example 1 87 | ```powershell 88 | Get-St2Actions -PackName "st2_dimensiondata" -Name "list_locations" 89 | ``` 90 | 91 | 92 | -------------------------------------------------------------------------------- /docs/powershell/Get-St2Executions.md: -------------------------------------------------------------------------------- 1 | Get-St2Executions 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Get a list of executions (run jobs) 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Get-St2Executions [-Connection ] [-Limit ] [-ActionName ] [-Action ] [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | 14 | 15 | ## PARAMETERS 16 | ### -Connection <St2ClientConnection> 17 | The connection object (defaults to the one stored in the session) 18 | ``` 19 | Required? false 20 | Position? named 21 | Default value 22 | Accept pipeline input? true (ByPropertyName) 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -Limit <Int32> 27 | Limit the number of returned results 28 | ``` 29 | Required? false 30 | Position? named 31 | Default value 5 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -ActionName <String> 37 | The name of the action, e.g. "libcloud.list_vms" 38 | ``` 39 | Required? false 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -Action <Action> 47 | The Action object returned by Get-St2Actions 48 | ``` 49 | Required? false 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -InformationAction <ActionPreference> 57 | 58 | ``` 59 | Required? false 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ### -InformationVariable <String> 67 | 68 | ``` 69 | Required? false 70 | Position? named 71 | Default value 72 | Accept pipeline input? false 73 | Accept wildcard characters? false 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | 79 | ## OUTPUTS 80 | 81 | 82 | ## NOTES 83 | 84 | 85 | ## EXAMPLES 86 | ### Example 1 87 | ```powershell 88 | $MyPack = Get-St2Packs -Name "example" 89 | 90 | foreach($action in $actions){ 91 | Write-Output "Getting executions for action $action.name" 92 | Get-St2Executions -Action $action -Connection $conn 93 | } 94 | ``` 95 | 96 | 97 | -------------------------------------------------------------------------------- /docs/powershell/Get-St2Packs.md: -------------------------------------------------------------------------------- 1 | Get-St2Packs 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Get the packs installed in this StackStorm database 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Get-St2Packs [-Connection ] [-Id ] [-Name ] [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | 14 | 15 | ## PARAMETERS 16 | ### -Connection <St2ClientConnection> 17 | The connection object (defaults to the one stored in the session) 18 | ``` 19 | Required? false 20 | Position? named 21 | Default value 22 | Accept pipeline input? true (ByPropertyName) 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -Id <String> 27 | 28 | ``` 29 | Required? false 30 | Position? named 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -Name <String> 37 | 38 | ``` 39 | Required? false 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -InformationAction <ActionPreference> 47 | 48 | ``` 49 | Required? false 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -InformationVariable <String> 57 | 58 | ``` 59 | Required? false 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ## INPUTS 67 | 68 | 69 | ## OUTPUTS 70 | 71 | 72 | ## NOTES 73 | 74 | 75 | ## EXAMPLES 76 | ### Example 1 77 | ```powershell 78 | $MyPack = Get-St2Packs -Name "example" 79 | 80 | foreach($action in $actions){ 81 | Write-Output "Getting executions for action $action.name" 82 | Get-St2Executions -Action $action -Connection $conn 83 | } 84 | ``` 85 | 86 | 87 | -------------------------------------------------------------------------------- /docs/powershell/Get-St2Rules.md: -------------------------------------------------------------------------------- 1 | Get-St2Rules 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Gets the rules available 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Get-St2Rules [-Connection ] [-PackName ] [-Pack ] [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | 14 | 15 | ## PARAMETERS 16 | ### -Connection <St2ClientConnection> 17 | The connection object (defaults to the one stored in the session) 18 | ``` 19 | Required? false 20 | Position? named 21 | Default value 22 | Accept pipeline input? true (ByPropertyName) 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -PackName <String> 27 | Filter by pack (name) 28 | ``` 29 | Required? false 30 | Position? named 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -Pack <Pack> 37 | Filter by pack 38 | ``` 39 | Required? false 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -InformationAction <ActionPreference> 47 | 48 | ``` 49 | Required? false 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -InformationVariable <String> 57 | 58 | ``` 59 | Required? false 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ## INPUTS 67 | 68 | 69 | ## OUTPUTS 70 | 71 | 72 | ## NOTES 73 | 74 | 75 | ## EXAMPLES 76 | -------------------------------------------------------------------------------- /docs/powershell/Install-St2Pack.md: -------------------------------------------------------------------------------- 1 | Install-St2Pack 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Install a pack 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Install-St2Pack [-Connection ] -Name [-RepoUrl ] [-Branch ] [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Installs a pack by running the packs.install action 14 | 15 | ## PARAMETERS 16 | ### -Connection <St2ClientConnection> 17 | 18 | ``` 19 | Required? false 20 | Position? named 21 | Default value 22 | Accept pipeline input? true (ByPropertyName) 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -Name <String> 27 | The pack name 28 | ``` 29 | Required? true 30 | Position? named 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -RepoUrl <String> 37 | The repository URL (git) 38 | ``` 39 | Required? false 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -Branch <String> 47 | The branch to select on the repository 48 | ``` 49 | Required? false 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -InformationAction <ActionPreference> 57 | 58 | ``` 59 | Required? false 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ### -InformationVariable <String> 67 | 68 | ``` 69 | Required? false 70 | Position? named 71 | Default value 72 | Accept pipeline input? false 73 | Accept wildcard characters? false 74 | ``` 75 | 76 | ## INPUTS 77 | 78 | 79 | ## OUTPUTS 80 | 81 | 82 | ## NOTES 83 | 84 | 85 | ## EXAMPLES 86 | -------------------------------------------------------------------------------- /docs/powershell/Invoke-St2Action.md: -------------------------------------------------------------------------------- 1 | Invoke-St2Action 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Invoke (run) an action within a pack 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Invoke-St2Action [-Connection ] -Parameters -ActionName [-InformationAction ] [-InformationVariable ] [] 10 | 11 | Invoke-St2Action [-Connection ] -Parameters -Action [-InformationAction ] [-InformationVariable ] [] 12 | ``` 13 | 14 | ## DESCRIPTION 15 | 16 | 17 | ## PARAMETERS 18 | ### -Connection <St2ClientConnection> 19 | The connection object (defaults to the one stored in the session) 20 | ``` 21 | Required? false 22 | Position? named 23 | Default value 24 | Accept pipeline input? true (ByPropertyName) 25 | Accept wildcard characters? false 26 | ``` 27 | 28 | ### -Parameters <Hashtable> 29 | Collection of parameters for the given action, each a Key-value-pair with the variable and the value. 30 | ``` 31 | Required? true 32 | Position? named 33 | Default value 34 | Accept pipeline input? false 35 | Accept wildcard characters? false 36 | ``` 37 | 38 | ### -ActionName <String> 39 | The name of the action to run, including the pack name 40 | ``` 41 | Required? true 42 | Position? named 43 | Default value 44 | Accept pipeline input? false 45 | Accept wildcard characters? false 46 | ``` 47 | 48 | ### -InformationAction <ActionPreference> 49 | 50 | ``` 51 | Required? false 52 | Position? named 53 | Default value 54 | Accept pipeline input? false 55 | Accept wildcard characters? false 56 | ``` 57 | 58 | ### -InformationVariable <String> 59 | 60 | ``` 61 | Required? false 62 | Position? named 63 | Default value 64 | Accept pipeline input? false 65 | Accept wildcard characters? false 66 | ``` 67 | 68 | ### -Action <Action> 69 | The action object, from Get-St2Actions 70 | ``` 71 | Required? true 72 | Position? named 73 | Default value 74 | Accept pipeline input? false 75 | Accept wildcard characters? false 76 | ``` 77 | 78 | ## INPUTS 79 | 80 | 81 | ## OUTPUTS 82 | 83 | 84 | ## NOTES 85 | 86 | 87 | ## EXAMPLES 88 | ### Run an action by name 89 | ```powershell 90 | Invoke-St2Action -ActionName "libcloud.list_vms" -Parameters @{"credentials"="my-aws"} 91 | ``` 92 | 93 | 94 | ### Run an action by reference 95 | ```powershell 96 | $action = Get-St2Actions -PackName "libcloud" -Name "list_vms" 97 | ``` 98 | 99 | 100 | -------------------------------------------------------------------------------- /docs/powershell/New-St2Action.md: -------------------------------------------------------------------------------- 1 | New-St2Action 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Create a new action inside a pack 6 | 7 | ## SYNTAX 8 | ```powershell 9 | New-St2Action -Parameters -RunnerType [-Connection ] -Name -Description -EntryPoint -Pack [-InformationAction ] [-InformationVariable ] [] 10 | 11 | New-St2Action -Parameters -RunnerType [-Connection ] -Name -Description -EntryPoint -PackName [-InformationAction ] [-InformationVariable ] [] 12 | ``` 13 | 14 | ## DESCRIPTION 15 | 16 | 17 | ## PARAMETERS 18 | ### -Parameters <NamedActionParameter[]> 19 | The collection of parameters created by New-St2ActionParameter 20 | ``` 21 | Required? true 22 | Position? named 23 | Default value 24 | Accept pipeline input? false 25 | Accept wildcard characters? false 26 | ``` 27 | 28 | ### -RunnerType <RunnerType> 29 | The type of runner for the action 30 | ``` 31 | Required? true 32 | Position? named 33 | Default value 34 | Accept pipeline input? false 35 | Accept wildcard characters? false 36 | ``` 37 | 38 | ### -Connection <St2ClientConnection> 39 | The connection object (defaults to the one stored in the session) 40 | ``` 41 | Required? false 42 | Position? named 43 | Default value 44 | Accept pipeline input? true (ByPropertyName) 45 | Accept wildcard characters? false 46 | ``` 47 | 48 | ### -Name <String> 49 | The name of the action 50 | ``` 51 | Required? true 52 | Position? named 53 | Default value 54 | Accept pipeline input? false 55 | Accept wildcard characters? false 56 | ``` 57 | 58 | ### -Description <String> 59 | Description of the action 60 | ``` 61 | Required? true 62 | Position? named 63 | Default value 64 | Accept pipeline input? false 65 | Accept wildcard characters? false 66 | ``` 67 | 68 | ### -EntryPoint <String> 69 | The entry point (script file name) 70 | ``` 71 | Required? true 72 | Position? named 73 | Default value 74 | Accept pipeline input? false 75 | Accept wildcard characters? false 76 | ``` 77 | 78 | ### -Pack <Pack> 79 | The pack to put the action into 80 | ``` 81 | Required? true 82 | Position? named 83 | Default value 84 | Accept pipeline input? false 85 | Accept wildcard characters? false 86 | ``` 87 | 88 | ### -InformationAction <ActionPreference> 89 | 90 | ``` 91 | Required? false 92 | Position? named 93 | Default value 94 | Accept pipeline input? false 95 | Accept wildcard characters? false 96 | ``` 97 | 98 | ### -InformationVariable <String> 99 | 100 | ``` 101 | Required? false 102 | Position? named 103 | Default value 104 | Accept pipeline input? false 105 | Accept wildcard characters? false 106 | ``` 107 | 108 | ### -PackName <String> 109 | The pack name to put the action into 110 | ``` 111 | Required? true 112 | Position? named 113 | Default value 114 | Accept pipeline input? false 115 | Accept wildcard characters? false 116 | ``` 117 | 118 | ## INPUTS 119 | 120 | 121 | ## OUTPUTS 122 | 123 | 124 | ## NOTES 125 | 126 | 127 | ## EXAMPLES 128 | -------------------------------------------------------------------------------- /docs/powershell/New-St2ActionParameter.md: -------------------------------------------------------------------------------- 1 | New-St2ActionParameter 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Create a new parameter for using with New-St2Action 6 | 7 | ## SYNTAX 8 | ```powershell 9 | New-St2ActionParameter -Name -Type -Description -Immutable [] -Required [] -DefaultValue [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Defines a new instance of NamedActionParameter class. 14 | 15 | ## PARAMETERS 16 | ### -Name <String> 17 | The name of the parameter 18 | ``` 19 | Required? true 20 | Position? named 21 | Default value 22 | Accept pipeline input? false 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -Type <ParameterType> 27 | The parameter type 28 | ``` 29 | Required? true 30 | Position? named 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -Description <String> 37 | Description of the parameter 38 | ``` 39 | Required? true 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -Immutable <Boolean> 47 | Is fixed (immutable) 48 | ``` 49 | Required? true 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -Required <Boolean> 57 | Is the parameter required? 58 | ``` 59 | Required? true 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ### -DefaultValue <Object> 67 | What is the default value of the parameter 68 | ``` 69 | Required? true 70 | Position? named 71 | Default value 72 | Accept pipeline input? false 73 | Accept wildcard characters? false 74 | ``` 75 | 76 | ### -InformationAction <ActionPreference> 77 | 78 | ``` 79 | Required? false 80 | Position? named 81 | Default value 82 | Accept pipeline input? false 83 | Accept wildcard characters? false 84 | ``` 85 | 86 | ### -InformationVariable <String> 87 | 88 | ``` 89 | Required? false 90 | Position? named 91 | Default value 92 | Accept pipeline input? false 93 | Accept wildcard characters? false 94 | ``` 95 | 96 | ## INPUTS 97 | 98 | 99 | ## OUTPUTS 100 | 101 | 102 | ## NOTES 103 | 104 | 105 | ## EXAMPLES 106 | -------------------------------------------------------------------------------- /docs/powershell/New-St2ClientConnection.md: -------------------------------------------------------------------------------- 1 | New-St2ClientConnection 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Create a new connection to a StackStorm (St2) API endpoint. 6 | 7 | ## SYNTAX 8 | ```powershell 9 | New-St2ClientConnection -Username -Password [-Name ] -ApiUrl -AuthApiUrl [-IgnoreCertificateValidation []] [-InformationAction ] [-InformationVariable ] [] 10 | ``` 11 | 12 | ## DESCRIPTION 13 | Create a new connection to a StackStorm (St2) API endpoint by authenticating with a username/password credential and gathering an OAuth token to use in subsequent requests. Connections will be saved to the current session so you do not need to specify the -Connection parameter with each request. 14 | 15 | ## PARAMETERS 16 | ### -Username <String> 17 | The username to authenticate with StackStorm 18 | ``` 19 | Required? true 20 | Position? named 21 | Default value 22 | Accept pipeline input? false 23 | Accept wildcard characters? false 24 | ``` 25 | 26 | ### -Password <String> 27 | The password to authenticate with StackStorm 28 | ``` 29 | Required? true 30 | Position? named 31 | Default value 32 | Accept pipeline input? false 33 | Accept wildcard characters? false 34 | ``` 35 | 36 | ### -Name <String> 37 | The name of your connection (optional) 38 | ``` 39 | Required? false 40 | Position? named 41 | Default value 42 | Accept pipeline input? false 43 | Accept wildcard characters? false 44 | ``` 45 | 46 | ### -ApiUrl <String> 47 | The URL of the API, typically http(s)://(ip):9101/ 48 | ``` 49 | Required? true 50 | Position? named 51 | Default value 52 | Accept pipeline input? false 53 | Accept wildcard characters? false 54 | ``` 55 | 56 | ### -AuthApiUrl <String> 57 | The URL of the Authentication API, typically http(s)://(ip):9100/ 58 | ``` 59 | Required? true 60 | Position? named 61 | Default value 62 | Accept pipeline input? false 63 | Accept wildcard characters? false 64 | ``` 65 | 66 | ### -InformationAction <ActionPreference> 67 | 68 | ``` 69 | Required? false 70 | Position? named 71 | Default value 72 | Accept pipeline input? false 73 | Accept wildcard characters? false 74 | ``` 75 | 76 | ### -InformationVariable <String> 77 | 78 | ``` 79 | Required? false 80 | Position? named 81 | Default value 82 | Accept pipeline input? false 83 | Accept wildcard characters? false 84 | ``` 85 | 86 | ### -IgnoreCertificateValidation <SwitchParameter> 87 | Ignore certificate validation (e.g. using the default self-signed certificate) 88 | ``` 89 | Required? false 90 | Position? named 91 | Default value 92 | Accept pipeline input? false 93 | Accept wildcard characters? false 94 | ``` 95 | 96 | ## INPUTS 97 | 98 | 99 | ## OUTPUTS 100 | 101 | 102 | ## NOTES 103 | 104 | 105 | ## EXAMPLES 106 | -------------------------------------------------------------------------------- /docs/powershell/Remove-St2Action.md: -------------------------------------------------------------------------------- 1 | Remove-St2Action 2 | =================== 3 | 4 | ## SYNOPSIS 5 | Delete an existing action from a pack 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Remove-St2Action [-Connection ] -Id [-InformationAction ] [-InformationVariable ] [] 10 | 11 | Remove-St2Action [-Connection ] -Action [-InformationAction ] [-InformationVariable ] [] 12 | ``` 13 | 14 | ## DESCRIPTION 15 | 16 | 17 | ## PARAMETERS 18 | ### -Connection <St2ClientConnection> 19 | The connection object (defaults to the one stored in the session) 20 | ``` 21 | Required? false 22 | Position? named 23 | Default value 24 | Accept pipeline input? true (ByPropertyName) 25 | Accept wildcard characters? false 26 | ``` 27 | 28 | ### -Id <String> 29 | The Id of the action to delete 30 | ``` 31 | Required? true 32 | Position? named 33 | Default value 34 | Accept pipeline input? false 35 | Accept wildcard characters? false 36 | ``` 37 | 38 | ### -InformationAction <ActionPreference> 39 | 40 | ``` 41 | Required? false 42 | Position? named 43 | Default value 44 | Accept pipeline input? false 45 | Accept wildcard characters? false 46 | ``` 47 | 48 | ### -InformationVariable <String> 49 | 50 | ``` 51 | Required? false 52 | Position? named 53 | Default value 54 | Accept pipeline input? false 55 | Accept wildcard characters? false 56 | ``` 57 | 58 | ### -Action <Action> 59 | The action to delete 60 | ``` 61 | Required? true 62 | Position? named 63 | Default value 64 | Accept pipeline input? false 65 | Accept wildcard characters? false 66 | ``` 67 | 68 | ## INPUTS 69 | 70 | 71 | ## OUTPUTS 72 | 73 | 74 | ## NOTES 75 | 76 | 77 | ## EXAMPLES 78 | -------------------------------------------------------------------------------- /docs/powershell/Remove-St2Rule.md: -------------------------------------------------------------------------------- 1 | Remove-St2Rule 2 | =================== 3 | 4 | ## SYNOPSIS 5 | 6 | 7 | ## SYNTAX 8 | ```powershell 9 | Remove-St2Rule [-Connection ] -Id [-InformationAction ] [-InformationVariable ] [] 10 | 11 | Remove-St2Rule [-Connection ] -Rule [-InformationAction ] [-InformationVariable ] [] 12 | ``` 13 | 14 | ## DESCRIPTION 15 | 16 | 17 | ## PARAMETERS 18 | ### -Connection <St2ClientConnection> 19 | 20 | ``` 21 | Required? false 22 | Position? named 23 | Default value 24 | Accept pipeline input? true (ByPropertyName) 25 | Accept wildcard characters? false 26 | ``` 27 | 28 | ### -Id <String> 29 | 30 | ``` 31 | Required? true 32 | Position? named 33 | Default value 34 | Accept pipeline input? false 35 | Accept wildcard characters? false 36 | ``` 37 | 38 | ### -InformationAction <ActionPreference> 39 | 40 | ``` 41 | Required? false 42 | Position? named 43 | Default value 44 | Accept pipeline input? false 45 | Accept wildcard characters? false 46 | ``` 47 | 48 | ### -InformationVariable <String> 49 | 50 | ``` 51 | Required? false 52 | Position? named 53 | Default value 54 | Accept pipeline input? false 55 | Accept wildcard characters? false 56 | ``` 57 | 58 | ### -Rule <Rule> 59 | 60 | ``` 61 | Required? true 62 | Position? named 63 | Default value 64 | Accept pipeline input? false 65 | Accept wildcard characters? false 66 | ``` 67 | 68 | ## INPUTS 69 | 70 | 71 | ## OUTPUTS 72 | 73 | 74 | ## NOTES 75 | 76 | 77 | ## EXAMPLES 78 | -------------------------------------------------------------------------------- /docs/powershell/index.md: -------------------------------------------------------------------------------- 1 | PowerShell Module for StackStorm 2 | ============= 3 | 4 | Installing 5 | ----- 6 | The PowerShell module is published via the CI process to nuget.org. 7 | 8 | * Release - [![NuGet](https://img.shields.io/nuget/v/St2.Client.PowerShell.svg)](https://www.nuget.org/packages/St2.Client.PowerShell/) 9 | 10 | Download the package then open using the [Nuget Package Explorer](https://npe.codeplex.com/) 11 | 12 | Extract the package contents to `c:\Program Files\WindowsPowerShell\Modules\St2.Client` to install the module. 13 | 14 | Using 15 | ----- 16 | 17 | ```powershell 18 | 19 | Import-Module St2.Client 20 | $conn = New-St2ClientConnection -Username testu -Password testp -ApiUrl "http://12.3.2.3:9101" -AuthApiUrl "http://12.3.2.3:9100" 21 | 22 | $MyPack = Get-St2Packs -Name "example" 23 | 24 | $actions = Get-St2Actions -Pack $MyPack 25 | 26 | foreach($action in $actions){ 27 | Write-Output "Getting executions for action $action.name" 28 | Get-St2Executions -Action $action -Connection $conn 29 | } 30 | 31 | $action = Get-St2Actions -PackName "st2_dimensiondata" -Name "list_locations" 32 | Invoke-St2Action -Action $action -Parameters @{"region"="dd-au"} 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonybaloney/St2Client/6d6fa592bbb444aed3711a1fdf0633bcec8d62c3/nuget/NuGet.exe -------------------------------------------------------------------------------- /nuget/nuget-anycpu.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tonybaloney/St2Client/6d6fa592bbb444aed3711a1fdf0633bcec8d62c3/nuget/nuget-anycpu.exe -------------------------------------------------------------------------------- /nuget/pack.ps1: -------------------------------------------------------------------------------- 1 | $root = (split-path -parent $MyInvocation.MyCommand.Definition) + '\..' 2 | $version = [System.Reflection.Assembly]::LoadFile("$root\St2.Client\bin\Release\St2.Client.dll").GetName().Version 3 | $versionStr = "{0}.{1}.{2}" -f ($version.Major, $version.Minor, $version.Build) 4 | 5 | Write-Host "Setting .nuspec version tag to $versionStr" 6 | 7 | $content = (Get-Content $root\St2.Client\St2.Client.nuspec) 8 | $content = $content -replace '\$version\$',$versionStr 9 | 10 | $content = (Get-Content $root\St2.Client.PowerShell\St2.Client.PowerShell.nuspec) 11 | $content = $content -replace '\$version\$',$versionStr -------------------------------------------------------------------------------- /xmldoc2md/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /xmldoc2md/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jaime Olivares 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /xmldoc2md/Program.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.IO; 3 | using System.Xml.Xsl; 4 | using System.Text; 5 | 6 | namespace XmlDocToMD 7 | { 8 | /// 9 | /// The unique class of the application 10 | /// 11 | class Program 12 | { 13 | /// 14 | /// The entry point of the application 15 | /// 16 | /// This is the unique functional method. All others are dummies 17 | /// The argument list. Not used 18 | static void Main(string[] args) 19 | { 20 | var sourceFile = "xmldoc2md.xml"; 21 | var stylesheet = "xmldoc2md.xsl"; 22 | var outputMD = "sample.md"; 23 | 24 | // Load stylesheet 25 | var xslt = new XslCompiledTransform(true); 26 | xslt.Load(stylesheet); 27 | 28 | // Creates the output buffer 29 | var sb = new StringBuilder(); 30 | 31 | // Performs the transformation 32 | using (var sw = new StringWriter(sb)) 33 | { 34 | xslt.Transform(sourceFile, null, sw); 35 | } 36 | 37 | var md = sb.ToString(); 38 | File.WriteAllText(outputMD, md); 39 | Process.Start(outputMD); 40 | } 41 | 42 | /// 43 | /// A dummy method 44 | /// 45 | /// An integer argument 46 | /// A string representation of the argument 47 | /// Whenever a file error occurs 48 | /// 49 | /// 50 | /// int x = 1; 51 | /// string s = DummyMethod(x); 52 | /// 53 | /// 54 | public string DummyMethod(int arg1) 55 | { 56 | this.DummyProperty = arg1.ToString(); 57 | return this.DummyProperty; 58 | } 59 | 60 | /// 61 | /// A private method 62 | /// 63 | private void PrivateMethod() { } 64 | 65 | /// 66 | /// A dummy property 67 | /// 68 | /// 69 | /// A string value 70 | public string DummyProperty 71 | { 72 | get { return this.DummyField; } 73 | set { this.DummyField = value; } 74 | } 75 | 76 | /// 77 | /// A dummy field 78 | /// 79 | /// Backend for . 80 | public string DummyField; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /xmldoc2md/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("XmlDocToMD")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("XmlDocToMD")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0596ca66-e899-4637-9535-e61126971b48")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /xmldoc2md/README.md: -------------------------------------------------------------------------------- 1 | # xmldoc2md 2 | Automatic documentation markdown formatter for Visual Studio projects 3 | 4 | See the article at [CodeProject](http://www.codeproject.com/Articles/1030797/Automatic-markdown-formatting-for-VS-xml-documenta) 5 | -------------------------------------------------------------------------------- /xmldoc2md/XmlDoc2MD.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0596CA66-E899-4637-9535-E61126971B48} 8 | Exe 9 | Properties 10 | XmlDoc2MD 11 | XmlDoc2MD 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | bin\Debug\XmlDoc2MD.xml 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Always 57 | 58 | 59 | 60 | 61 | Powershell.exe -ExecutionPolicy Unrestricted -file "$(ProjectDir)xmldoc2md.ps1" -xml "$(TargetDir)xmldoc2md.xml" -xsl "$(ProjectDir)xmldoc2md.xsl" -output "$(SolutionDir)xmldoc2md.md" 62 | 63 | 70 | -------------------------------------------------------------------------------- /xmldoc2md/XmlDoc2MD.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlDoc2MD", "XmlDoc2MD.csproj", "{0596CA66-E899-4637-9535-E61126971B48}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0596CA66-E899-4637-9535-E61126971B48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {0596CA66-E899-4637-9535-E61126971B48}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {0596CA66-E899-4637-9535-E61126971B48}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {0596CA66-E899-4637-9535-E61126971B48}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /xmldoc2md/xmldoc2md.md: -------------------------------------------------------------------------------- 1 | #XmlDoc2MD 2 | 3 | ##Program 4 | 5 | The unique class of the application 6 | 7 | ###Fields 8 | 9 | ####DummyField 10 | A dummy field Backend for . 11 | ###Properties 12 | 13 | ####DummyProperty 14 | A dummy property A string value 15 | ###Methods 16 | 17 | 18 | ####Main(System.String[]) 19 | This is the unique functional method. All others are dummies 20 | The entry point of the application 21 | > #####Parameters 22 | > **args:** The argument list. Not used 23 | 24 | 25 | ####DummyMethod(System.Int32) 26 | A dummy method 27 | > #####Parameters 28 | > **arg1:** An integer argument 29 | 30 | > #####Return value 31 | > A string representation of the argument 32 | > #####Exceptions 33 | > **System.IO.IOException:** Whenever a file error occurs 34 | 35 | > #####Example 36 | > 37 | 38 | ``` 39 | 40 | int x = 1; 41 | string s = DummyMethod(x); 42 | ``` 43 | 44 | 45 | ####PrivateMethod 46 | A private method -------------------------------------------------------------------------------- /xmldoc2md/xmldoc2md.ps1: -------------------------------------------------------------------------------- 1 | # xmldoc2md.ps1 2 | # By Jaime Olivares 3 | # URL: http://github.com/jaime-olivares/xmldoc2md 4 | 5 | param ( 6 | [string]$xml = $(throw "-xml is required."), 7 | [string]$xsl = $(throw "-xsl is required."), 8 | [string]$output = $(throw "-output is required.") 9 | ) 10 | 11 | # var = new XslCompiledTransform(true); 12 | $xslt = New-Object -TypeName "System.Xml.Xsl.XslCompiledTransform" 13 | 14 | # xslt.Load(stylesheet); 15 | $xslt.Load($xsl) 16 | 17 | # xslt.Transform(sourceFile, null, sw); 18 | $xslt.Transform($xml, $output) 19 | -------------------------------------------------------------------------------- /xmldoc2md/xmldoc2md.xsl: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | # 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ## 38 | 39 | 40 | 41 | 42 | 43 | 44 | ###Fields 45 | 46 | 47 | 48 | #### 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | ###Properties 58 | 59 | 60 | 61 | #### 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | ###Methods 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | ####Constructor 79 | 80 | 81 | 82 | 83 | #### 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | > #####Parameters 98 | 99 | 100 | 101 | 102 | > #####Return value 103 | 104 | 105 | 106 | 107 | > #####Exceptions 108 | 109 | 110 | 111 | 112 | > #####Example 113 | > 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | ` 132 | 133 | ` 134 | 135 | 136 | 137 | ``` 138 | 139 | ``` 140 | 141 | 142 | 143 | > **:** 144 | 145 | 146 | 147 | [External file]({@file}) 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | > **:** 156 | 157 | 158 | 159 | * 160 | 161 | * 162 | 163 | 164 | 165 | **Permission:** ** 166 | 167 | 168 | 169 | > 170 | 171 | 172 | 173 | 174 | > *See: * 175 | 176 | 177 | 178 | > *See also: 179 | 180 | 181 | 182 | 183 | --------------------------------------------------------------------------------