Friday, May 14, 2021

FDMEE 11.2.x...I can't believe my eyes! that script has a hard-coded password!

Ey there!

Long time ago I was showing one of the different methods to avoid hard-coding passwords in FDMEE scripts. You can see the original post here.

I have upgraded FDMEE to 11.2.x, and now what?
If you run the same code in 11.2.x, you will gen the following error:

TypeError: snpsDecypher(): expected 2 args; got 1

Why? FDMEE 11.1.2.x uses ODI 11g and FDMEE 11.2.x uses ODI 12c. And the ODI APIs have slightly changed. Some methods are now deprecated.

Luckily, there is a workaround. Let's use the ODI 12c API :-)
The code below also shows you how to use different EPM API such as the EPM Registry API.

Let me highlight something that I have seen in different implementations. If you want to execute a SQL statement against the FDMEE database, you don't need to open the connection via jdbc. There are API methods to execute SQL statements against it. Those methods will manage the DB connection for you.

Enjoy the code!

# ***************************************
# ODI 12c Password Decrypter
# ***************************************

''' 
	ODI 11g Code
	--------------------------------------------
	# Import ODI API class
        from com.sunopsis.dwg import DwgObject
	# Decrypt pwd
	connPwdDec = DwgObject.snpsDecypher(connPwdEnc)
	
	Execution in ODI 12c
	--------------------------------------------
	Traceback (most recent call last):
	File "<string>", line 529, in executeJythonScript
	File "\\WIN19\EPMSHARE\FDMEE/data/scripts/custom/odi12c_decrypy_pwd.py", line 20, in <module>
        connPwdDec = DwgObject.snpsDecypher(connPwdEnc)
	TypeError: snpsDecypher(): expected 2 args; got 1
	
	Cause
	--------------------------------------------
	Function (depecreated) is defined as:
	public static String snpsDecypher(String pPass, OdiInstance pOdiInstance)
	
'''

# Import libraries
from oracle.odi.core.config import MasterRepositoryDbInfo
from oracle.odi.core.config import OdiInstanceConfig
from oracle.odi.core.config import PoolingAttributes
from oracle.odi.core.config import WorkRepositoryDbInfo
from oracle.odi.core import OdiInstance
from com.sunopsis.dwg import DwgObject

from com.hyperion.aif.util import RegistryUtilCore
from com.hyperion.hit.registry import DBTypeComponentImpl
from com.hyperion.hit.registry import ComponentType

# Encrypted password (you can get it from ODI SNP tables as you would do in 11g)
connPwdEnc = "xxxxxxxxxxxxxxxxxxxx"

# Get MR Connection details
# ----------------------------
aifDbComponent = RegistryUtilCore.getAIFDatabaseComponent()
jdbcDriver = aifDbComponent.getPropertyValue("dbJDBCDriverProperty")
jdbcUrl = aifDbComponent.getJdbcUrl()
jdbcUserName = aifDbComponent.getUserName()
jdbcPwd = aifDbComponent.getPassword()
fdmAPI.logInfo("Jdbc Driver ->" + str(jdbcDriver))
fdmAPI.logInfo("Jdbc Url -> " + str(jdbcUrl))
fdmAPI.logInfo("Jdbc User -> " + str(jdbcUserName))
fdmAPI.logInfo("Jdbc Pwd -> " + str(jdbcPwd))

# Create MR/WR Info
# ----------------------------
workRep = "FDMEE"
masterInfo = MasterRepositoryDbInfo(jdbcUrl, jdbcDriver, jdbcUserName, jdbcPwd, PoolingAttributes())
workInfo = WorkRepositoryDbInfo(workRep, PoolingAttributes())

# Create ODI instance
# ----------------------------
odiInstance = OdiInstance.createInstance(OdiInstanceConfig(masterInfo, workInfo))

# Decrypt password
# ----------------------------
connPwdDec = DwgObject.snpsDecypher(connPwdEnc, odiInstance)

# Log decrypted password
fdmAPI.logInfo("Jdbc Decrypted Pwd -> " + str(connPwdDec))

# Destroy objects
odiInstance.close()

Have a good weekend!