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
This commit is contained in:
parent
064d89a850
commit
b13fa0d408
2 changed files with 24 additions and 15 deletions
|
@ -315,7 +315,16 @@ namespace Ansible.Basic
|
||||||
using (EventLog eventLog = new EventLog("Application"))
|
using (EventLog eventLog = new EventLog("Application"))
|
||||||
{
|
{
|
||||||
eventLog.Source = logSource;
|
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";
|
return "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER";
|
||||||
foreach (string omitMe in noLogStrings)
|
foreach (string omitMe in noLogStrings)
|
||||||
if (stringValue.Contains(omitMe))
|
if (stringValue.Contains(omitMe))
|
||||||
return (stringValue).Replace(omitMe, new String('*', omitMe.Length));
|
return (stringValue).Replace(omitMe, "********");
|
||||||
value = stringValue;
|
value = stringValue;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -657,25 +657,25 @@ $tests = @{
|
||||||
dict = @{
|
dict = @{
|
||||||
pass = "plain"
|
pass = "plain"
|
||||||
hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
||||||
sub_hide = "****word"
|
sub_hide = "********word"
|
||||||
int_hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
int_hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
||||||
}
|
}
|
||||||
custom = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
custom = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
||||||
list = @(
|
list = @(
|
||||||
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
|
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
|
||||||
"****word",
|
"********word",
|
||||||
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
|
"VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
|
||||||
"pa ss",
|
"pa ss",
|
||||||
@{
|
@{
|
||||||
pass = "plain"
|
pass = "plain"
|
||||||
hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
||||||
sub_hide = "****word"
|
sub_hide = "********word"
|
||||||
int_hide = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
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"
|
password = "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -686,21 +686,21 @@ $tests = @{
|
||||||
|
|
||||||
$expected_event = @'
|
$expected_event = @'
|
||||||
test_no_log - Invoked with:
|
test_no_log - Invoked with:
|
||||||
username: user - **** - name
|
username: user - ******** - name
|
||||||
dict: dict: sub_hide: ****word
|
dict: dict: sub_hide: ****word
|
||||||
pass: plain
|
pass: plain
|
||||||
int_hide: ****56
|
int_hide: ********56
|
||||||
hide: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
hide: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
||||||
data: Oops this is secret: ****
|
data: Oops this is secret: ********
|
||||||
custom: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
custom: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
||||||
list:
|
list:
|
||||||
- VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
- VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
||||||
- ****word
|
- ********word
|
||||||
- ****567
|
- ********567
|
||||||
- pa ss
|
- pa ss
|
||||||
- sub_hide: ****word
|
- sub_hide: ********word
|
||||||
pass: plain
|
pass: plain
|
||||||
int_hide: ****56
|
int_hide: ********56
|
||||||
hide: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
hide: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
||||||
password2: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
password2: VALUE_SPECIFIED_IN_NO_LOG_PARAMETER
|
||||||
password: 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
|
$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.Keys.Count | Assert-Equals -Expected 4
|
||||||
$actual.changed | Assert-Equals -Expected $false
|
$actual.changed | Assert-Equals -Expected $false
|
||||||
|
|
Loading…
Reference in a new issue