mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Improve the ssh_known_hosts
rule import time
This commit is contained in:
parent
9fc2bc904c
commit
e5ce000399
@ -1,25 +1,19 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
patterns = [
|
|
||||||
r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!',
|
|
||||||
r'WARNING: POSSIBLE DNS SPOOFING DETECTED!',
|
|
||||||
r"Warning: the \S+ host key for '([^']+)' differs from the key for the IP address '([^']+)'",
|
|
||||||
]
|
|
||||||
offending_pattern = re.compile(
|
|
||||||
r'(?:Offending (?:key for IP|\S+ key)|Matching host key) in ([^:]+):(\d+)',
|
|
||||||
re.MULTILINE)
|
|
||||||
|
|
||||||
commands = ['ssh', 'scp']
|
|
||||||
|
|
||||||
|
|
||||||
def match(command, settings):
|
def match(command, settings):
|
||||||
if not command.script:
|
if not command.script:
|
||||||
return False
|
return False
|
||||||
if not command.script.split()[0] in commands:
|
if not command.script.startswith(('ssh', 'scp')):
|
||||||
return False
|
return False
|
||||||
if not any([re.findall(pattern, command.stderr) for pattern in patterns]):
|
|
||||||
return False
|
patterns = (
|
||||||
return True
|
r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!',
|
||||||
|
r'WARNING: POSSIBLE DNS SPOOFING DETECTED!',
|
||||||
|
r"Warning: the \S+ host key for '([^']+)' differs from the key for the IP address '([^']+)'",
|
||||||
|
)
|
||||||
|
|
||||||
|
return any(re.findall(pattern, command.stderr) for pattern in patterns)
|
||||||
|
|
||||||
|
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
@ -27,6 +21,9 @@ def get_new_command(command, settings):
|
|||||||
|
|
||||||
|
|
||||||
def side_effect(old_cmd, command, settings):
|
def side_effect(old_cmd, command, settings):
|
||||||
|
offending_pattern = re.compile(
|
||||||
|
r'(?:Offending (?:key for IP|\S+ key)|Matching host key) in ([^:]+):(\d+)',
|
||||||
|
re.MULTILINE)
|
||||||
offending = offending_pattern.findall(old_cmd.stderr)
|
offending = offending_pattern.findall(old_cmd.stderr)
|
||||||
for filepath, lineno in offending:
|
for filepath, lineno in offending:
|
||||||
with open(filepath, 'r') as fh:
|
with open(filepath, 'r') as fh:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user