#!/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, 'winrm_wrapper.writeLog', 'winrm_wrapper.writeLog', False, 'import winrm_wrapper\n'), (15, 'winrm_wrapper.writeLog', 'winrm_wrapper.writeLog', False, 'import winrm_wrapper\n'), (16, 'codecs.open', 'codecs.open', False, 'import codecs\n'), (21, 'winrm_wrapper.executeScript', 'winrm_wrapper.executeScript', False, 'import winrm_wrapper\n'), (24, 'winrm_wrapper.writeLog', 'winrm_wrapper.writeLog', False, 'import winrm_wrapper\n'), (26, 'sys.exit', 'sys.exit', False, 'import sys, os\n'), (6, 'os.path.dirname', 'os.path.dirname', False, 'import sys, os\n')]