Reply
New Contributor
Posts: 1
Registered: ‎03-30-2018

Use Encrypted password for Cloudera Manager ApiResource instead of cleartext password

am trying to use an encrypted password in the python script for Cloudera Backup Disaster Recovery using Cloudera Manager API.

This is the BDR script i am trying to run:

https://www.cloudera.com/documentation/enterprise/5-12-x/topics/cm_bdr_howto_api.html

When i am hard coding the password

(ApiResource(server_host="hostname",username="uqqq",password="xyz",version=14,use_tls=True)), 

it is working. But when i am trying to assign to a variable(var_passwprd="xyz") and then passing the variable to the password

(ApiResource(server_host="hostname",username="uqqq",password=var_passwprd,version=14,use_tls=True)), 

it is throwing below error:

Traceback (most recent call last): 
 File "test2.py", line 41, in <module> 
target_cluster = target_api.get_cluster('QA') 
File "/opt/pythonvirtual/bdr/lib/python2.7/site-
packages/cm_api/api_client.py", line 140, in get_cluster return clusters.get_cluster(self, name) 
File "/opt/pythonvirtual/bdr/lib/python2.7/site-
packages/cm_api/endpoints/clusters.py", line 57, in get_cluster return call(resource_root.get, "%s/%s" % (CLUSTERS_PATH, name), ApiCluster) 
File "/opt/pythonvirtual/bdr/lib/python2.7/site-
packages/cm_api/endpoints/types.py", line 139, in call 
ret = method(path, params=params) 
File "/opt/pythonvirtual/bdr/lib/python2.7/site-
packages/cm_api/resource.py", line 110, in get return self.invoke("GET", relpath, params) 
File "/opt/pythonvirtual/bdr/lib/python2.7/site-
packages/cm_api/resource.py", line 73, in invoke 
headers=headers) 
File "/opt/pythonvirtual/bdr/lib/python2.7/site-
packages/cm_api/http_client.py", line 183, in execute raise self._exc_class(ex) 
cm_api.api_client.ApiException: <html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> 
<title>Error 401 Bad credentials</title> 
</head> 
<body><h2>HTTP ERROR 401</h2> 
<p>Problem accessing /api/v16/clusters/QA. Reason: 
<pre>    Bad credentials</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/> 
<br/> 
<br/> 
</body> 
</html> 
(error 401)

 

Announcements