Skip to content

Commit

Permalink
Merge pull request #5 from ltamaster/add-ssl-cert-path
Browse files Browse the repository at this point in the history
Adding certificate path for HTTPS connections
  • Loading branch information
ltamaster authored May 7, 2018
2 parents 820697c + 608f6a9 commit 66b038b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 30 deletions.
30 changes: 22 additions & 8 deletions contents/winrm-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import sys
import argparse
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()

parser = argparse.ArgumentParser(description='Run Bolt command.')
parser.add_argument('--username', help='the username')
Expand All @@ -12,12 +14,14 @@
parser.add_argument('--port', help='port',default="5985")
parser.add_argument('--nossl', help='nossl',default="False")
parser.add_argument('--debug', help='nossl',default="False")
parser.add_argument('--certpath', help='certpath')

args = parser.parse_args()

hostname = None
username = None
password = None
certpath = None

if args.hostname:
hostname = args.hostname
Expand Down Expand Up @@ -49,6 +53,9 @@
else:
debug = False

if args.certpath:
certpath = args.certpath

if not hostname:
print("hostname is required")
sys.exit(1)
Expand All @@ -74,17 +81,24 @@
print "username:" +username
print "nossl:" + str(nossl)
print "transport:" + transport
if(certpath):
print "certpath:" + certpath
print "------------------------------------------"

if(nossl):
session = winrm.Session(endpoint,
auth=(username, password),
transport=authentication,
server_cert_validation='ignore')

arguments={}
arguments["transport"] = authentication

if(nossl == True):
arguments["server_cert_validation"] = "ignore"
else:
session = winrm.Session(endpoint,
auth=(username, password),
transport=authentication)
if(transport=="https"):
arguments["server_cert_validation"] = "validate"
arguments["ca_trust_path"] = certpath

session = winrm.Session(target=endpoint,
auth=(username, password),
**arguments)

exec_command = "ipconfig"
result = session.run_cmd(exec_command)
Expand Down
37 changes: 24 additions & 13 deletions contents/winrm-exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import argparse
import os
import sys

import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
from winrm.protocol import Protocol


parser = argparse.ArgumentParser(description='Run Bolt command.')
parser.add_argument('hostname', help='the hostname')
args = parser.parse_args()
Expand All @@ -17,6 +17,7 @@
nossl=False
debug=False
shell = "cmd"
certpath = None

if "RD_CONFIG_PASSWORD_STORAGE_PATH" in os.environ:
password = os.getenv("RD_CONFIG_PASSWORD_STORAGE_PATH")
Expand All @@ -31,14 +32,19 @@
port = os.getenv("RD_CONFIG_WINRMPORT")

if "RD_CONFIG_NOSSL" in os.environ:
nossl = os.getenv("RD_CONFIG_NOSSL")
if os.getenv("RD_CONFIG_NOSSL") == "true":
nossl = True
else:
nossl = False

if "RD_CONFIG_SHELL" in os.environ:
shell = os.getenv("RD_CONFIG_SHELL")

if os.getenv("RD_JOB_LOGLEVEL") == "DEBUG":
debug = True

if "RD_CONFIG_CERTPATH" in os.environ:
certpath = os.getenv("RD_CONFIG_CERTPATH")

exec_command = os.getenv("RD_EXEC_COMMAND")

Expand All @@ -61,27 +67,32 @@
print "endpoint:" +endpoint
print "authentication:" +authentication
print "username:" +username
print "nossl:" + str(nossl)
print "------------------------------------------"

arguments = {}
arguments["transport"] = authentication

if(nossl):
session = winrm.Session(endpoint,
auth=(username, password),
transport=authentication,
server_cert_validation='ignore')
if(nossl == True):
arguments["server_cert_validation"] = "ignore"
else:
session = winrm.Session(endpoint,
auth=(username, password),
transport=authentication)
if(transport=="https"):
arguments["server_cert_validation"] = "validate"
arguments["ca_trust_path"] = certpath

session = winrm.Session(target=endpoint,
auth=(username, password),
**arguments)

if shell == "cmd":
result = session.run_cmd(exec_command)

if shell == "powershell":
result = session.run_ps(exec_command)


print result.std_out
print result.std_err

if(result.std_err):
print result.std_err

sys.exit(result.status_code)
30 changes: 21 additions & 9 deletions contents/winrm-filecopier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import time
from base64 import b64encode
from winrm.protocol import Protocol
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()


class RemoteCommandError(Exception):
Expand Down Expand Up @@ -107,7 +109,13 @@ def winrm_upload(
port = os.getenv("RD_CONFIG_WINRMPORT")

if "RD_CONFIG_NOSSL" in os.environ:
nossl = os.getenv("RD_CONFIG_NOSSL")
if os.getenv("RD_CONFIG_NOSSL") == "true":
nossl = True
else:
nossl = False

if "RD_CONFIG_CERTPATH" in os.environ:
certpath = os.getenv("RD_CONFIG_CERTPATH")

if "RD_OPTION_USERNAME" in os.environ and os.getenv("RD_OPTION_USERNAME"):
#take user from job
Expand All @@ -123,15 +131,19 @@ def winrm_upload(

endpoint = transport+'://'+args.hostname+':'+port

if(nossl):
session = winrm.Session(endpoint,
auth=(username, password),
transport=authentication,
server_cert_validation='ignore')
arguments = {}
arguments["transport"] = authentication

if(nossl == True):
arguments["server_cert_validation"] = "ignore"
else:
session = winrm.Session(endpoint,
auth=(username, password),
transport=authentication)
if(transport=="https"):
arguments["server_cert_validation"] = "validate"
arguments["ca_trust_path"] = certpath

session = winrm.Session(target=endpoint,
auth=(username, password),
**arguments)

copy = CopyFiles(session)
copy.winrm_upload(args.destination,args.source)
18 changes: 18 additions & 0 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ providers:
renderingOptions:
groupName: Connection
instance-scope-node-attribute: "winrm-port"
- name: certpath
title: Certificate Path
description: "Certificate path for ssl verification"
type: String
required: false
scope: Instance
renderingOptions:
groupName: Connection
instance-scope-node-attribute: "winrm-certpath"
- name: shell
title: Shell
description: "Windows Shell interpreter"
Expand Down Expand Up @@ -139,6 +148,15 @@ providers:
renderingOptions:
groupName: Connection
instance-scope-node-attribute: "winrm-port"
- name: certpath
title: Certificate Path
description: "Certificate path for ssl verification"
type: String
required: false
scope: Instance
renderingOptions:
groupName: Connection
instance-scope-node-attribute: "winrm-certpath"
- name: username
title: Username
type: String
Expand Down

0 comments on commit 66b038b

Please sign in to comment.