From b13fa0d408224b818544de9f1d2dd9fd0823cda2 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Wed, 3 Apr 2019 06:49:43 +1000 Subject: [PATCH] Ansible.Basic - event log perm fix and no_log improv (#54699) * Ansible.Basic - event log perm fix and no_log improv * Still log other failures --- .../module_utils/csharp/Ansible.Basic.cs | 13 ++++++++-- .../library/ansible_basic_tests.ps1 | 26 +++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/ansible/module_utils/csharp/Ansible.Basic.cs b/lib/ansible/module_utils/csharp/Ansible.Basic.cs index b570a05dbad..a67f67fb369 100644 --- a/lib/ansible/module_utils/csharp/Ansible.Basic.cs +++ b/lib/ansible/module_utils/csharp/Ansible.Basic.cs @@ -315,7 +315,16 @@ namespace Ansible.Basic using (EventLog eventLog = new EventLog("Application")) { eventLog.Source = logSource; - eventLog.WriteEntry(message, logEntryType, 0); + try + { + eventLog.WriteEntry(message, logEntryType, 0); + } + catch (System.InvalidOperationException) { } // Ignore permission errors on the Application event log + catch (System.Exception e) + { + // Cannot call Warn as that calls LogEvent and we get stuck in a loop + warnings.Add(String.Format("Unknown error when creating event log entry: {0}", e.Message)); + } } } @@ -1249,7 +1258,7 @@ namespace Ansible.Basic return "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"; foreach (string omitMe in noLogStrings) if (stringValue.Contains(omitMe)) - return (stringValue).Replace(omitMe, new String('*', omitMe.Length)); + return (stringValue).Replace(omitMe, "********"); value = stringValue; } return value; diff --git a/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 b/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 index 15d15b20794..81a0156dd0c 100644 --- a/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 +++ b/test/integration/targets/win_csharp_utils/library/ansible_basic_tests.ps1 @@ -657,25 +657,25 @@ $tests = @{ dict = @{ pass = "plain" hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" - sub_hide = "****word" + sub_hide = "********word" int_hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } custom = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" list = @( "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", - "****word", + "********word", "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "pa ss", @{ pass = "plain" hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" - sub_hide = "****word" + sub_hide = "********word" int_hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } ) - data = "Oops this is secret: ****" + data = "Oops this is secret: ********" } - username = "user - **** - name" + username = "user - ******** - name" password = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER" } } @@ -686,21 +686,21 @@ $tests = @{ $expected_event = @' test_no_log - Invoked with: - username: user - **** - name + username: user - ******** - name dict: dict: sub_hide: ****word pass: plain - int_hide: ****56 + int_hide: ********56 hide: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER - data: Oops this is secret: **** + data: Oops this is secret: ******** custom: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER list: - VALUE_SPECIFIED_IN_NO_LOG_PARAMETER - - ****word - - ****567 + - ********word + - ********567 - pa ss - - sub_hide: ****word + - sub_hide: ********word pass: plain - int_hide: ****56 + int_hide: ********56 hide: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER password2: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER password: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER @@ -1898,7 +1898,7 @@ test_no_log - Invoked with: } $failed | Assert-Equals -Expected $true - $expected_msg = "value of option_key must be one of: a, b. Got no match for: ***" + $expected_msg = "value of option_key must be one of: a, b. Got no match for: ********" $actual.Keys.Count | Assert-Equals -Expected 4 $actual.changed | Assert-Equals -Expected $false