You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by pr...@apache.org on 2020/05/28 06:40:38 UTC
[ranger] branch master updated: RANGER-2759: Ranger should support
python 3
This is an automated email from the ASF dual-hosted git repository.
pradeep pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/master by this push:
new d5e3dc8 RANGER-2759: Ranger should support python 3
d5e3dc8 is described below
commit d5e3dc8c722e7ec4f035139c7c20e706aa82b146
Author: pradeep <pr...@apache.org>
AuthorDate: Sat May 23 13:32:59 2020 +0530
RANGER-2759: Ranger should support python 3
---
agents-common/scripts/upgrade-plugin.py | 23 ++--
kms/scripts/db_setup.py | 2 +-
kms/scripts/dba_script.py | 26 ++--
security-admin/scripts/changepasswordutil.py | 10 +-
security-admin/scripts/changeusernameutil.py | 8 +-
security-admin/scripts/db_setup.py | 10 +-
security-admin/scripts/dba_script.py | 30 +++--
security-admin/scripts/deleteUserGroupUtil.py | 16 ++-
security-admin/scripts/ranger_credential_helper.py | 20 +--
security-admin/scripts/restrict_permissions.py | 30 +++--
security-admin/scripts/rolebasedusersearchutil.py | 17 +--
.../scripts/updateUserAndGroupNamesInJson.py | 4 +-
security-admin/scripts/update_property.py | 2 +-
security-admin/scripts/upgrade_admin.py | 71 +++++-----
security-admin/src/bin/ranger_install.py | 133 +++++++++---------
security-admin/src/bin/ranger_usersync.py | 8 +-
security-admin/src/bin/service_start.py | 4 +-
tagsync/scripts/setup.py | 150 +++++++++++----------
tagsync/scripts/updatetagadminpassword.py | 19 +--
unixauthservice/scripts/setup.py | 131 +++++++++---------
unixauthservice/scripts/updatepolicymgrpassword.py | 18 +--
21 files changed, 393 insertions(+), 339 deletions(-)
diff --git a/agents-common/scripts/upgrade-plugin.py b/agents-common/scripts/upgrade-plugin.py
index fe7a11f..d865ee3 100755
--- a/agents-common/scripts/upgrade-plugin.py
+++ b/agents-common/scripts/upgrade-plugin.py
@@ -18,7 +18,10 @@ import xml.etree.ElementTree as ET
import os,errno,sys
from os import listdir
from os.path import isfile, join, dirname
-from urlparse import urlparse
+try:
+ from urllib.parse import urlparse
+except ImportError:
+ from urlparse import urlparse
debugLevel = 1
@@ -31,9 +34,9 @@ SUPPORTED_COMPONENTS = [ "hdfs", "hive", "hbase", "knox", "storm" ]
xmlTemplateDirectory = './install/conf.templates/enable'
def showUsage():
- print "This script must be run with a <componentName> as parameter"
- print "USAGE: upgrade-plugin.py <componentName>"
- print " <componentName> could be any one of the following: %s" % (SUPPORTED_COMPONENTS)
+ print("This script must be run with a <componentName> as parameter")
+ print("USAGE: upgrade-plugin.py <componentName>")
+ print(" <componentName> could be any one of the following: %s" % (SUPPORTED_COMPONENTS))
if (len(sys.argv) == 1):
showUsage()
@@ -42,7 +45,7 @@ if (len(sys.argv) == 1):
componentName = sys.argv[1]
if (componentName not in SUPPORTED_COMPONENTS):
- print "Invalid componentName passed as parameter: %s" % (componentName)
+ print("Invalid componentName passed as parameter: %s" % (componentName))
showUsage()
sys.exit(1)
@@ -92,8 +95,8 @@ def writeXMLUsingProperties(xmlTemplateFileName,prop,xmlOutputFileName):
def rewriteConfig(props,newProps):
if (debugLevel > 0):
- for k,v in props.iteritems():
- print "old config[%s] = [%s]" % (k,v)
+ for k,v in props.items():
+ print("old config[%s] = [%s]" % (k,v))
#
# Derived fields
#
@@ -137,10 +140,10 @@ def main():
r = getXMLConfigMap(file)
props.update(r)
if (len(foundFiles) == 0):
- print "INFO: Previous version of ranger is not enabled/configured for component [%s]" % (componentName)
+ print("INFO: Previous version of ranger is not enabled/configured for component [%s]" % (componentName))
sys.exit(0)
if (len(foundFiles) != 3):
- print "ERROR: Expected to find three files matching xasecure-*.xml files under the folder (%s) - found %s" % (configDirectory,foundFiles)
+ print("ERROR: Expected to find three files matching xasecure-*.xml files under the folder (%s) - found %s" % (configDirectory,foundFiles))
sys.exit(1)
for fn in listdir(xmlTemplateDirectory):
file = join(xmlTemplateDirectory,fn)
@@ -149,7 +152,7 @@ def main():
newProps.update(r)
newConfigFile = join(configDirectory,fn)
if isfile(newConfigFile):
- print "ERROR: new config file [%s] already exists. Upgrade script can not overwrite an existing config file." % (newConfigFile)
+ print("ERROR: new config file [%s] already exists. Upgrade script can not overwrite an existing config file." % (newConfigFile))
sys.exit(1)
rewriteConfig(props,newProps)
diff --git a/kms/scripts/db_setup.py b/kms/scripts/db_setup.py
index 7a0105e..9928f46 100644
--- a/kms/scripts/db_setup.py
+++ b/kms/scripts/db_setup.py
@@ -44,7 +44,7 @@ def check_output(query):
elif os_name == "WINDOWS":
p = subprocess.Popen(query, stdout=subprocess.PIPE, shell=True)
output = p.communicate ()[0]
- return output
+ return output.decode()
def log(msg,type):
if type == 'info':
diff --git a/kms/scripts/dba_script.py b/kms/scripts/dba_script.py
index 91477c6..c399de6 100755
--- a/kms/scripts/dba_script.py
+++ b/kms/scripts/dba_script.py
@@ -25,6 +25,8 @@ import getpass
from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
+try: input = raw_input
+except NameError: pass
globalDict = {}
os_name = platform.system()
@@ -44,7 +46,7 @@ def check_output(query):
elif os_name == "WINDOWS":
p = subprocess.Popen(query, stdout=subprocess.PIPE, shell=True)
output = p.communicate ()[0]
- return output
+ return output.decode()
def log(msg,type):
if type == 'info':
@@ -90,13 +92,13 @@ def logFile(msg):
f.write(msg+"\n")
f.close()
else:
- print("Unable to open file "+logFileName+" in write mode, Check file permissions.")
+ log("[E] Unable to open file "+logFileName+" in write mode, Check file permissions.", "error")
sys.exit()
else:
- print(logFileName+" is Invalid input file name! Provide valid file path to write DBA scripts:")
+ log("[E] "+logFileName+" is Invalid input file name! Provide valid file path to write DBA scripts:", "error")
sys.exit()
else:
- print("Invalid input! Provide file path to write DBA scripts:")
+ log("[E] Invalid input! Provide file path to write DBA scripts:", "error")
sys.exit()
def password_validation(password, userType):
@@ -1283,7 +1285,7 @@ def main(argv):
else :
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
if (quiteMode):
@@ -1292,7 +1294,7 @@ def main(argv):
XA_DB_FLAVOR=''
while XA_DB_FLAVOR == "":
log("Enter db flavour{MYSQL|ORACLE|POSTGRES|MSSQL|SQLA} :","info")
- XA_DB_FLAVOR=raw_input()
+ XA_DB_FLAVOR=input()
XA_DB_FLAVOR = XA_DB_FLAVOR.upper()
log("[I] DB FLAVOR:" + str(XA_DB_FLAVOR),"info")
@@ -1304,10 +1306,10 @@ def main(argv):
if not dryMode:
if XA_DB_FLAVOR == "MYSQL" or XA_DB_FLAVOR == "ORACLE" or XA_DB_FLAVOR == "POSTGRES" or XA_DB_FLAVOR == "MSSQL":
log("Enter JDBC connector file for :"+XA_DB_FLAVOR,"info")
- CONNECTOR_JAR=raw_input()
+ CONNECTOR_JAR=input()
while os.path.isfile(CONNECTOR_JAR) == False:
log("JDBC connector file "+CONNECTOR_JAR+" does not exist, Please enter connector path :","error")
- CONNECTOR_JAR=raw_input()
+ CONNECTOR_JAR=input()
else:
log("[E] ---------- NO SUCH SUPPORTED DB FLAVOUR.. ----------", "error")
sys.exit(1)
@@ -1322,7 +1324,7 @@ def main(argv):
xa_db_host=''
while xa_db_host == "":
log("Enter DB Host :","info")
- xa_db_host=raw_input()
+ xa_db_host=input()
if (quiteMode):
xa_db_root_user = globalDict['db_root_user']
@@ -1335,7 +1337,7 @@ def main(argv):
xa_db_root_user=''
while xa_db_root_user == "":
log("Enter db root user:","info")
- xa_db_root_user=raw_input()
+ xa_db_root_user=input()
log("Enter db root password:","info")
xa_db_root_password = getpass.getpass("Enter db root password:")
@@ -1348,7 +1350,7 @@ def main(argv):
db_name = ''
while db_name == "":
log("Enter DB Name :","info")
- db_name=raw_input()
+ db_name=input()
if (quiteMode):
db_user = globalDict['db_user']
@@ -1359,7 +1361,7 @@ def main(argv):
db_user=''
while db_user == "":
log("Enter db user name:","info")
- db_user=raw_input()
+ db_user=input()
if (quiteMode):
db_password = globalDict['db_password']
diff --git a/security-admin/scripts/changepasswordutil.py b/security-admin/scripts/changepasswordutil.py
index 6c73ed3..c9c4edc 100644
--- a/security-admin/scripts/changepasswordutil.py
+++ b/security-admin/scripts/changepasswordutil.py
@@ -28,6 +28,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
+try: input = raw_input
+except NameError: pass
os_name = platform.system()
os_name = os_name.upper()
@@ -73,7 +75,7 @@ def main(argv):
else:
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
USERNAME = ''
@@ -90,8 +92,8 @@ def main(argv):
sys.exit(1)
while userName == "":
- print "Enter user name:"
- userName=raw_input()
+ print("Enter user name:")
+ userName=input()
while oldPassword == "":
oldPassword=getpass.getpass("Enter current password:")
@@ -109,7 +111,7 @@ def main(argv):
path = os.path.join("%s","WEB-INF","classes","conf:%s","WEB-INF","classes","lib","*:%s","WEB-INF",":%s","META-INF",":%s","WEB-INF","lib","*:%s","WEB-INF","classes",":%s","WEB-INF","classes","META-INF:%s/*")%(app_home ,app_home ,app_home, app_home, app_home, app_home ,app_home,ews_lib)
elif os_name == "WINDOWS":
path = os.path.join("%s","WEB-INF","classes","conf;%s","WEB-INF","classes","lib","*;%s","WEB-INF",";%s","META-INF",";%s","WEB-INF","lib","*;%s","WEB-INF","classes",";%s","WEB-INF","classes","META-INF" )%(app_home ,app_home ,app_home, app_home, app_home, app_home ,app_home)
- get_java_cmd = "%s -Dlogdir=%s -Dlog4j.configuration=db_patch.log4j.xml -cp %s org.apache.ranger.patch.cliutil.%s %s %s %s"%(JAVA_BIN,ranger_log,path,
+ get_java_cmd = "%s -Dlogdir=%s -Dlog4j.configuration=db_patch.log4j.xml -cp %s org.apache.ranger.patch.cliutil.%s %s %s %s"%(JAVA_BIN,ranger_log,path,
'ChangePasswordUtil','"'+userName+'"','"'+oldPassword+'"','"'+newPassword+'"')
if os_name == "LINUX":
ret = subprocess.call(shlex.split(get_java_cmd))
diff --git a/security-admin/scripts/changeusernameutil.py b/security-admin/scripts/changeusernameutil.py
index cb471f0..45c0ef7 100644
--- a/security-admin/scripts/changeusernameutil.py
+++ b/security-admin/scripts/changeusernameutil.py
@@ -28,6 +28,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
+try: input = raw_input
+except NameError: pass
os_name = platform.system()
os_name = os_name.upper()
@@ -73,7 +75,7 @@ def main(argv):
else:
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
USERNAME = ''
@@ -90,8 +92,8 @@ def main(argv):
sys.exit(1)
while userName == "":
- print "Enter user name:"
- userName=raw_input()
+ print("Enter user name:")
+ userName=input()
while oldPassword == "":
oldPassword=getpass.getpass("Enter current password:")
diff --git a/security-admin/scripts/db_setup.py b/security-admin/scripts/db_setup.py
index 6670e6c..b448738 100644
--- a/security-admin/scripts/db_setup.py
+++ b/security-admin/scripts/db_setup.py
@@ -55,7 +55,7 @@ def check_output(query):
elif os_name == "WINDOWS":
p = subprocess.Popen(query, stdout=subprocess.PIPE, shell=True)
output = p.communicate ()[0]
- return output
+ return output.decode()
def log(msg,type):
if type == 'info':
@@ -423,7 +423,7 @@ class BaseDB(object):
key3 = int(version.strip("J"))
my_dict[key3] = filename
- keylist = my_dict.keys()
+ keylist = list(my_dict)
keylist.sort()
for key in keylist:
#print "%s: %s" % (key, my_dict[key])
@@ -1047,20 +1047,20 @@ def main(argv):
lib_home = os.path.join(RANGER_ADMIN_HOME,"ews","webapp","WEB-INF","lib","*")
get_ranger_version_cmd="%s -cp %s org.apache.ranger.common.RangerVersionInfo"%(JAVA_BIN,lib_home)
ranger_version = check_output(get_ranger_version_cmd).split("\n")[1]
- except Exception, error:
+ except Exception as error:
ranger_version=''
try:
if ranger_version=="" or ranger_version=="ranger-admin - None":
script_path = os.path.join(RANGER_ADMIN_HOME,"ews","ranger-admin-services.sh")
ranger_version=check_output(script_path +" version").split("\n")[1]
- except Exception, error:
+ except Exception as error:
ranger_version=''
try:
if ranger_version=="" or ranger_version=="ranger-admin - None":
ranger_version=check_output("ranger-admin version").split("\n")[1]
- except Exception, error:
+ except Exception as error:
ranger_version=''
if ranger_version=="" or ranger_version is None:
diff --git a/security-admin/scripts/dba_script.py b/security-admin/scripts/dba_script.py
index e889529..87ef88e 100644
--- a/security-admin/scripts/dba_script.py
+++ b/security-admin/scripts/dba_script.py
@@ -26,6 +26,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
import time
+try: input = raw_input
+except NameError: pass
globalDict = {}
os_name = platform.system()
@@ -53,7 +55,7 @@ def check_output(query):
elif os_name == "WINDOWS":
p = subprocess.Popen(query, stdout=subprocess.PIPE, shell=True)
output = p.communicate ()[0]
- return output
+ return output.decode()
def log(msg,type):
if type == 'info':
@@ -101,13 +103,13 @@ def logFile(msg):
f.write(msg+"\n")
f.close()
else:
- print("Unable to open file "+logFileName+" in write mode, Check file permissions.")
+ log("[E] Unable to open file "+logFileName+" in write mode, Check file permissions.", "error")
sys.exit()
else:
- print(logFileName+" is Invalid input file name! Provide valid file path to write DBA scripts:")
+ log("[E] "+logFileName+" is Invalid input file name! Provide valid file path to write DBA scripts:", "error")
sys.exit()
else:
- print("Invalid input! Provide file path to write DBA scripts:")
+ log("[E] Invalid input! Provide file path to write DBA scripts:", "error")
sys.exit()
def password_validation(password, userType):
@@ -1494,7 +1496,7 @@ def main(argv):
else :
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
@@ -1505,7 +1507,7 @@ def main(argv):
XA_DB_FLAVOR=''
while XA_DB_FLAVOR == "":
log("Enter db flavour{MYSQL|ORACLE|POSTGRES|MSSQL|SQLA} :","info")
- XA_DB_FLAVOR=raw_input()
+ XA_DB_FLAVOR=input()
AUDIT_DB_FLAVOR = XA_DB_FLAVOR
XA_DB_FLAVOR = XA_DB_FLAVOR.upper()
@@ -1519,10 +1521,10 @@ def main(argv):
if not dryMode:
if XA_DB_FLAVOR == "MYSQL" or XA_DB_FLAVOR == "ORACLE" or XA_DB_FLAVOR == "POSTGRES" or XA_DB_FLAVOR == "MSSQL" or XA_DB_FLAVOR == "SQLA":
log("Enter JDBC connector file for :"+XA_DB_FLAVOR,"info")
- CONNECTOR_JAR=raw_input()
+ CONNECTOR_JAR=input()
while os.path.isfile(CONNECTOR_JAR) == False:
log("JDBC connector file "+CONNECTOR_JAR+" does not exist, Please enter connector path :","error")
- CONNECTOR_JAR=raw_input()
+ CONNECTOR_JAR=input()
else:
log("[E] ---------- NO SUCH SUPPORTED DB FLAVOUR.. ----------", "error")
sys.exit(1)
@@ -1539,7 +1541,7 @@ def main(argv):
xa_db_host=''
while xa_db_host == "":
log("Enter DB Host :","info")
- xa_db_host=raw_input()
+ xa_db_host=input()
audit_db_host=xa_db_host
log("[I] DB Host:" + str(xa_db_host),"info")
@@ -1554,7 +1556,7 @@ def main(argv):
xa_db_root_user=''
while xa_db_root_user == "":
log("Enter db root user:","info")
- xa_db_root_user=raw_input()
+ xa_db_root_user=input()
log("Enter db root password:","info")
xa_db_root_password = getpass.getpass("Enter db root password:")
@@ -1567,7 +1569,7 @@ def main(argv):
db_name = ''
while db_name == "":
log("Enter DB Name :","info")
- db_name=raw_input()
+ db_name=input()
if (quiteMode):
db_user = globalDict['db_user']
@@ -1578,7 +1580,7 @@ def main(argv):
db_user=''
while db_user == "":
log("Enter db user name:","info")
- db_user=raw_input()
+ db_user=input()
if (quiteMode):
db_password = globalDict['db_password']
@@ -1610,7 +1612,7 @@ def main(argv):
audit_db_name=''
while audit_db_name == "":
log("Enter audit db name:","info")
- audit_db_name = raw_input()
+ audit_db_name = input()
if (quiteMode):
if 'audit_db_user' in globalDict:
@@ -1622,7 +1624,7 @@ def main(argv):
audit_db_user=''
while audit_db_user == "":
log("Enter audit user name:","info")
- audit_db_user = raw_input()
+ audit_db_user = input()
if (quiteMode):
if 'audit_db_password' in globalDict:
diff --git a/security-admin/scripts/deleteUserGroupUtil.py b/security-admin/scripts/deleteUserGroupUtil.py
index 04648b3..1c9f583 100644
--- a/security-admin/scripts/deleteUserGroupUtil.py
+++ b/security-admin/scripts/deleteUserGroupUtil.py
@@ -17,7 +17,11 @@ import os,sys
import pycurl
import getpass
import logging
-from StringIO import StringIO as BytesIO
+try:
+ from StringIO import StringIO as BytesIO
+except ImportError:
+ from io import BytesIO
+
def log(msg,type):
if type == 'info':
logging.info(" %s",msg)
@@ -85,12 +89,12 @@ def processRequest(url,usernamepassword,data,method,isHttps,certfile,isDebug):
header.close()
c.close()
if isDebug ==True or (response_code!=200 and response_code!=204):
- print 'Request URL = ' + str(url)
- print 'Response = ' + str(headerResponse)
+ log('Request URL = ' + str(url), "info")
+ log('Response = ' + str(headerResponse), "info")
return response_code
def validateArgs(argv):
if(len(argv)<7):
- log("[E] insufficient number of arguments. Found " + len(argv) + "; expected at least 7","error")
+ log("[E] insufficient number of arguments. Found " + str(len(argv)) + "; expected at least 7","error")
printUsage()
if not "-users" in argv and not "-groups" in argv:
log("[E] -users or -groups switch was missing!","error")
@@ -217,8 +221,8 @@ def main(argv):
response_code=0
try:
response_code=processRequest(url,usernamepassword,None,'get',isHttps,certfile,False)
- except pycurl.error, e:
- print e
+ except pycurl.error as e:
+ print(e)
sys.exit(1)
if response_code == 302 or response_code==401 or response_code==403:
log("[E] Authentication Error:Please try with valid credentials!","error")
diff --git a/security-admin/scripts/ranger_credential_helper.py b/security-admin/scripts/ranger_credential_helper.py
index b36adea..85f29ac 100644
--- a/security-admin/scripts/ranger_credential_helper.py
+++ b/security-admin/scripts/ranger_credential_helper.py
@@ -20,11 +20,11 @@ from subprocess import Popen,PIPE
from optparse import OptionParser
if os.getenv('JAVA_HOME') is None:
- print "ERROR: JAVA_HOME environment property was not defined, exit."
+ print("ERROR: JAVA_HOME environment property was not defined, exit.")
sys.exit(1)
else:
JAVA_BIN=os.path.join(os.getenv('JAVA_HOME'),'bin','java')
-print "Using Java:" + str(JAVA_BIN)
+print("Using Java:" + str(JAVA_BIN))
def main():
@@ -54,22 +54,22 @@ def call_keystore(libpath, filepath, aliasKey, aliasValue='', getorcreate='get')
output, error = p.communicate()
statuscode = p.returncode
if statuscode == 0:
- print "Alias " + aliasKey + " created successfully!"
+ print("Alias " + aliasKey + " created successfully!")
else :
- print "Error creating Alias!! Error: " + str(error)
-
+ print("Error creating Alias!! Error: " + str(error))
+
elif getorcreate == 'get':
commandtorun = [JAVA_BIN, '-cp', finalLibPath, 'org.apache.ranger.credentialapi.buildks' ,'get', aliasKey, '-provider',finalFilePath]
p = Popen(commandtorun,stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, error = p.communicate()
statuscode = p.returncode
if statuscode == 0:
- print "Alias : " + aliasKey + " Value : " + str(output)
+ print("Alias : " + aliasKey + " Value : " + str(output))
else :
- print "Error getting value!! Error: " + str(error)
-
+ print("Error getting value!! Error: " + str(error))
+
else:
- print 'Invalid Arguments!!'
-
+ print('Invalid Arguments!!')
+
if __name__ == '__main__':
main()
diff --git a/security-admin/scripts/restrict_permissions.py b/security-admin/scripts/restrict_permissions.py
index 1ce54a5..b19bafe 100644
--- a/security-admin/scripts/restrict_permissions.py
+++ b/security-admin/scripts/restrict_permissions.py
@@ -26,6 +26,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
+try: input = raw_input
+except NameError: pass
globalDict = {}
os_name = platform.system()
@@ -82,13 +84,13 @@ def logFile(msg):
f.write(msg+"\n")
f.close()
else:
- print("Unable to open file "+logFileName+" in write mode, Check file permissions.")
+ log("[E] Unable to open file "+logFileName+" in write mode, Check file permissions.", "error")
sys.exit()
else:
- print(logFileName+" is Invalid input file name! Provide valid file path to write DBA scripts:")
+ log("[E] "+ logFileName+" is Invalid input file name! Provide valid file path to write DBA scripts:", "error")
sys.exit()
else:
- print("Invalid input! Provide file path to write DBA scripts:")
+ log("[E] Invalid input! Provide file path to write DBA scripts:", "error")
sys.exit()
class BaseDB(object):
@@ -303,10 +305,10 @@ def main(argv):
JAVA_BIN = JAVA_BIN+'.exe'
if os.path.isfile(JAVA_BIN):
pass
- else :
+ else :
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
if (quiteMode):
@@ -316,7 +318,7 @@ def main(argv):
XA_DB_FLAVOR=''
while XA_DB_FLAVOR == "":
log("Enter db flavour{MYSQL} :","info")
- XA_DB_FLAVOR=raw_input()
+ XA_DB_FLAVOR=input()
AUDIT_DB_FLAVOR = XA_DB_FLAVOR
XA_DB_FLAVOR = XA_DB_FLAVOR.upper()
AUDIT_DB_FLAVOR = AUDIT_DB_FLAVOR.upper()
@@ -328,10 +330,10 @@ def main(argv):
else:
if XA_DB_FLAVOR == "MYSQL":
log("Enter JDBC connector file for :"+XA_DB_FLAVOR,"info")
- CONNECTOR_JAR=raw_input()
+ CONNECTOR_JAR=input()
while os.path.isfile(CONNECTOR_JAR) == False:
log("JDBC connector file "+CONNECTOR_JAR+" does not exist, Please enter connector path :","error")
- CONNECTOR_JAR=raw_input()
+ CONNECTOR_JAR=input()
else:
log("[E] ---------- NO SUCH SUPPORTED DB FLAVOUR.. ----------", "error")
sys.exit(1)
@@ -343,7 +345,7 @@ def main(argv):
xa_db_host=''
while xa_db_host == "":
log("Enter DB Host :","info")
- xa_db_host=raw_input()
+ xa_db_host=input()
audit_db_host=xa_db_host
log("[I] DB Host:" + str(xa_db_host),"info")
@@ -354,7 +356,7 @@ def main(argv):
xa_db_root_user=''
while xa_db_root_user == "":
log("Enter db root user:","info")
- xa_db_root_user=raw_input()
+ xa_db_root_user=input()
log("Enter db root password:","info")
xa_db_root_password = getpass.getpass("Enter db root password:")
@@ -364,7 +366,7 @@ def main(argv):
db_name = ''
while db_name == "":
log("Enter DB Name :","info")
- db_name=raw_input()
+ db_name=input()
if (quiteMode):
db_user = globalDict['db_user']
@@ -372,7 +374,7 @@ def main(argv):
db_user=''
while db_user == "":
log("Enter db user name:","info")
- db_user=raw_input()
+ db_user=input()
if (quiteMode):
db_password = globalDict['db_password']
@@ -388,7 +390,7 @@ def main(argv):
audit_db_name=''
while audit_db_name == "":
log("Enter audit db name:","info")
- audit_db_name = raw_input()
+ audit_db_name = input()
if (quiteMode):
audit_db_user = globalDict['audit_db_user']
@@ -396,7 +398,7 @@ def main(argv):
audit_db_user=''
while audit_db_user == "":
log("Enter audit user name:","info")
- audit_db_user = raw_input()
+ audit_db_user = input()
if (quiteMode):
audit_db_password = globalDict['audit_db_password']
diff --git a/security-admin/scripts/rolebasedusersearchutil.py b/security-admin/scripts/rolebasedusersearchutil.py
index 23e0839..f9feddc 100644
--- a/security-admin/scripts/rolebasedusersearchutil.py
+++ b/security-admin/scripts/rolebasedusersearchutil.py
@@ -29,7 +29,8 @@ from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
from operator import contains
-
+try: input = raw_input
+except NameError: pass
os_name = platform.system()
os_name = os_name.upper()
@@ -77,7 +78,7 @@ def main(argv):
else:
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
userName = ""
password = ""
@@ -88,10 +89,10 @@ def main(argv):
userroleFlag = False
if len(argv) == 1:
- print msgPrompt + " or \n" + msgCommand + "\n " +msgRoleList
- userName = raw_input('Enter a user name: ')
+ log("[I] " +msgPrompt + " or \n" + msgCommand + "\n " +msgRoleList, "info")
+ userName = input('Enter a user name: ')
password = getpass.getpass('Enter a user password:')
- userRole = raw_input('Enter a role: ')
+ userRole = input('Enter a role: ')
elif len(argv) > 1 and len(argv) < 8 :
for i in range(1, len(sys.argv)) :
if sys.argv[i] == "-u" :
@@ -128,13 +129,13 @@ def main(argv):
if userRole.lower() == "-p" or userRole.lower() == "-r" or userRole.lower() == "-u":
userRoleMsgFlag = True
if userNameMsgFlag == True or passwordMsgFlag == True or userRoleMsgFlag == True :
- print msgPrompt + " or \n" + msgCommand + "\n " +msgRoleList
+ log("[I] "+msgPrompt + " or \n" + msgCommand + "\n " +msgRoleList, "info")
if userNameMsgFlag == True :
- userName = raw_input('Enter a user name: ')
+ userName = input('Enter a user name: ')
if passwordMsgFlag == True :
password = getpass.getpass("Enter user password:")
if userRoleMsgFlag == True :
- userRole = raw_input('Enter a role: ')
+ userRole = input('Enter a role: ')
if userName != "" and password != "" :
if os_name == "LINUX":
path = os.path.join("%s","WEB-INF","classes","conf:%s","WEB-INF","classes","lib","*:%s","WEB-INF",":%s","META-INF",":%s","WEB-INF","lib","*:%s","WEB-INF","classes",":%s","WEB-INF","classes","META-INF:%s/*")%(app_home ,app_home ,app_home, app_home, app_home, app_home ,app_home,ews_lib)
diff --git a/security-admin/scripts/updateUserAndGroupNamesInJson.py b/security-admin/scripts/updateUserAndGroupNamesInJson.py
index f56e048..b115d22 100644
--- a/security-admin/scripts/updateUserAndGroupNamesInJson.py
+++ b/security-admin/scripts/updateUserAndGroupNamesInJson.py
@@ -28,6 +28,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
+try: input = raw_input
+except NameError: pass
os_name = platform.system()
os_name = os_name.upper()
@@ -72,7 +74,7 @@ def main(argv):
else:
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
if os_name == "LINUX":
diff --git a/security-admin/scripts/update_property.py b/security-admin/scripts/update_property.py
index 1eab564..fc2a310 100644
--- a/security-admin/scripts/update_property.py
+++ b/security-admin/scripts/update_property.py
@@ -23,7 +23,7 @@ def write_properties_to_xml(xml_path, property_name='', property_value=''):
try:
xml = ET.parse(xml_path)
except ExpatError:
- print "Error while parsing file:"+xml_path
+ print("Error while parsing file:"+xml_path)
return -1
root = xml.getroot()
for child in root.findall('property'):
diff --git a/security-admin/scripts/upgrade_admin.py b/security-admin/scripts/upgrade_admin.py
index 903f8bb..10fa485 100755
--- a/security-admin/scripts/upgrade_admin.py
+++ b/security-admin/scripts/upgrade_admin.py
@@ -13,9 +13,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-import StringIO
+from __future__ import print_function
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+try:
+ from ConfigParser import ConfigParser
+except ImportError:
+ from configparser import ConfigParser
import xml.etree.ElementTree as ET
-import ConfigParser
import os,sys,getopt
from os import listdir
from os.path import isfile, join, dirname, basename
@@ -29,10 +36,10 @@ installPropFileName = 'install.properties'
tempLibFolder = "./upgrade-temp"
def showUsage():
- print "upgrade_admin.py [-g] [-h]"
- print "This script will generate %s based on currently installed ranger (v0.4.*) configuration." % (installPropFileName)
- print " -g option will generate ranger-admin-site.xml in the current directory."
- print " -h will display help text."
+ print("upgrade_admin.py [-g] [-h]")
+ print("This script will generate %s based on currently installed ranger (v0.4.*) configuration." % (installPropFileName))
+ print(" -g option will generate ranger-admin-site.xml in the current directory.")
+ print(" -h will display help text.")
try:
opts, args = getopt.getopt(sys.argv[1:],"gh")
@@ -130,16 +137,16 @@ def archiveFile(originalFileName):
archiveDir = dirname(originalFileName)
archiveFileName = "." + basename(originalFileName) + "." + (strftime("%d%m%Y%H%M%S", localtime()))
movedFileName = join(archiveDir,archiveFileName)
- print "INFO: moving [%s] to [%s] ......." % (originalFileName,movedFileName)
+ print("INFO: moving [%s] to [%s] ......." % (originalFileName,movedFileName))
os.rename(originalFileName, movedFileName)
def getPropertiesConfigMap(configFileName):
ret = {}
- config = StringIO.StringIO()
+ config = StringIO()
config.write('[dummysection]\n')
config.write(open(configFileName).read())
config.seek(0,os.SEEK_SET)
- fcp = ConfigParser.ConfigParser()
+ fcp = ConfigParser()
fcp.optionxform = str
fcp.readfp(config)
for k,v in fcp.items('dummysection'):
@@ -148,11 +155,11 @@ def getPropertiesConfigMap(configFileName):
def getPropertiesKeyList(configFileName):
ret = []
- config = StringIO.StringIO()
+ config = StringIO()
config.write('[dummysection]\n')
config.write(open(configFileName).read())
config.seek(0,os.SEEK_SET)
- fcp = ConfigParser.ConfigParser()
+ fcp = ConfigParser()
fcp.optionxform = str
fcp.readfp(config)
for k,v in fcp.items('dummysection'):
@@ -171,10 +178,10 @@ def writeXMLUsingProperties(xmlTemplateFileName,prop,xmlOutputFileName):
root = tree.getroot()
for config in root.iter('property'):
name = config.find('name').text
- if (name in prop.keys()):
+ if (name in list(prop)):
config.find('value').text = prop[name]
else:
- print "ERROR: key not found: %s" % (name)
+ print("ERROR: key not found: %s" % (name))
if isfile(xmlOutputFileName):
archiveFile(xmlOutputFileName)
tree.write(xmlOutputFileName)
@@ -196,15 +203,15 @@ def main():
webserverConfigFileName = join(configDirectory, webserverConfigFile)
webconfig = getPropertiesConfigMap(webserverConfigFileName)
- for k in config2xmlMAP.keys():
+ for k in list(config2xmlMAP):
xmlKey = config2xmlMAP[k]
- if (k in xaSysProps.keys()):
+ if (k in list(xaSysProps)):
xmlVal = xaSysProps[k]
- elif (k in xaLdapProps.keys()):
+ elif (k in list(xaLdapProps)):
xmlVal = xaLdapProps[k]
- elif (k in unixauthProps.keys()):
+ elif (k in list(unixauthProps)):
xmlVal = unixauthProps[k]
- elif (k in webconfig.keys()):
+ elif (k in list(webconfig)):
xmlVal = webconfig[k]
else:
xmlVal = 'Unknown'
@@ -255,7 +262,7 @@ def main():
installProps['db_name'] = ''
installProps['audit_db_name'] = ''
else:
- print "ERROR: Unable to determine the DB_FLAVOR from url [%]" % (jdbcUrl)
+ print("ERROR: Unable to determine the DB_FLAVOR from url [%]" % (jdbcUrl))
sys.exit(1)
installProps['db_user'] = xaSysProps['jdbc.user']
@@ -300,13 +307,13 @@ def main():
defValMap = getPropertiesConfigMap(installFileName)
- for wk,wv in webconfig.iteritems():
+ for wk,wv in webconfig.items():
nk = "ranger." + wk
- nk = nk.replace('.','_')
+ nk = nk.replace('.','_')
installProps[nk] = wv
keylist.append(nk)
- writeToFile(keylist,defValMap,installProps,installPropFileName)
+ writeToFile(keylist,defValMap,installProps,installPropFileName)
if (generateXML == 1):
writeXMLUsingProperties(join(templateDirectoryName,rangerSiteTemplateXMLFile), rangerprops, rangerSiteXMLFile)
@@ -315,22 +322,22 @@ def writeToFile(keyList, defValMap, props, outFileName):
if (isfile(outFileName)):
archiveFile(outFileName)
-
+
outf = open(outFileName, 'w')
- print >> outf, "#"
- print >> outf, "# -----------------------------------------------------------------------------------"
- print >> outf, "# This file is generated as part of upgrade script and should be deleted after upgrade"
- print >> outf, "# Generated at %s " % (strftime("%d/%m/%Y %H:%M:%S", localtime()))
- print >> outf, "# -----------------------------------------------------------------------------------"
- print >> outf, "#"
+ print("#", file=outf)
+ print("# -----------------------------------------------------------------------------------", file=outf)
+ print("# This file is generated as part of upgrade script and should be deleted after upgrade", file=outf)
+ print("# Generated at %s " % (strftime("%d/%m/%Y %H:%M:%S", localtime())), file=outf)
+ print("# -----------------------------------------------------------------------------------", file=outf)
+ print("#", file=outf)
for key in keyList:
if (key in props):
- print >> outf, "%s=%s" % (key,props[key])
+ print("%s=%s" % (key,props[key]), file=outf)
else:
- print >> outf, "# Default value for [%s] is used\n%s=%s\n#---" % (key, key,defValMap[key])
-
+ print("# Default value for [%s] is used\n%s=%s\n#---" % (key, key,defValMap[key]), file=outf)
+
outf.flush()
outf.close()
diff --git a/security-admin/src/bin/ranger_install.py b/security-admin/src/bin/ranger_install.py
index 0cbe43d..90ac92a 100644
--- a/security-admin/src/bin/ranger_install.py
+++ b/security-admin/src/bin/ranger_install.py
@@ -16,15 +16,19 @@ import sys
import errno
import logging
import zipfile
-import ConfigParser
-import StringIO
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+try:
+ from ConfigParser import ConfigParser
+except ImportError:
+ from configparser import ConfigParser
import subprocess
import fileinput
-#import MySQLdb
import zipfile
import re
import shutil
-import commands
from datetime import date
import getpass
import glob
@@ -78,11 +82,11 @@ def getstatusoutput(cmd):
"sts = pipe.returncode
"""
ret = subprocess.call(cmd, shell=True)
- print "------------------"
- print " cmd: " + str(cmd)
+ print("------------------")
+ print(" cmd: " + str(cmd))
#print " output: " + output
- print " ret: " + str(ret)
- print "------------------"
+ print(" ret: " + str(ret))
+ print("------------------")
return ret, ret
#if sts is None:
# log("sts is None!!!! Manually setting to -1. PLEASE CHECK!!!!!!!!!!!!!!","info")
@@ -168,8 +172,7 @@ def get_class_path(paths):
def get_jdk_options():
global conf_dict
- return [os.getenv('RANGER_PROPERTIES', ''),"-Dlogdir="+os.getenv("RANGER_LOG_DIR"),
- ' -Dcatalina.base=' + conf_dict['EWS_ROOT'] ]
+ return [os.getenv('RANGER_PROPERTIES', ''),"-Dlogdir="+os.getenv("RANGER_LOG_DIR"),' -Dcatalina.base=' + conf_dict['EWS_ROOT'] ]
"""
@@ -263,7 +266,7 @@ def init_variables(switch):
conf_dict['JAVA_BIN']= os.path.join(os.getenv("JAVA_HOME"),'bin','java.exe')
conf_dict['DB_FLAVOR'] = os.getenv("RANGER_DB_FLAVOR")
conf_dict['RANGER_DB_FLAVOR'] = os.getenv("RANGER_DB_FLAVOR")
- conf_dict['RANGER_AUDIT_DB_FLAVOR'] = os.getenv("RANGER_DB_FLAVOR")
+ conf_dict['RANGER_AUDIT_DB_FLAVOR'] = os.getenv("RANGER_DB_FLAVOR")
dir = os.path.join(os.getenv("RANGER_HOME"),"connector-jar")
ews_dir = os.path.join(os.getenv("RANGER_ADMIN_HOME"),"ews","webapp","WEB-INF","lib")
log(ews_dir,"info")
@@ -287,8 +290,8 @@ def init_variables(switch):
shutil.copy2(src, dir)
shutil.copy2(src, ews_dir)
conf_dict['SQL_CONNECTOR_JAR'] = os.path.join(dir,filename)
-
-
+
+
conf_dict['db_host']=os.getenv("RANGER_ADMIN_DB_HOST") + ":" + os.getenv("RANGER_ADMIN_DB_PORT")
conf_dict['db_name']=os.getenv("RANGER_ADMIN_DB_DBNAME")
conf_dict['db_user']=os.getenv("RANGER_ADMIN_DB_USERNAME")
@@ -438,15 +441,15 @@ def get_mysql_cmd(user, password, host):
return cmdArr
def create_mysql_user(db_name, db_user, db_password, db_host, db_root_password):
- global conf_dict
- cmdArr = []
-
- MYSQL_BIN = conf_dict["MYSQL_BIN"]
- hosts_arr =["%", "localhost"]
- #check_mysql_password()
- ### From properties file
- log("\nCreating MySQL user "+db_user+" (using root priviledges)\n", 'debug')
- for host in hosts_arr:
+ global conf_dict
+ cmdArr = []
+
+ MYSQL_BIN = conf_dict["MYSQL_BIN"]
+ hosts_arr =["%", "localhost"]
+ #check_mysql_password()
+ ### From properties file
+ log("\nCreating MySQL user "+db_user+" (using root priviledges)\n", 'debug')
+ for host in hosts_arr:
cmdArr = get_mysql_cmd('root', db_root_password, db_host)
#subprocess.call(["mysql", "-u", username, "-p%s" % password, "-e", "SELECT @@hostname"]
@@ -486,8 +489,8 @@ def check_mysql_password ():
cmdStr = "\""+MYSQL_BIN+"\""+" -u root --password="+db_root_password+" -h "+MYSQL_HOST+" -s -e \"select version();\""
status, output = getstatusoutput(cmdStr)
- print "Status: " + str(status)
- print "output: " + str(output)
+ print("Status: " + str(status))
+ print("output: " + str(output))
if status == 0:
log("Checking MYSQL root password DONE", "info")
@@ -696,7 +699,7 @@ def update_xapolicymgr_properties():
ModConfig(xapolicymgr_properties,"xa.webapp.dir", WEBAPP_ROOT.replace('\\','/' ))
def updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file):
- ret = subprocess.call(['python', '%s\update_property.py' %os.getenv("RANGER_ADMIN_HOME"), propertyName ,newPropertyValue ,to_file])
+ ret = subprocess.call(['python', '%s\\update_property.py' %os.getenv("RANGER_ADMIN_HOME"), propertyName ,newPropertyValue ,to_file])
if ret == 0:
log("Updated property for :"+to_file,"info")
else:
@@ -884,22 +887,22 @@ def update_properties():
newPropertyValue="ranger.jpa.jdbc.password"
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_default)
- propertyName="ranger.credential.provider.path"
- newPropertyValue=os.getenv("RANGER_ADMIN_CRED_KEYSTORE_FILE")
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+ propertyName="ranger.credential.provider.path"
+ newPropertyValue=os.getenv("RANGER_ADMIN_CRED_KEYSTORE_FILE")
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.jpa.jdbc.password"
- newPropertyValue="_"
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
-
- propertyName="ranger.jpa.audit.jdbc.credential.alias"
+ propertyName="ranger.jpa.jdbc.password"
+ newPropertyValue="_"
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+
+ propertyName="ranger.jpa.audit.jdbc.credential.alias"
newPropertyValue="ranger.jpa.audit.jdbc.password"
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_default)
-
- propertyName="ranger.jpa.audit.jdbc.password"
- newPropertyValue="_"
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
-
+
+ propertyName="ranger.jpa.audit.jdbc.password"
+ newPropertyValue="_"
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+
else:
propertyName="ranger.jpa.jdbc.password"
newPropertyValue=os.getenv("RANGER_ADMIN_DB_PASSWORD")
@@ -911,7 +914,7 @@ def update_properties():
if os.getenv("RANGER_AUTHENTICATION_METHOD") == "LDAP":
- password_validation(os.getenv("RANGER_LDAP_BIND_PASSWORD"), "LDAP_BIND")
+ password_validation(os.getenv("RANGER_LDAP_BIND_PASSWORD"), "LDAP_BIND")
propertyName="ranger.authentication.method"
newPropertyValue=os.getenv("RANGER_AUTHENTICATION_METHOD")
@@ -936,30 +939,30 @@ def update_properties():
propertyName="ranger.ldap.group.roleattribute"
newPropertyValue=os.getenv("RANGER_LDAP_GROUPROLEATTRIBUTE")
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
-
- propertyName="ranger.ldap.base.dn"
+
+ propertyName="ranger.ldap.base.dn"
newPropertyValue=os.getenv("RANGER_LDAP_BASE_DN")
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.ldap.bind.dn"
- newPropertyValue=os.getenv("RANGER_LDAP_BIND_DN")
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
-
- propertyName="ranger.ldap.bind.password"
- newPropertyValue="_"
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
-
+ propertyName="ranger.ldap.bind.dn"
+ newPropertyValue=os.getenv("RANGER_LDAP_BIND_DN")
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+
+ propertyName="ranger.ldap.bind.password"
+ newPropertyValue="_"
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+
propertyName="ranger.ldap.referral"
newPropertyValue=os.getenv("RANGER_LDAP_REFERRAL")
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.ldap.user.searchfilter"
- newPropertyValue=os.getenv("RANGER_LDAP_USERSEARCHFILTER")
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+ propertyName="ranger.ldap.user.searchfilter"
+ newPropertyValue=os.getenv("RANGER_LDAP_USERSEARCHFILTER")
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
elif os.getenv("RANGER_AUTHENTICATION_METHOD") == "ACTIVE_DIRECTORY":
- password_validation(os.getenv("RANGER_LDAP_AD_BIND_PASSWORD"), "AD_BIND")
+ password_validation(os.getenv("RANGER_LDAP_AD_BIND_PASSWORD"), "AD_BIND")
propertyName="ranger.authentication.method"
newPropertyValue=os.getenv("RANGER_AUTHENTICATION_METHOD")
@@ -973,25 +976,25 @@ def update_properties():
newPropertyValue=os.getenv("RANGER_LDAP_AD_URL")
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.ldap.ad.base.dn"
+ propertyName="ranger.ldap.ad.base.dn"
newPropertyValue=os.getenv("RANGER_LDAP_AD_BASE_DN")
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.ldap.ad.bind.dn"
- newPropertyValue=os.getenv("RANGER_LDAP_AD_BIND_DN")
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+ propertyName="ranger.ldap.ad.bind.dn"
+ newPropertyValue=os.getenv("RANGER_LDAP_AD_BIND_DN")
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+
+ propertyName="ranger.ldap.ad.bind.password"
+ newPropertyValue="_"
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.ldap.ad.bind.password"
- newPropertyValue="_"
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
-
propertyName="ranger.ldap.ad.referral"
newPropertyValue=os.getenv("RANGER_LDAP_AD_REFERRAL")
updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
- propertyName="ranger.ldap.ad.user.searchfilter"
- newPropertyValue=os.getenv("RANGER_LDAP_AD_USERSEARCHFILTER")
- updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
+ propertyName="ranger.ldap.ad.user.searchfilter"
+ newPropertyValue=os.getenv("RANGER_LDAP_AD_USERSEARCHFILTER")
+ updatePropertyToFilePy(propertyName ,newPropertyValue ,to_file_ranger)
def setup_authentication(authentication_method, xmlPath):
if authentication_method == "UNIX":
@@ -1275,7 +1278,7 @@ def call_keystore(libpath,aliasKey,aliasValue , filepath,getorcreate):
statuscode = p.returncode
return statuscode, output
else:
- print 'proper command not received for input need get or create'
+ print('proper command not received for input need get or create')
# Entry point to script using --service
diff --git a/security-admin/src/bin/ranger_usersync.py b/security-admin/src/bin/ranger_usersync.py
index 4309589..4374896 100644
--- a/security-admin/src/bin/ranger_usersync.py
+++ b/security-admin/src/bin/ranger_usersync.py
@@ -17,10 +17,8 @@ import os
import logging
import subprocess
import time
-#import ranger_install
from xml.dom.minidom import getDOMImplementation
import shutil
-import commands
import re
cmd = sys.argv[0]
@@ -76,9 +74,9 @@ def init_variables():
conf_dict["RANGER_ADMIN_HOME"] = os.getenv("RANGER_ADMIN_HOME")
conf_dict["RANGER_USERSYNC_HOME"] = os.getenv("RANGER_USERSYNC_HOME")
conf_dict["INSTALL_DIR"] = os.getenv("RANGER_USERSYNC_HOME")
- USERSYNC_HOME = conf_dict['RANGER_USERSYNC_HOME']
+ USERSYNC_HOME = conf_dict['RANGER_USERSYNC_HOME']
copy_files(os.path.join(USERSYNC_HOME,"conf.dist"), os.path.join(USERSYNC_HOME,"conf"))
- pass
+ pass
def get_class_path(paths):
separator = ';' if sys.platform == 'win32' else ':';
@@ -117,7 +115,7 @@ if service_entry:
text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL)
prettyXml = text_re.sub('>\g<1></', uglyXml)
- print prettyXml
+ print(prettyXml)
except:
sys.exit(1)
diff --git a/security-admin/src/bin/service_start.py b/security-admin/src/bin/service_start.py
index 035a86c..ea13b85 100644
--- a/security-admin/src/bin/service_start.py
+++ b/security-admin/src/bin/service_start.py
@@ -55,7 +55,7 @@ if service_entry:
text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL)
prettyXml = text_re.sub('>\g<1></', uglyXml)
- print prettyXml
+ print(prettyXml)
except:
- print "######################## Ranger Setup failed! #######################"
+ print("######################## Ranger Setup failed! #######################")
sys.exit(1)
diff --git a/tagsync/scripts/setup.py b/tagsync/scripts/setup.py
index 1293303..10835b0 100755
--- a/tagsync/scripts/setup.py
+++ b/tagsync/scripts/setup.py
@@ -14,21 +14,30 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+try:
+ from ConfigParser import ConfigParser
+except ImportError:
+ from configparser import ConfigParser
+try:
+ from urlparse import urlparse
+except ImportError:
+ from urllib.parse import urlparse
import re
-import StringIO
import xml.etree.ElementTree as ET
-import ConfigParser
import os,errno,sys,getopt
from os import listdir
from os.path import isfile, join, dirname, basename
-from urlparse import urlparse
from time import gmtime, strftime, localtime
from xml import etree
import shutil
import pwd, grp
if (not 'JAVA_HOME' in os.environ):
- print "ERROR: JAVA_HOME environment variable is not defined. Please define JAVA_HOME before running this script"
+ print("ERROR: JAVA_HOME environment variable is not defined. Please define JAVA_HOME before running this script")
sys.exit(1)
debugLevel = 1
@@ -63,7 +72,7 @@ defaultKeyStoreFileName = '/etc/ranger/tagsync/conf/rangertagsync.jceks'
unixUserProp = 'unix_user'
unixGroupProp = 'unix_group'
-logFolderPermMode = 0777
+logFolderPermMode = 0o777
rootOwnerId = 0
initPrefixList = ['S99', 'K00']
@@ -98,7 +107,7 @@ configure_security = False
RANGER_TAGSYNC_HOME = os.getenv("RANGER_TAGSYNC_HOME")
if RANGER_TAGSYNC_HOME is None:
- RANGER_TAGSYNC_HOME = os.getcwd()
+ RANGER_TAGSYNC_HOME = os.getcwd()
def populate_global_dict():
global globalDict
@@ -120,7 +129,7 @@ def archiveFile(originalFileName):
archiveDir = dirname(originalFileName)
archiveFileName = "." + basename(originalFileName) + "." + (strftime("%d%m%Y%H%M%S", localtime()))
movedFileName = join(archiveDir,archiveFileName)
- print "INFO: moving [%s] to [%s] ......." % (originalFileName,movedFileName)
+ print("INFO: moving [%s] to [%s] ......." % (originalFileName,movedFileName))
os.rename(originalFileName, movedFileName)
def getXMLConfigKeys(xmlFileName):
@@ -145,11 +154,11 @@ def getXMLConfigMap(xmlFileName):
def getPropertiesConfigMap(configFileName):
ret = {}
- config = StringIO.StringIO()
+ config = StringIO()
config.write('[dummysection]\n')
config.write(open(configFileName).read())
config.seek(0,os.SEEK_SET)
- fcp = ConfigParser.ConfigParser()
+ fcp = ConfigParser()
fcp.optionxform = str
fcp.readfp(config)
for k,v in fcp.items('dummysection'):
@@ -158,11 +167,11 @@ def getPropertiesConfigMap(configFileName):
def getPropertiesKeyList(configFileName):
ret = []
- config = StringIO.StringIO()
+ config = StringIO()
config.write('[dummysection]\n')
config.write(open(configFileName).read())
config.seek(0,os.SEEK_SET)
- fcp = ConfigParser.ConfigParser()
+ fcp = ConfigParser()
fcp.optionxform = str
fcp.readfp(config)
for k,v in fcp.items('dummysection'):
@@ -170,11 +179,11 @@ def getPropertiesKeyList(configFileName):
return ret
def writeXMLUsingProperties(xmlTemplateFileName,prop,xmlOutputFileName):
- tree = ET.parse(xmlTemplateFileName)
- root = tree.getroot()
- for config in root.findall('property'):
- name = config.find('name').text
- if (name in prop.keys()):
+ tree = ET.parse(xmlTemplateFileName)
+ root = tree.getroot()
+ for config in root.findall('property'):
+ name = config.find('name').text
+ if (name in list(prop)):
if (name == TAGSYNC_ATLAS_TO_RANGER_SERVICE_MAPPING):
# Expected value is 'clusterName,componentName,serviceName;clusterName,componentName,serviceName' ...
# Blanks are not supported anywhere in the value.
@@ -192,16 +201,16 @@ def writeXMLUsingProperties(xmlTemplateFileName,prop,xmlOutputFileName):
newName.text = TAGSYNC_INSTALL_PROP_PREFIX_FOR_ATLAS_RANGER_MAPPING + str(parts[1]) + TAGSYNC_ATLAS_CLUSTER_IDENTIFIER + str(parts[0]) + TAGSYNC_INSTALL_PROP_SUFFIX_FOR_ATLAS_RANGER_MAPPING
newValue.text = str(parts[2])
else:
- print "ERROR: incorrect syntax for %s, value=%s" % (TAGSYNC_ATLAS_TO_RANGER_SERVICE_MAPPING, multiValues[index])
+ print("ERROR: incorrect syntax for %s, value=%s" % (TAGSYNC_ATLAS_TO_RANGER_SERVICE_MAPPING, multiValues[index]))
index += 1
root.remove(config)
else:
config.find('value').text = str(prop[name])
- #else:
- # print "ERROR: key not found: %s" % (name)
- if isfile(xmlOutputFileName):
- archiveFile(xmlOutputFileName)
- tree.write(xmlOutputFileName)
+ #else:
+ # print "ERROR: key not found: %s" % (name)
+ if isfile(xmlOutputFileName):
+ archiveFile(xmlOutputFileName)
+ tree.write(xmlOutputFileName)
def updatePropertyInJCKSFile(jcksFileName,propName,value):
fn = jcksFileName
@@ -210,7 +219,7 @@ def updatePropertyInJCKSFile(jcksFileName,propName,value):
cmd = "java -cp './lib/*' %s create '%s' -value '%s' -provider jceks://file%s 2>&1" % (credUpdateClassName,propName,value,fn)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: Unable to update the JCKSFile (%s) for aliasName (%s)" % (fn,propName)
+ print("ERROR: Unable to update the JCKSFile (%s) for aliasName (%s)" % (fn,propName))
sys.exit(1)
return ret
@@ -219,13 +228,13 @@ def convertInstallPropsToXML(props):
ret = {}
atlasOutFn = join(confFolderName, atlasApplicationPropFileName)
- atlasOutFile = file(atlasOutFn, "w")
+ atlasOutFile = open(atlasOutFn, "w")
atlas_principal = ''
atlas_keytab = ''
- for k,v in props.iteritems():
- if (k in directKeyMap.keys()):
+ for k,v in props.items():
+ if (k in list(directKeyMap)):
newKey = directKeyMap[k]
if (k == TAGSYNC_ATLAS_KAFKA_ENDPOINTS_KEY):
atlasOutFile.write(newKey + "=" + v + "\n")
@@ -244,7 +253,7 @@ def convertInstallPropsToXML(props):
else:
ret[newKey] = v
else:
- print "INFO: Direct Key not found:%s" % (k)
+ print("INFO: Direct Key not found:%s" % (k))
if (configure_security):
atlasOutFile.write("atlas.jaas.KafkaClient.loginModuleName = com.sun.security.auth.module.Krb5LoginModule" + "\n")
@@ -275,26 +284,26 @@ def createUser(username,groupname):
cmd = "useradd -g %s %s -m" % (groupname,username)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret)
+ print("ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret))
sys.exit(1)
try:
ret = pwd.getpwnam(username).pw_uid
return ret
- except KeyError, e:
- print "ERROR: Unable to create a new user account: %s with group %s - error [%s]" % (username,groupname,e)
+ except KeyError as e:
+ print("ERROR: Unable to create a new user account: %s with group %s - error [%s]" % (username,groupname,e))
sys.exit(1)
def createGroup(groupname):
cmd = "groupadd %s" % (groupname)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret)
+ print("ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret))
sys.exit(1)
try:
ret = grp.getgrnam(groupname).gr_gid
return ret
- except KeyError, e:
- print "ERROR: Unable to create a new group: %s" % (groupname,e)
+ except KeyError as e:
+ print("ERROR: Unable to create a new group: %s" % (groupname,e))
sys.exit(1)
def initializeInitD():
@@ -302,7 +311,7 @@ def initializeInitD():
fn = join(installPropDirName,initdProgramName)
initdFn = join(initdDirName,initdProgramName)
shutil.copy(fn, initdFn)
- os.chmod(initdFn,0550)
+ os.chmod(initdFn,0o550)
rcDirList = [ "/etc/rc2.d", "/etc/rc3.d", "/etc/rc.d/rc2.d", "/etc/rc.d/rc3.d" ]
for rcDir in rcDirList:
if (os.path.isdir(rcDir)):
@@ -323,7 +332,7 @@ def initializeInitD():
def write_env_files(exp_var_name, log_path, file_name):
final_path = "{0}/{1}".format(confBaseDirName,file_name)
if not os.path.isfile(final_path):
- print "INFO: Creating %s file" % file_name
+ print("INFO: Creating %s file" % file_name)
f = open(final_path, "w")
f.write("export {0}={1}".format(exp_var_name,log_path))
f.close()
@@ -332,7 +341,7 @@ def main():
global configure_security
- print "\nINFO: Installing ranger-tagsync .....\n"
+ print("\nINFO: Installing ranger-tagsync .....\n")
populate_global_dict()
@@ -345,16 +354,16 @@ def main():
hadoop_conf = globalDict['hadoop_conf']
- pid_dir_path = globalDict['TAGSYNC_PID_DIR_PATH']
- unix_user = globalDict['unix_user']
+ pid_dir_path = globalDict['TAGSYNC_PID_DIR_PATH']
+ unix_user = globalDict['unix_user']
- if pid_dir_path == "":
- pid_dir_path = "/var/run/ranger"
+ if pid_dir_path == "":
+ pid_dir_path = "/var/run/ranger"
dirList = [ rangerBaseDirName, tagsyncBaseDirFullName, confFolderName ]
for dir in dirList:
if (not os.path.isdir(dir)):
- os.makedirs(dir,0755)
+ os.makedirs(dir,0o755)
defFileList = [ log4jFileName ]
for defFile in defFileList:
@@ -372,7 +381,7 @@ def main():
str = "export JAVA_HOME=%s\n" % os.environ['JAVA_HOME']
jhf.write(str)
jhf.close()
- os.chmod(java_home_setter_fn,0750)
+ os.chmod(java_home_setter_fn,0o750)
if (not os.path.isdir(localConfFolderName)):
@@ -404,8 +413,8 @@ def main():
if (not os.path.isdir(tagsyncLogFolderName)):
os.makedirs(tagsyncLogFolderName,logFolderPermMode)
- if (not os.path.isdir(pid_dir_path)):
- os.makedirs(pid_dir_path,logFolderPermMode)
+ if (not os.path.isdir(pid_dir_path)):
+ os.makedirs(pid_dir_path,logFolderPermMode)
if (unixUserProp in mergeProps):
ownerName = mergeProps[unixUserProp]
@@ -421,12 +430,12 @@ def main():
try:
groupId = grp.getgrnam(groupName).gr_gid
- except KeyError, e:
+ except KeyError as e:
groupId = createGroup(groupName)
try:
ownerId = pwd.getpwnam(ownerName).pw_uid
- except KeyError, e:
+ except KeyError as e:
ownerId = createUser(ownerName, groupName)
os.chown(logFolderName,ownerId,groupId)
@@ -469,53 +478,54 @@ def main():
for dir in fixPermList:
for root, dirs, files in os.walk(dir):
os.chown(root, ownerId, groupId)
- os.chmod(root,0755)
+ os.chmod(root,0o755)
for obj in dirs:
dn = join(root,obj)
os.chown(dn, ownerId, groupId)
- os.chmod(dn, 0755)
+ os.chmod(dn, 0o755)
for obj in files:
fn = join(root,obj)
os.chown(fn, ownerId, groupId)
- os.chmod(fn, 0755)
+ os.chmod(fn, 0o755)
write_env_files("RANGER_TAGSYNC_HADOOP_CONF_DIR", hadoop_conf, ENV_HADOOP_CONF_FILE)
- write_env_files("TAGSYNC_PID_DIR_PATH", pid_dir_path, ENV_PID_FILE);
+ write_env_files("TAGSYNC_PID_DIR_PATH", pid_dir_path, ENV_PID_FILE);
os.chown(os.path.join(confBaseDirName, ENV_HADOOP_CONF_FILE),ownerId,groupId)
- os.chmod(os.path.join(confBaseDirName, ENV_HADOOP_CONF_FILE),0755)
- os.chown(os.path.join(confBaseDirName, ENV_PID_FILE),ownerId,groupId)
- os.chmod(os.path.join(confBaseDirName, ENV_PID_FILE),0755)
+ os.chmod(os.path.join(confBaseDirName, ENV_HADOOP_CONF_FILE),0o755)
+ os.chown(os.path.join(confBaseDirName, ENV_PID_FILE),ownerId,groupId)
+ os.chmod(os.path.join(confBaseDirName, ENV_PID_FILE),0o755)
- f = open(os.path.join(confBaseDirName, ENV_PID_FILE), "a+")
- f.write("\nexport {0}={1}".format("UNIX_TAGSYNC_USER",unix_user))
- f.close()
+ f = open(os.path.join(confBaseDirName, ENV_PID_FILE), "a+")
+ f.write("\nexport {0}={1}".format("UNIX_TAGSYNC_USER",unix_user))
+ f.close()
hadoop_conf_full_path = os.path.join(hadoop_conf, hadoopConfFileName)
tagsync_conf_full_path = os.path.join(tagsyncBaseDirFullName,confBaseDirName,hadoopConfFileName)
if not isfile(hadoop_conf_full_path):
- print "WARN: core-site.xml file not found in provided hadoop conf path..."
+ print("WARN: core-site.xml file not found in provided hadoop conf path...")
f = open(tagsync_conf_full_path, "w")
f.write("<configuration></configuration>")
f.close()
os.chown(tagsync_conf_full_path,ownerId,groupId)
- os.chmod(tagsync_conf_full_path,0750)
+ os.chmod(tagsync_conf_full_path,0o750)
else:
if os.path.islink(tagsync_conf_full_path):
os.remove(tagsync_conf_full_path)
if isfile(hadoop_conf_full_path) and not isfile(tagsync_conf_full_path):
- os.symlink(hadoop_conf_full_path, tagsync_conf_full_path)
- rangerTagsync_password = globalDict['rangerTagsync_password']
- rangerTagsync_name ='rangerTagsync'
- endPoint='RANGER'
- cmd = 'python updatetagadminpassword.py %s %s %s' %(endPoint, rangerTagsync_name, rangerTagsync_password)
- if rangerTagsync_password != "" :
- output = os.system(cmd)
- if (output == 0):
- print "[I] Successfully updated password of " + rangerTagsync_name +" user"
- else:
- print "[ERROR] Unable to change password of " + rangerTagsync_name +" user."
- print "\nINFO: Completed ranger-tagsync installation.....\n"
+ os.symlink(hadoop_conf_full_path, tagsync_conf_full_path)
+
+ rangerTagsync_password = globalDict['rangerTagsync_password']
+ rangerTagsync_name ='rangerTagsync'
+ endPoint='RANGER'
+ cmd = 'python updatetagadminpassword.py %s %s %s' %(endPoint, rangerTagsync_name, rangerTagsync_password)
+ if rangerTagsync_password != "" :
+ output = os.system(cmd)
+ if (output == 0):
+ print("[I] Successfully updated password of " + rangerTagsync_name +" user")
+ else:
+ print("[ERROR] Unable to change password of " + rangerTagsync_name +" user.")
+ print("\nINFO: Completed ranger-tagsync installation.....\n")
main()
diff --git a/tagsync/scripts/updatetagadminpassword.py b/tagsync/scripts/updatetagadminpassword.py
index f3e3025..ff0cce1 100644
--- a/tagsync/scripts/updatetagadminpassword.py
+++ b/tagsync/scripts/updatetagadminpassword.py
@@ -29,6 +29,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
+try: input = raw_input
+except NameError: pass
globalDict = {}
os_name = platform.system()
@@ -55,7 +57,7 @@ def log(msg,type):
logging.error(" %s",msg)
def import_properties_from_xml(xml_path, properties_from_xml=None):
- print('getting values from file : ' + str(xml_path))
+ log('[I] Getting values from file : ' + str(xml_path), "info")
if os.path.isfile(xml_path):
xml = ET.parse(xml_path)
root = xml.getroot()
@@ -66,7 +68,7 @@ def import_properties_from_xml(xml_path, properties_from_xml=None):
value = child.find("value").text.strip() if child.find("value").text is not None else ""
properties_from_xml[name] = value
else:
- print('XML file not found at path : ' + str(xml_path))
+ log('[E] XML file not found at path : ' + str(xml_path), "error")
return properties_from_xml
def write_properties_to_xml(xml_path, property_name='', property_value=''):
@@ -105,7 +107,7 @@ def main(argv):
else:
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
globalDict=import_properties_from_xml(CFG_FILE,globalDict)
@@ -118,14 +120,15 @@ def main(argv):
PASSWORD=''
USERNAME_PROPERTY_NAME=''
FILENAME_PROPERTY_NAME=''
- if len(argv) == 4:
- ENDPOINT=argv[1]
- USERNAME=argv[2]
- PASSWORD=argv[3]
+ if len(argv) == 4:
+ ENDPOINT=argv[1]
+ USERNAME=argv[2]
+ PASSWORD=argv[3]
+
while ENDPOINT == "" or not (ENDPOINT == "ATLAS" or ENDPOINT == "RANGER"):
sys.stdout.write('Enter Destination NAME (Ranger/Atlas):')
sys.stdout.flush()
- ENDPOINT=raw_input()
+ ENDPOINT=input()
ENDPOINT = ENDPOINT.upper()
if ENDPOINT == "ATLAS":
diff --git a/unixauthservice/scripts/setup.py b/unixauthservice/scripts/setup.py
index 1dc1847..5e19ea1 100755
--- a/unixauthservice/scripts/setup.py
+++ b/unixauthservice/scripts/setup.py
@@ -14,21 +14,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+
+try:
+ from StringIO import StringIO
+except ImportError:
+ from io import StringIO
+try:
+ from ConfigParser import ConfigParser
+except ImportError:
+ from configparser import ConfigParser
+try:
+ import commands as commands
+except ImportError:
+ import subprocess as commands
+
import re
-import StringIO
import xml.etree.ElementTree as ET
-import ConfigParser
import os, sys
from os.path import isfile, join, dirname, basename
from time import strftime, localtime
import shutil
import pwd, grp
-import commands
globalDict = {}
if (not 'JAVA_HOME' in os.environ):
- print "ERROR: JAVA_HOME environment variable is not defined. Please define JAVA_HOME before running this script"
+ print("ERROR: JAVA_HOME environment variable is not defined. Please define JAVA_HOME before running this script")
sys.exit(1)
debugLevel = 1
@@ -73,7 +84,7 @@ defaultDNAME = 'cn=unixauthservice,ou=authenticator,o=mycompany,c=US'
unixUserProp = 'unix_user'
unixGroupProp = 'unix_group'
-logFolderPermMode = 0770
+logFolderPermMode = 0o770
rootOwnerId = 0
initPrefixList = ['S99', 'K00']
@@ -122,7 +133,7 @@ def initvariable():
rangerBaseDirName = ranger_base_dir
except:
info = sys.exc_info()
- print info[0], ":", info[1]
+ print(info[0], ":", info[1])
usersyncBaseDirFullName = join(rangerBaseDirName, usersyncBaseDirName)
confFolderName = join(usersyncBaseDirFullName, confBaseDirName)
@@ -134,7 +145,7 @@ def archiveFile(originalFileName):
archiveDir = dirname(originalFileName)
archiveFileName = "." + basename(originalFileName) + "." + (strftime("%d%m%Y%H%M%S", localtime()))
movedFileName = join(archiveDir, archiveFileName)
- print "INFO: moving [%s] to [%s] ......." % (originalFileName, movedFileName)
+ print("INFO: moving [%s] to [%s] ......." % (originalFileName, movedFileName))
os.rename(originalFileName, movedFileName)
@@ -161,11 +172,11 @@ def getXMLConfigMap(xmlFileName):
def getPropertiesConfigMap(configFileName):
ret = {}
- config = StringIO.StringIO()
+ config = StringIO()
config.write('[dummysection]\n')
config.write(open(configFileName).read())
config.seek(0, os.SEEK_SET)
- fcp = ConfigParser.ConfigParser()
+ fcp = ConfigParser()
fcp.optionxform = str
fcp.readfp(config)
for k, v in fcp.items('dummysection'):
@@ -175,11 +186,11 @@ def getPropertiesConfigMap(configFileName):
def getPropertiesKeyList(configFileName):
ret = []
- config = StringIO.StringIO()
+ config = StringIO()
config.write('[dummysection]\n')
config.write(open(configFileName).read())
config.seek(0, os.SEEK_SET)
- fcp = ConfigParser.ConfigParser()
+ fcp = ConfigParser()
fcp.optionxform = str
fcp.readfp(config)
for k, v in fcp.items('dummysection'):
@@ -197,7 +208,7 @@ def writeXMLUsingProperties(xmlTemplateFileName, prop, xmlOutputFileName):
if name in prop_arr:
config.find('value').text = "_"
continue
- if (name in prop.keys()):
+ if (name in list(prop)):
config.find('value').text = str(prop[name])
# else:
# print "ERROR: key not found: %s" % (name)
@@ -214,7 +225,7 @@ def updatePropertyInJCKSFile(jcksFileName, propName, value):
credUpdateClassName, propName, value, fn)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: Unable update the JCKSFile(%s) for aliasName (%s)" % (fn, propName)
+ print("ERROR: Unable update the JCKSFile(%s) for aliasName (%s)" % (fn, propName))
sys.exit(1)
return ret
@@ -222,24 +233,24 @@ def updatePropertyInJCKSFile(jcksFileName, propName, value):
def password_validation(password, userType):
if password:
if re.search("[\\\`'\"]", password):
- print "[E] " + userType + " property contains one of the unsupported special characters like \" ' \ `"
+ print("[E] " + userType + " property contains one of the unsupported special characters like \" ' \ `")
sys.exit(1)
else:
- print "[I] " + userType + " property is verified."
+ print("[I] " + userType + " property is verified.")
else:
- print "[E] Blank password is not allowed for property " + userType + ",please enter valid password."
+ print("[E] Blank password is not allowed for property " + userType + ",please enter valid password.")
sys.exit(1)
def convertInstallPropsToXML(props):
directKeyMap = getPropertiesConfigMap(join(installTemplateDirName, install2xmlMapFileName))
ret = {}
- for k, v in props.iteritems():
- if (k in directKeyMap.keys()):
+ for k, v in props.items():
+ if (k in list(directKeyMap)):
newKey = directKeyMap[k]
ret[newKey] = v
else:
- print "Direct Key not found:%s" % (k)
+ print("Direct Key not found:%s" % (k))
ret['ranger.usersync.sink.impl.class'] = 'org.apache.ranger.unixusersync.process.PolicyMgrUserGroupBuilder'
if (SYNC_SOURCE_KEY in ret):
@@ -263,14 +274,14 @@ def convertInstallPropsToXML(props):
else:
ret[SYNC_INTERVAL_NEW_KEY] = int(ret[SYNC_INTERVAL_NEW_KEY]) * 60000
else:
- print "ERROR: Invalid value (%s) defined for %s in install.properties. Only valid values are %s" % (
- syncSource, SYNC_SOURCE_KEY, SYNC_SOURCE_LIST)
+ print("ERROR: Invalid value (%s) defined for %s in install.properties. Only valid values are %s" % (
+ syncSource, SYNC_SOURCE_KEY, SYNC_SOURCE_LIST))
sys.exit(1)
ret['ranger.usersync.sync.source'] = syncSource
del ret['SYNC_SOURCE']
else:
- print "ERROR: No value defined for SYNC_SOURCE in install.properties. valid values are %s" % (
- SYNC_SOURCE_KEY, SYNC_SOURCE_LIST)
+ print("ERROR: No value defined for SYNC_SOURCE in install.properties. valid values are %s" % (
+ SYNC_SOURCE_KEY, SYNC_SOURCE_LIST))
sys.exit(1)
return ret
@@ -283,13 +294,13 @@ def createUser(username, groupname):
cmd = "useradd -g %s %s -m" % (groupname, username)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret)
+ print("ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret))
sys.exit(1)
try:
ret = pwd.getpwnam(username).pw_uid
return ret
- except KeyError, e:
- print "ERROR: Unable to create a new user account: %s with group %s - error [%s]" % (username, groupname, e)
+ except KeyError as e:
+ print("ERROR: Unable to create a new user account: %s with group %s - error [%s]" % (username, groupname, e))
sys.exit(1)
@@ -300,13 +311,13 @@ def createGroup(groupname):
cmd = "groupadd %s" % (groupname)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret)
+ print("ERROR: os command execution (%s) failed. error code = %d " % (cmd, ret))
sys.exit(1)
try:
ret = grp.getgrnam(groupname).gr_gid
return ret
- except KeyError, e:
- print "ERROR: Unable to create a new group: %s" % (groupname, e)
+ except KeyError as e:
+ print("ERROR: Unable to create a new group: %s" % (groupname, e))
sys.exit(1)
@@ -325,7 +336,7 @@ def initializeInitD(ownerName):
f = open(initdFn, 'w')
f.write(newdata)
f.close()
- os.chmod(initdFn, 0550)
+ os.chmod(initdFn, 0o550)
rcDirList = ["/etc/rc2.d", "/etc/rc3.d", "/etc/rc.d/rc2.d", "/etc/rc.d/rc3.d"]
for rcDir in rcDirList:
if (os.path.isdir(rcDir)):
@@ -348,7 +359,7 @@ def createJavaKeystoreForSSL(fn, passwd):
fn, passwd, passwd, defaultDNAME)
ret = os.system(cmd)
if (ret != 0):
- print "ERROR: unable to create JavaKeystore for SSL: file (%s)" % (fn)
+ print("ERROR: unable to create JavaKeystore for SSL: file (%s)" % (fn))
sys.exit(1)
return ret
@@ -356,7 +367,7 @@ def createJavaKeystoreForSSL(fn, passwd):
def write_env_files(exp_var_name, log_path, file_name):
final_path = "{0}/{1}".format(confBaseDirName, file_name)
if not os.path.isfile(final_path):
- print "Creating %s file" % file_name
+ print("Creating %s file" % file_name)
f = open(final_path, "w")
f.write("export {0}={1}".format(exp_var_name, log_path))
f.close()
@@ -371,22 +382,22 @@ def main():
unix_user = globalDict['unix_user']
rangerUsersync_password = globalDict['rangerUsersync_password']
- if globalDict['SYNC_SOURCE'].lower() == SYNC_SOURCE_LDAP and globalDict.has_key('ROLE_ASSIGNMENT_LIST_DELIMITER') \
- and globalDict.has_key('USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER') and globalDict.has_key('USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER'):
+ if globalDict['SYNC_SOURCE'].lower() == SYNC_SOURCE_LDAP and 'ROLE_ASSIGNMENT_LIST_DELIMITER' in globalDict \
+ and 'USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER' in globalDict and 'USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER' in globalDict:
roleAssignmentDelimiter = globalDict['ROLE_ASSIGNMENT_LIST_DELIMITER']
userGroupAssignmentDelimiter= globalDict['USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER']
userNameGroupNameAssignmentListDelimiter= globalDict['USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER'];
if roleAssignmentDelimiter != "" :
if roleAssignmentDelimiter == userGroupAssignmentDelimiter or roleAssignmentDelimiter == userNameGroupNameAssignmentListDelimiter :
- print "ERROR: All Delimiters ROLE_ASSIGNMENT_LIST_DELIMITER, USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER and USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER should be different"
+ print("ERROR: All Delimiters ROLE_ASSIGNMENT_LIST_DELIMITER, USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER and USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER should be different")
sys.exit(1)
if userGroupAssignmentDelimiter != "" :
if roleAssignmentDelimiter == userGroupAssignmentDelimiter or userGroupAssignmentDelimiter == userNameGroupNameAssignmentListDelimiter:
- print "ERROR: All Delimiters ROLE_ASSIGNMENT_LIST_DELIMITER, USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER and USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER should be different"
+ print("ERROR: All Delimiters ROLE_ASSIGNMENT_LIST_DELIMITER, USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER and USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER should be different")
sys.exit(1)
if userNameGroupNameAssignmentListDelimiter != "":
if roleAssignmentDelimiter == userNameGroupNameAssignmentListDelimiter or userGroupAssignmentDelimiter == userNameGroupNameAssignmentListDelimiter:
- print "ERROR: All Delimiters ROLE_ASSIGNMENT_LIST_DELIMITER, USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER and USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER should be different"
+ print("ERROR: All Delimiters ROLE_ASSIGNMENT_LIST_DELIMITER, USERS_GROUPS_ASSIGNMENT_LIST_DELIMITER and USERNAME_GROUPNAME_ASSIGNMENT_LIST_DELIMITER should be different")
sys.exit(1)
if pid_dir_path == "":
@@ -399,7 +410,7 @@ def main():
dirList = [rangerBaseDirName, usersyncBaseDirFullName, confFolderName, certFolderName]
for dir in dirList:
if (not os.path.isdir(dir)):
- os.makedirs(dir, 0750)
+ os.makedirs(dir, 0o750)
defFileList = [defaultSiteXMLFileName, log4jFileName]
for defFile in defFileList:
@@ -417,7 +428,7 @@ def main():
str = "export JAVA_HOME=%s\n" % os.environ['JAVA_HOME']
jhf.write(str)
jhf.close()
- os.chmod(java_home_setter_fn, 0750)
+ os.chmod(java_home_setter_fn, 0o750)
if (not os.path.isdir(localConfFolderName)):
os.symlink(confFolderName, localConfFolderName)
@@ -481,12 +492,12 @@ def main():
try:
groupId = grp.getgrnam(groupName).gr_gid
- except KeyError, e:
+ except KeyError as e:
groupId = createGroup(groupName)
try:
ownerId = pwd.getpwnam(ownerName).pw_uid
- except KeyError, e:
+ except KeyError as e:
ownerId = createUser(ownerName, groupName)
os.chown(logFolderName, ownerId, groupId)
@@ -502,7 +513,7 @@ def main():
cryptPath = mergeProps['ranger.usersync.credstore.filename']
- for keyName, aliasName in PROP2ALIASMAP.iteritems():
+ for keyName, aliasName in PROP2ALIASMAP.items():
if (keyName in mergeProps):
keyPassword = mergeProps[keyName]
updatePropertyInJCKSFile(cryptPath, aliasName, keyPassword)
@@ -533,16 +544,16 @@ def main():
os.chown(ugsyncCryptPath, ownerId, groupId)
writeXMLUsingProperties(fn, mergeProps, outfn)
-
+
hadoop_conf_full_path = join(hadoop_conf, hadoopConfFileName)
usersync_conf_full_path = join(usersyncBaseDirFullName, confBaseDirName, hadoopConfFileName)
if not isfile(hadoop_conf_full_path):
- print "WARN: core-site.xml file not found in provided hadoop conf path..."
+ print("WARN: core-site.xml file not found in provided hadoop conf path...")
f = open(usersync_conf_full_path, "w")
f.write("<configuration></configuration>")
f.close()
os.chown(usersync_conf_full_path, ownerId, groupId)
- os.chmod(usersync_conf_full_path, 0750)
+ os.chmod(usersync_conf_full_path, 0o750)
else:
if os.path.islink(usersync_conf_full_path):
os.remove(usersync_conf_full_path)
@@ -552,42 +563,42 @@ def main():
for dir in fixPermList:
for root, dirs, files in os.walk(dir):
os.chown(root, ownerId, groupId)
- os.chmod(root, 0755)
+ os.chmod(root, 0o755)
for obj in dirs:
dn = join(root, obj)
os.chown(dn, ownerId, groupId)
- os.chmod(dn, 0755)
+ os.chmod(dn, 0o755)
for obj in files:
fn = join(root, obj)
os.chown(fn, ownerId, groupId)
- os.chmod(fn, 0750)
+ os.chmod(fn, 0o750)
if isfile(nativeAuthProgramName):
os.chown(nativeAuthProgramName, rootOwnerId, groupId)
- os.chmod(nativeAuthProgramName, 0750)
+ os.chmod(nativeAuthProgramName, 0o750)
else:
- print "WARNING: Unix Authentication Program (%s) is not available for setting chmod(4550), chown(%s:%s) " % (
- nativeAuthProgramName, "root", groupName)
+ print("WARNING: Unix Authentication Program (%s) is not available for setting chmod(4550), chown(%s:%s) " % (
+ nativeAuthProgramName, "root", groupName))
if isfile(pamAuthProgramName):
os.chown(pamAuthProgramName, rootOwnerId, groupId)
- os.chmod(pamAuthProgramName, 0750)
+ os.chmod(pamAuthProgramName, 0o750)
else:
- print "WARNING: Unix Authentication Program (%s) is not available for setting chmod(4550), chown(%s:%s) " % (
- pamAuthProgramName, "root", groupName)
+ print("WARNING: Unix Authentication Program (%s) is not available for setting chmod(4550), chown(%s:%s) " % (
+ pamAuthProgramName, "root", groupName))
write_env_files("logdir", logFolderName, ENV_LOGDIR_FILE);
write_env_files("RANGER_USERSYNC_HADOOP_CONF_DIR", hadoop_conf, ENV_HADOOP_CONF_FILE);
write_env_files("USERSYNC_PID_DIR_PATH", pid_dir_path, ENV_PID_FILE);
write_env_files("USERSYNC_CONF_DIR", confFolderName, ENV_CONF_FILE);
os.chown(join(confBaseDirName, ENV_LOGDIR_FILE), ownerId, groupId)
- os.chmod(join(confBaseDirName, ENV_LOGDIR_FILE), 0755)
+ os.chmod(join(confBaseDirName, ENV_LOGDIR_FILE), 0o755)
os.chown(join(confBaseDirName, ENV_HADOOP_CONF_FILE), ownerId, groupId)
- os.chmod(join(confBaseDirName, ENV_HADOOP_CONF_FILE), 0755)
+ os.chmod(join(confBaseDirName, ENV_HADOOP_CONF_FILE), 0o755)
os.chown(join(confBaseDirName, ENV_PID_FILE), ownerId, groupId)
- os.chmod(join(confBaseDirName, ENV_PID_FILE), 0755)
+ os.chmod(join(confBaseDirName, ENV_PID_FILE), 0o755)
os.chown(join(confBaseDirName, ENV_CONF_FILE), ownerId, groupId)
- os.chmod(join(confBaseDirName, ENV_CONF_FILE), 0755)
+ os.chmod(join(confBaseDirName, ENV_CONF_FILE), 0o755)
f = open(join(confBaseDirName, ENV_PID_FILE), "a+")
f.write("\nexport {0}={1}".format("UNIX_USERSYNC_USER", unix_user))
@@ -602,8 +613,8 @@ def main():
if rangerUsersync_password != "" :
output = os.system(cmd)
if (output == 0):
- print "[I] Successfully updated password of " + rangerUsersync_name +" user"
+ print("[I] Successfully updated password of " + rangerUsersync_name +" user")
else:
- print "[ERROR] Unable to change password of " + rangerUsersync_name +" user."
+ print("[ERROR] Unable to change password of " + rangerUsersync_name +" user.")
main()
diff --git a/unixauthservice/scripts/updatepolicymgrpassword.py b/unixauthservice/scripts/updatepolicymgrpassword.py
index bd6d7dd..42d44a8 100644
--- a/unixauthservice/scripts/updatepolicymgrpassword.py
+++ b/unixauthservice/scripts/updatepolicymgrpassword.py
@@ -29,6 +29,8 @@ from os.path import basename
from subprocess import Popen,PIPE
from datetime import date
from datetime import datetime
+try: input = raw_input
+except NameError: pass
globalDict = {}
installglobalDict={}
@@ -37,12 +39,12 @@ os_name = os_name.upper()
RANGER_USERSYNC_HOME = os.getenv("RANGER_USERSYNC_HOME")
if RANGER_USERSYNC_HOME is None:
- RANGER_USERSYNC_HOME = os.getcwd()
+ RANGER_USERSYNC_HOME = os.getcwd()
def check_output(query):
if os_name == "LINUX":
p = subprocess.Popen(shlex.split(query), stdout=subprocess.PIPE)
- elif os_name == "WINDOWS":
+ elif os_name == "WINDOWS":
p = subprocess.Popen(query, stdout=subprocess.PIPE, shell=True)
output = p.communicate ()[0]
return output
@@ -116,7 +118,7 @@ def main(argv):
else:
while os.path.isfile(JAVA_BIN) == False:
log("Enter java executable path: :","info")
- JAVA_BIN=raw_input()
+ JAVA_BIN=input()
log("[I] Using Java:" + str(JAVA_BIN),"info")
globalDict=import_properties_from_xml(CFG_FILE,globalDict)
@@ -128,13 +130,13 @@ def main(argv):
unix_user = installglobalDict['unix_user']
unix_group = installglobalDict['unix_group']
- if len(argv) == 3:
- SYNC_POLICY_MGR_USERNAME=argv[1]
- SYNC_POLICY_MGR_PASSWORD=argv[2]
+ if len(argv) == 3:
+ SYNC_POLICY_MGR_USERNAME=argv[1]
+ SYNC_POLICY_MGR_PASSWORD=argv[2]
while SYNC_POLICY_MGR_USERNAME == "":
- print "Enter policymgr user name:"
- SYNC_POLICY_MGR_USERNAME=raw_input()
+ print("Enter policymgr user name:")
+ SYNC_POLICY_MGR_USERNAME=input()
while SYNC_POLICY_MGR_PASSWORD == "":
SYNC_POLICY_MGR_PASSWORD=getpass.getpass("Enter policymgr user password:")