Skip to content

Commit

Permalink
Merge pull request #83 from rundeck-plugins/fix-2147-pywinrm-appending
Browse files Browse the repository at this point in the history
RUN-506: Appending files instead of overriding
  • Loading branch information
L2JE authored Nov 18, 2021
2 parents eb726b7 + 48a71ee commit 1a2622f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 11 additions & 2 deletions contents/winrm-filecopier.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def winrm_upload(self,
remote_filename,
local_path,
step=2048,
quiet=True):
quiet=True,
override=False):

if remote_path.endswith('/') or remote_path.endswith('\\'):
full_path = remote_path + remote_filename
Expand All @@ -185,6 +186,9 @@ def winrm_upload(self,

self.session.run_ps('if (!(Test-Path {0})) {{ New-Item -ItemType directory -Path {0} }}'.format(remote_path))

if(override):
self.session.run_ps('if ((Test-Path {0} -PathType Leaf)) {{ rm {0} }}'.format(full_path))

size = os.stat(local_path).st_size
with open(local_path, 'rb') as f:
for i in range(0, size, step):
Expand Down Expand Up @@ -245,6 +249,10 @@ def winrm_upload(self,
krb5config = None
krbdelegation = False
forceTicket = False
override=False

if os.environ.get('RD_CONFIG_OVERRIDE') == 'true':
override = True

if "RD_CONFIG_AUTHTYPE" in os.environ:
authentication = os.getenv("RD_CONFIG_AUTHTYPE")
Expand Down Expand Up @@ -377,7 +385,8 @@ def winrm_upload(self,
copy.winrm_upload(remote_path=destination,
remote_filename=filename,
local_path=args.source,
quiet=quiet)
quiet=quiet,
override=override)
else:
log.warn("The source is a directory, skipping copy")

7 changes: 5 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ providers:
name: debug
title: Debug?
description: 'Write debug messages'
- type: Boolean
name: override
title: Override?
description: 'Overrides the file on the remote server if it already exists'
- name: krb5config
title: krb5 Config File
description: "Path of krb5.conf file"
Expand Down Expand Up @@ -409,5 +413,4 @@ providers:
default: "false"
required: false
renderingOptions:
groupName: Kerberos

groupName: Kerberos

0 comments on commit 1a2622f

Please sign in to comment.