#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# All params from IdM is stored in environment and you can get them by os.environ["paramName"]
import sys, os
# this is needed for importing file winrm_wrapper from parent dir
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import winrm_wrapper
import codecs

uid = os.environ["__UID__"]

winrm_wrapper.writeLog("Delete start for " + uid)

# Load PS script from file and replace params
winrm_wrapper.writeLog("loading script")
f = codecs.open(os.environ["script"], encoding='utf-8', mode='r')
command = f.read()
command = command.replace("$uid", uid)

# Call wrapper
winrm_wrapper.executeScript(os.environ["endpoint"], os.environ["authentication"], os.environ["user"],
                                    os.environ["password"], os.environ["caTrustPath"], os.environ["ignoreCaValidation"], command, uid)

winrm_wrapper.writeLog("Delete end for " + uid)
print("__UID__=" + uid)
sys.exit()

[((12, 0, 12, 49), 'winrm_wrapper.writeLog', 'winrm_wrapper.writeLog', ({(12, 23, 12, 48): "('Delete start for ' + uid)"}, {}), "('Delete start for ' + uid)", False, 'import winrm_wrapper\n'), ((15, 0, 15, 40), 'winrm_wrapper.writeLog', 'winrm_wrapper.writeLog', ({(15, 23, 15, 39): '"""loading script"""'}, {}), "('loading script')", False, 'import winrm_wrapper\n'), ((16, 4, 16, 65), 'codecs.open', 'codecs.open', (), '', False, 'import codecs\n'), ((21, 0, 22, 134), 'winrm_wrapper.executeScript', 'winrm_wrapper.executeScript', ({(21, 28, 21, 50): "os.environ['endpoint']", (21, 52, 21, 80): "os.environ['authentication']", (21, 82, 21, 100): "os.environ['user']", (22, 36, 22, 58): "os.environ['password']", (22, 60, 22, 85): "os.environ['caTrustPath']", (22, 87, 22, 119): "os.environ['ignoreCaValidation']", (22, 121, 22, 128): 'command', (22, 130, 22, 133): 'uid'}, {}), "(os.environ['endpoint'], os.environ[\n    'authentication'], os.environ['user'], os.environ['password'], os.\n    environ['caTrustPath'], os.environ['ignoreCaValidation'], command, uid)", False, 'import winrm_wrapper\n'), ((24, 0, 24, 47), 'winrm_wrapper.writeLog', 'winrm_wrapper.writeLog', ({(24, 23, 24, 46): "('Delete end for ' + uid)"}, {}), "('Delete end for ' + uid)", False, 'import winrm_wrapper\n'), ((26, 0, 26, 10), 'sys.exit', 'sys.exit', ({}, {}), '()', False, 'import sys, os\n'), ((6, 29, 6, 54), 'os.path.dirname', 'os.path.dirname', ({(6, 45, 6, 53): '__file__'}, {}), '(__file__)', False, 'import sys, os\n')]