1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-21 01:59:10 +00:00
thefuck/thefuck/rules/ssh_known_hosts.py
2015-08-19 11:00:27 +02:00

37 lines
1.0 KiB
Python

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):
if not command.script:
return False
if not command.script.split()[0] in commands:
return False
if not any([re.findall(pattern, command.stderr) for pattern in patterns]):
return False
return True
def get_new_command(command, settings):
return command.script
def side_effect(old_cmd, command, settings):
offending = offending_pattern.findall(old_cmd.stderr)
for filepath, lineno in offending:
with open(filepath, 'r') as fh:
lines = fh.readlines()
del lines[int(lineno) - 1]
with open(filepath, 'w') as fh:
fh.writelines(lines)