Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1d13de5
Initial work on winrm_runner
nmaludy Jun 7, 2018
c816e32
Removed temp file and added integration test stub for winrm_runner
nmaludy Jun 8, 2018
8deb9fa
Merge remote-tracking branch 'upstream/master' into feature/winrm-runner
nmaludy Jun 8, 2018
8086ec1
Added support for passing in parameters to the winrm script runner
nmaludy Jun 8, 2018
eedab89
Merge branch 'master' into feature/winrm-runner
nmaludy Jun 8, 2018
1fce590
Fix flake8 errors
nmaludy Jun 8, 2018
b028e6c
Merge remote-tracking branch 'origin/feature/winrm-runner' into featu…
nmaludy Jun 8, 2018
e50f329
Initial work on WinRM runner unit testing
nmaludy Jun 11, 2018
26d773e
WinRM runner unit tests
nmaludy Jun 11, 2018
59825a1
Merge remote-tracking branch 'upstream/master' into feature/winrm-runner
nmaludy Jun 11, 2018
a936394
Added runner requirements.txt files to virtualenv for testing
nmaludy Jun 11, 2018
f9e7b78
Fix flake8 errors
nmaludy Jun 11, 2018
d0f182a
More unit tests for winrm runner
nmaludy Jun 11, 2018
d466e14
Work in WinRM unit tests
nmaludy Jun 12, 2018
ac730ec
Fixed script winrm runner unit test
nmaludy Jun 12, 2018
b21823b
Added new winrm-cmd runner and new actions core.winrm_cmd and winrm_p…
nmaludy Jun 12, 2018
2b1fe5f
Added unit tests for winrm_command_runner
nmaludy Jun 12, 2018
e7dfc75
Added winrm-cmd to winrm runner entry points
nmaludy Jun 12, 2018
11e6328
Added winrm runner to tox
nmaludy Jun 12, 2018
1420e88
Changed winrm_runner/runner.yaml symlink to include ./
nmaludy Jun 12, 2018
920c1be
Added winrm_runner symlink to st2tests
nmaludy Jun 12, 2018
d11ba9f
Changed hard coded number of runners in st2api tests
nmaludy Jun 12, 2018
409fd6f
Fixed python3 byte/unicode problem
nmaludy Jun 12, 2018
dc6a511
Merge branch 'master' into feature/winrm-runner
nmaludy Jun 12, 2018
08a681d
Added WinRM runner examples. Found a few more corner-cases in the Win…
nmaludy Jun 14, 2018
7750c6f
Merge remote-tracking branch 'origin/feature/winrm-runner' into featu…
nmaludy Jun 14, 2018
c09d659
Merge remote-tracking branch 'upstream/master' into feature/winrm-runner
nmaludy Jun 14, 2018
00d62e1
Merge remote-tracking branch 'upstream/master' into feature/winrm-runner
nmaludy Jun 18, 2018
3f6f9b3
Renamed _run_cmd and _run_ps functions in winrm base runner
nmaludy Jun 18, 2018
b05a241
Renamed _run_cmd and _run_ps functions in winrm base runner
nmaludy Jun 18, 2018
8219953
Merge remote-tracking branch 'origin/feature/winrm-runner' into featu…
nmaludy Jun 19, 2018
d660ddf
Merge branch 'master' into feature/winrm-runner
Kami Jun 22, 2018
f01e359
Fixed unit tests for WinRM runner
nmaludy Jun 22, 2018
2d3eb18
Fixed some more places where the number of runners was hard coded
nmaludy Jun 22, 2018
48f94eb
Merge remote-tracking branch 'upstream/master' into feature/winrm-runner
nmaludy Jun 22, 2018
0a5c159
Merge branch 'master' into feature/winrm-runner
nmaludy Jun 23, 2018
deffff9
Linked winrm_runner version to st2common to go along with #4211
nmaludy Jun 28, 2018
b978b1f
Merge remote-tracking branch 'origin/feature/winrm-runner' into featu…
nmaludy Jun 28, 2018
93e770d
Merge remote-tracking branch 'upstream/master' into feature/winrm-runner
nmaludy Jun 28, 2018
365ad33
Merge branch 'master' into feature/winrm-runner
Kami Jul 9, 2018
67f4583
Update CHANGELOG.rst
Kami Jul 9, 2018
de155e6
Update setup.py
Kami Jul 9, 2018
2ecf3a0
Update CHANGELOG.rst
Kami Jul 9, 2018
1783f0a
Update CHANGELOG.rst
Kami Jul 9, 2018
dbecb37
Update tox.ini
Kami Jul 9, 2018
3c78019
Update tox.ini
Kami Jul 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ in development
Added
~~~~~

