Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 67B64184D6 for ; Wed, 23 Dec 2015 15:07:18 +0000 (UTC) Received: (qmail 37984 invoked by uid 500); 23 Dec 2015 15:06:42 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 37907 invoked by uid 500); 23 Dec 2015 15:06:41 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 36974 invoked by uid 99); 23 Dec 2015 15:06:41 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Dec 2015 15:06:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8184CE0ADA; Wed, 23 Dec 2015 15:06:41 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ncole@apache.org To: commits@ambari.apache.org Date: Wed, 23 Dec 2015 15:07:28 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [49/51] [abbrv] ambari git commit: AMBARI-14486. When command which use password fail, password is exposed (aonishuk) AMBARI-14486. When command which use password fail, password is exposed (aonishuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c9981170 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c9981170 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c9981170 Branch: refs/heads/branch-dev-patch-upgrade Commit: c9981170a04fa80f23c8a71a11a2dab2f6a45805 Parents: a69a544 Author: Andrew Onishuk Authored: Wed Dec 23 16:55:30 2015 +0200 Committer: Andrew Onishuk Committed: Wed Dec 23 16:55:30 2015 +0200 ---------------------------------------------------------------------- .../python/resource_management/core/base.py | 7 +---- .../python/resource_management/core/logger.py | 29 ++++++++++++++++++++ .../python/resource_management/core/shell.py | 16 ++++++----- 3 files changed, 39 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/c9981170/ambari-common/src/main/python/resource_management/core/base.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/resource_management/core/base.py b/ambari-common/src/main/python/resource_management/core/base.py index b8e07d3..1500e1f 100644 --- a/ambari-common/src/main/python/resource_management/core/base.py +++ b/ambari-common/src/main/python/resource_management/core/base.py @@ -161,12 +161,7 @@ class Resource(object): return unicode(self) def __unicode__(self): - if isinstance(self.name, basestring) and not isinstance(self.name, PasswordString): - name = "'" + self.name + "'" # print string cutely not with repr - else: - name = repr(self.name) - - return u"%s[%s]" % (self.__class__.__name__, name) + return u"%s[%s]" % (self.__class__.__name__, Logger._get_resource_name_repr(self.name)) def __getstate__(self): return dict( http://git-wip-us.apache.org/repos/asf/ambari/blob/c9981170/ambari-common/src/main/python/resource_management/core/logger.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/resource_management/core/logger.py b/ambari-common/src/main/python/resource_management/core/logger.py index f126f1e..fd05b02 100644 --- a/ambari-common/src/main/python/resource_management/core/logger.py +++ b/ambari-common/src/main/python/resource_management/core/logger.py @@ -106,6 +106,35 @@ class Logger: return Logger.get_function_repr(repr(resource), resource.arguments, resource) @staticmethod + def _get_resource_name_repr(name): + if isinstance(name, basestring) and not isinstance(name, PasswordString): + name = "'" + name + "'" # print string cutely not with repr + else: + name = repr(name) + + return name + + @staticmethod + def format_command_for_output(command): + """ + Format command to be output by replacing the PasswordStrings. + """ + if isinstance(command, (list, tuple)): + result = [] + for x in command: + if isinstance(x, PasswordString): + result.append(repr(x).strip("'")) # string '' + else: + result.append(x) + else: + if isinstance(command, PasswordString): + result = repr(command).strip("'") # string '' + else: + result = command + + return result + + @staticmethod def get_function_repr(name, arguments, resource=None): logger_level = logging._levelNames[Logger.logger.level] http://git-wip-us.apache.org/repos/asf/ambari/blob/c9981170/ambari-common/src/main/python/resource_management/core/shell.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/resource_management/core/shell.py b/ambari-common/src/main/python/resource_management/core/shell.py index 14d65c2..5acbda9 100644 --- a/ambari-common/src/main/python/resource_management/core/shell.py +++ b/ambari-common/src/main/python/resource_management/core/shell.py @@ -38,7 +38,7 @@ from resource_management.core.logger import Logger from ambari_commons.constants import AMBARI_SUDO_BINARY # use quiet=True calls from this folder (logs get too messy duplicating the resources with its commands) -RMF_FOLDER = 'resource_management/' +NOT_LOGGED_FOLDER = 'resource_management/core' EXPORT_PLACEHOLDER = "[RMF_EXPORT_PLACEHOLDER]" ENV_PLACEHOLDER = "[RMF_ENV_PLACEHOLDER]" @@ -52,11 +52,11 @@ def log_function_call(function): caller_filename = sys._getframe(1).f_code.co_filename # quiet = can be False/True or None -- which means undefined yet quiet = kwargs['quiet'] if 'quiet' in kwargs else None - is_internal_call = RMF_FOLDER in caller_filename + is_internal_call = NOT_LOGGED_FOLDER in caller_filename if quiet == False or (quiet == None and not is_internal_call): - command_alias = string_cmd_from_args_list(command) if isinstance(command, (list, tuple)) else command - log_msg = Logger.get_function_repr("{0}['{1}']".format(function.__name__, command_alias), kwargs) + command_repr = Logger._get_resource_name_repr(command) + log_msg = Logger.get_function_repr("{0}[{1}]".format(function.__name__, command_repr), kwargs) Logger.info(log_msg) # logoutput=False - never log @@ -171,7 +171,8 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE {int fd} - redirect to file with descriptor. {string filename} - redirects to a file with name. """ - command_alias = string_cmd_from_args_list(command) if isinstance(command, (list, tuple)) else command + command_alias = Logger.format_command_for_output(command) + command_alias = string_cmd_from_args_list(command_alias) if isinstance(command_alias, (list, tuple)) else command_alias # Append current PATH to env['PATH'] env = _add_current_path_to_env(env) @@ -266,7 +267,8 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE _print(line) # Wait for process to terminate - proc.wait() + if not timeout or not timeout_event.is_set(): + proc.wait() finally: for fp in files_to_close: @@ -281,7 +283,7 @@ def _call(command, logoutput=None, throw_on_failure=True, stdout=subprocess.PIPE t.cancel() # timeout occurred else: - err_msg = ("Execution of '%s' was killed due timeout after %d seconds") % (command, timeout) + err_msg = Logger.filter_text(("Execution of '%s' was killed due timeout after %d seconds") % (command_alias, timeout)) raise ExecuteTimeoutException(err_msg) code = proc.returncode