mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Refactor ssh verify line to smartly parse extra options
Lines in an ssh auth key can begin like this: tunnel="1",command="sh /etc/netstart tun1" ssh-rsa Need to separate the parsing of options from the key. This patch groups the ssh auth key line into two parts, [{options}* key]
This commit is contained in:
parent
cbe04a5095
commit
2d9b2ba86b
@ -3,6 +3,7 @@ Manage client ssh components
|
||||
'''
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
|
||||
def _refine_enc(enc):
|
||||
@ -138,13 +139,16 @@ def _validate_keys(key_file):
|
||||
if line.startswith('#'):
|
||||
# Commented Line
|
||||
continue
|
||||
comps = line.split()
|
||||
ln = re.search('(.*?)\s?((?:ssh\-|ecds).+)$');
|
||||
opts = ln.group(1)
|
||||
comps = ln.group(2).split()
|
||||
|
||||
if len(comps) < 2:
|
||||
# Not a valid line
|
||||
continue
|
||||
if comps[0][:4:] not in ['ssh-', 'ecds']:
|
||||
if opts:
|
||||
# It has options, grab them
|
||||
options = comps[0].split(',')
|
||||
options = opts.split(',')
|
||||
else:
|
||||
options = []
|
||||
if not options:
|
||||
@ -194,14 +198,17 @@ def rm_auth_key(user, key, config='.ssh/authorized_keys'):
|
||||
# Commented Line
|
||||
lines.append(line)
|
||||
continue
|
||||
comps = line.split()
|
||||
ln = re.search('(.*?)\s?((?:ssh\-|ecds).+)$');
|
||||
opts = ln.group(1)
|
||||
comps = ln.group(2).split()
|
||||
|
||||
if len(comps) < 2:
|
||||
# Not a valid line
|
||||
lines.append(line)
|
||||
continue
|
||||
if comps[0][:4:] not in ['ssh-', 'ecds']:
|
||||
if opts:
|
||||
# It has options, grab them
|
||||
options = comps[0].split(',')
|
||||
options = opts.split(',')
|
||||
else:
|
||||
options = []
|
||||
if not options:
|
||||
|
Loading…
Reference in New Issue
Block a user