* Add new runners: ``winrm-cmd``, ``winrm-ps-cmd`` and ``winrm-ps-script``.
The ``winrm-cmd`` runner executes Command Prompt commands remotely on Windows hosts using the
WinRM protocol. The ``winrm-ps-cmd`` and ``winrm-ps-script`` runners execute PowerShell commands
and scripts on remote Windows hosts using the WinRM protocol.

To accompany these new runners, there are two new actions ``core.winrm_cmd`` that executes remote
Command Prompt commands along with ``core.winrm_ps_cmd`` that executes remote PowerShell commands.
(new feature) #1636

Contributed by Nick Maludy (Encore Technologies).
* Add new ``?tags``, query param filter to the ``/v1/actions`` API endpoint. This query parameter
allows users to filter out actions based on the tag name . By default, when no filter values are
provided, all actions are returned. (new feature) #4219
Expand All @@ -17,6 +27,11 @@ Changed
* Update ``st2client/setup.py`` file to dynamically load requirements from
``st2client/requirements.txt`` file. The code works with pip >= 6.0.0, although using pip 9.0.0
or higher is strongly recommended. (improvement) #4209
* Migrated runners to using the ``in-requirements.txt`` pattern for "components" in the build
system, so the ``Makefile`` correctly generates and installs runner dependencies during
testing and packaging. (improvement) (bugfix) #4169

Contributed by Nick Maludy (Encore Technologies).

2.8.0 - July 10, 2018
---------------------
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ requirements: virtualenv .sdist-requirements
$(VIRTUALENV_DIR)/bin/pip install --upgrade "virtualenv==15.1.0" # Required for packs.install in dev envs.

