def save_passwd_for_alias(alias, passwd, masterKey=""): if alias and passwd: jdk_path = find_jdk() if jdk_path is None: print_error_msg( "No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 if masterKey is None or masterKey == "": masterKey = "None" serverClassPath = ambari_server.serverClassPath.ServerClassPath( get_ambari_properties(), None) command = SECURITY_PROVIDER_PUT_CMD.format( get_java_exe_path(), serverClassPath.get_full_ambari_classpath_escaped_for_shell(), alias, passwd, masterKey) (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from credential provider save passwd: " + str(retcode)) return retcode else: print_error_msg("Alias or password is unreadable.")
def save_passwd_for_alias(alias, passwd, masterKey=""): if alias and passwd: jdk_path = find_jdk() if jdk_path is None: print_error_msg("No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 if masterKey is None or masterKey == "": masterKey = "None" serverClassPath = ambari_server.serverClassPath.ServerClassPath(get_ambari_properties(), None) command = SECURITY_PROVIDER_PUT_CMD.format(get_java_exe_path(), serverClassPath.get_full_ambari_classpath_escaped_for_shell(), alias, passwd, masterKey) (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from credential provider save passwd: " + str(retcode)) return retcode else: print_error_msg("Alias or password is unreadable.")
def read_passwd_for_alias(alias, masterKey=""): if alias: jdk_path = find_jdk() if jdk_path is None: print_error_msg( "No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 tempFileName = "ambari.passwd" passwd = "" tempDir = tempfile.gettempdir() #create temporary file for writing tempFilePath = tempDir + os.sep + tempFileName file = open(tempFilePath, 'w+') os.chmod(tempFilePath, stat.S_IREAD | stat.S_IWRITE) file.close() if masterKey is None or masterKey == "": masterKey = "None" serverClassPath = ambari_server.serverClassPath.ServerClassPath( get_ambari_properties(), None) command = SECURITY_PROVIDER_GET_CMD.format( get_java_exe_path(), serverClassPath.get_full_ambari_classpath_escaped_for_shell(), alias, tempFilePath, masterKey) (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from credential provider get passwd: " + str(retcode)) if retcode != 0: print 'ERROR: Unable to read password from store. alias = ' + alias else: passwd = open(tempFilePath, 'r').read() # Remove temporary file os.remove(tempFilePath) return passwd else: print_error_msg("Alias is unreadable.")
def read_passwd_for_alias(alias, masterKey=""): if alias: jdk_path = find_jdk() if jdk_path is None: print_error_msg("No JDK found, please run the \"setup\" " "command to install a JDK automatically or install any " "JDK manually to " + configDefaults.JDK_INSTALL_DIR) return 1 tempFileName = "ambari.passwd" passwd = "" tempDir = tempfile.gettempdir() #create temporary file for writing tempFilePath = tempDir + os.sep + tempFileName file = open(tempFilePath, 'w+') os.chmod(tempFilePath, stat.S_IREAD | stat.S_IWRITE) file.close() if masterKey is None or masterKey == "": masterKey = "None" serverClassPath = ambari_server.serverClassPath.ServerClassPath(get_ambari_properties(), None) command = SECURITY_PROVIDER_GET_CMD.format(get_java_exe_path(), serverClassPath.get_full_ambari_classpath_escaped_for_shell(), alias, tempFilePath, masterKey) (retcode, stdout, stderr) = run_os_command(command) print_info_msg("Return code from credential provider get passwd: " + str(retcode)) if retcode != 0: print 'ERROR: Unable to read password from store. alias = ' + alias else: passwd = open(tempFilePath, 'r').read() # Remove temporary file os.remove(tempFilePath) return passwd else: print_error_msg("Alias is unreadable.")