# Generate all requirements to support current CI pipeline.
$(VIRTUALENV_DIR)/bin/python scripts/fixate-requirements.py --skip=virtualenv -s st2*/in-requirements.txt -f fixed-requirements.txt -o requirements.txt
$(VIRTUALENV_DIR)/bin/python scripts/fixate-requirements.py --skip=virtualenv -s st2*/in-requirements.txt contrib/runners/*/in-requirements.txt -f fixed-requirements.txt -o requirements.txt

# Generate finall requirements.txt file for each component
@for component in $(COMPONENTS); do\
@for component in $(COMPONENTS_WITH_RUNNERS); do\
echo "==========================================================="; \
echo "Generating requirements.txt for" $$component; \
echo "==========================================================="; \
Expand Down
12 changes: 12 additions & 0 deletions contrib/core/actions/winrm_cmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

---
name: "winrm_cmd"
runner_type: "winrm-cmd"
description: "Action to execute arbitrary Windows Command Prompt command remotely via WinRM."
enabled: true
entry_point: ""
parameters:
cmd:
description: "Arbitrary Windows Command Prompt command to be executed on the remote host."
type: "string"
required: true
12 changes: 12 additions & 0 deletions contrib/core/actions/winrm_ps_cmd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

---
name: "winrm_ps_cmd"
runner_type: "winrm-ps-cmd"
description: "Action to execute arbitrary Windows PowerShell command remotely via WinRM."
enabled: true
entry_point: ""
parameters:
cmd:
description: "Arbitrary Windows PowerShell command to be executed on the remote host."
type: "string"
required: true
6 changes: 6 additions & 0 deletions contrib/examples/actions/winrm_get_uptime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
name: "winrm_get_uptime"
description: "Action that returns Windows host's uptime using WinRM."
enabled: true
entry_point: "windows/get_uptime.ps1"
runner_type: "winrm-ps-script"
10 changes: 10 additions & 0 deletions contrib/examples/actions/winrm_ipconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: "winrm_get_ipconfig"
description: "Action that returns Windows host's IP config information."
enabled: true
runner_type: "winrm-cmd"
parameters:
cmd:
type: string
default: "ipconfig /all"
immutable: true
17 changes: 17 additions & 0 deletions contrib/examples/actions/winrm_powershell_env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: "winrm_powershell_env"
description: "Action that sets an environment variable then prints it out. This also demonstrates returning JSON data from PowerShell and being able to utilize it as an object via stdout."
enabled: true
runner_type: "winrm-ps-cmd"
parameters:
env_var_name:
type: string
default: "ST2_WINRM_ENV_TEST"
cmd:
type: string
default: "Get-Item Env:{{ env_var_name }} | ConvertTo-Json -Depth 1 -Compress"
immutable: true
env:
type: object
default:
"{{ env_var_name }}": "This is a test"
Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/action_chain_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/announcement_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/cloudslang_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/http_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/inquirer_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/local_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/mistral_v2/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/noop_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/python_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/remote_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

Empty file.
2 changes: 2 additions & 0 deletions contrib/runners/windows_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!

11 changes: 11 additions & 0 deletions contrib/runners/winrm_runner/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://docs.python.org/2/distutils/sourcedist.html#commands
# Include all files under the source tree by default.
# Another behaviour can be used in the future though.
include __init__.py
include runner.yaml
include dist_utils.py
include requirements.txt
include README.rst
include CHANGELOG.rst
include LICENSE
global-exclude *.pyc
107 changes: 107 additions & 0 deletions contrib/runners/winrm_runner/dist_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import os
import re
import sys

from distutils.version import StrictVersion

GET_PIP = 'curl https://bootstrap.pypa.io/get-pip.py | python'

try:
import pip
from pip import __version__ as pip_version
except ImportError as e:
print('Failed to import pip: %s' % (str(e)))
print('')
print('Download pip:\n%s' % (GET_PIP))
sys.exit(1)

try:
# pip < 10.0
from pip.req import parse_requirements
except ImportError:
# pip >= 10.0

try:
from pip._internal.req.req_file import parse_requirements
except ImportError as e:
print('Failed to import parse_requirements from pip: %s' % (str(e)))
print('Using pip: %s' % (str(pip_version)))
sys.exit(1)

__all__ = [
'check_pip_version',
'fetch_requirements',
'apply_vagrant_workaround',
'get_version_string',
'parse_version_string'
]


def check_pip_version():
"""
Ensure that a minimum supported version of pip is installed.
"""
if StrictVersion(pip.__version__) < StrictVersion('6.0.0'):
print("Upgrade pip, your version `{0}' "
"is outdated:\n{1}".format(pip.__version__, GET_PIP))
sys.exit(1)


def fetch_requirements(requirements_file_path):
"""
Return a list of requirements and links by parsing the provided requirements file.
"""
links = []
reqs = []
for req in parse_requirements(requirements_file_path, session=False):
if req.link:
links.append(str(req.link))
reqs.append(str(req.req))
return (reqs, links)


def apply_vagrant_workaround():
"""
Function which detects if the script is being executed inside vagrant and if it is, it deletes
"os.link" attribute.
Note: Without this workaround, setup.py sdist will fail when running inside a shared directory
(nfs / virtualbox shared folders).
"""
if os.environ.get('USER', None) == 'vagrant':
del os.link


def get_version_string(init_file):
"""
Read __version__ string for an init file.
"""

with open(init_file, 'r') as fp:
content = fp.read()
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
content, re.M)
if version_match:
return version_match.group(1)

raise RuntimeError('Unable to find version string in %s.' % (init_file))


# alias for get_version_string
parse_version_string = get_version_string
1 change: 1 addition & 0 deletions contrib/runners/winrm_runner/in-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pywinrm
2 changes: 2 additions & 0 deletions contrib/runners/winrm_runner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Don't edit this file. It's generated automatically!
pywinrm==0.3.0
1 change: 1 addition & 0 deletions contrib/runners/winrm_runner/runner.yaml
56 changes: 56 additions & 0 deletions contrib/runners/winrm_runner/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
import os.path

from setuptools import setup
from setuptools import find_packages

from dist_utils import fetch_requirements
from dist_utils import apply_vagrant_workaround

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
REQUIREMENTS_FILE = os.path.join(BASE_DIR, 'requirements.txt')

install_reqs, dep_links = fetch_requirements(REQUIREMENTS_FILE)

apply_vagrant_workaround()
setup(
name='stackstorm-runner-winrm',
version='2.8.0',
description=('WinRM shell command and PowerShell script action runner for'
' the StackStorm event-driven automation platform'),
author='StackStorm',
author_email='info@stackstorm.com',
license='Apache License (2.0)',
url='https://stackstorm.com/',
install_requires=install_reqs,
dependency_links=dep_links,
test_suite='tests',
zip_safe=False,
include_package_data=True,
packages=find_packages(exclude=['setuptools', 'tests']),
package_data={'winrm_ps_command_runner': ['runner.yaml']},
scripts=[],
entry_points={
'st2common.runners.runner': [
'winrm-cmd = winrm_runner.winrm_command_runner',
'winrm-ps-cmd = winrm_runner.winrm_ps_command_runner',
'winrm-ps-script = winrm_runner.winrm_ps_script_runner',
],
}
)
Empty file.
Empty file.
23 changes: 23 additions & 0 deletions contrib/runners/winrm_runner/tests/unit/fixtures/TestScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[CmdletBinding()]
Param(
[bool]$p_bool,
[int]$p_integer,
[double]$p_number,
[string]$p_str,
[array]$p_array,
[hashtable]$p_obj,
[Parameter(Position=0)]
[string]$p_pos0,
[Parameter(Position=1)]
[string]$p_pos1
)


Write-Output "p_bool = $p_bool"
Write-Output "p_integer = $p_integer"
Write-Output "p_number = $p_number"
Write-Output "p_str = $p_str"
Write-Output "p_array = $($p_array | ConvertTo-Json -Compress)"
Write-Output "p_obj = $($p_obj | ConvertTo-Json -Compress)"
Write-Output "p_pos0 = $p_pos0"
Write-Output "p_pos1 = $p_pos1"
Loading