Skip to content
This repository was archived by the owner on Dec 21, 2022. It is now read-only.

Commit f9eb27f

Browse files
committed
preserve CamelCase
1 parent 095627c commit f9eb27f

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

storm/parsers/ssh_config_parser.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414

1515
class StormConfig(SSHConfig):
16+
def __init__(self, *a, **kw):
17+
super(StormConfig, self).__init__(*a, **kw)
18+
self.lower_to_original = {}
19+
1620
def parse(self, file_obj):
1721
"""
1822
Read an OpenSSH config from the given file object.
@@ -49,19 +53,21 @@ def parse(self, file_obj):
4953
if line.lower().strip().startswith('proxycommand'):
5054
proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I)
5155
match = proxy_re.match(line)
52-
key, value = match.group(1).lower(), match.group(2)
56+
key, value = match.group(1), match.group(2)
5357
else:
5458
key, value = line.split('=', 1)
55-
key = key.strip().lower()
59+
key = key.strip()
5660
else:
5761
# find first whitespace, and split there
5862
i = 0
5963
while (i < len(line)) and not line[i].isspace():
6064
i += 1
6165
if i == len(line):
6266
raise Exception('Unparsable line: %r' % line)
63-
key = line[:i].lower()
67+
key = line[:i]
6468
value = line[i:].lstrip()
69+
self.lower_to_original[key.lower()] = key
70+
key = key.lower()
6571
if key == 'host':
6672
self._config.append(host)
6773
value = value.split()
@@ -92,6 +98,7 @@ def __init__(self, ssh_config_file=None):
9298
ssh_config_file = self.get_default_ssh_config_file()
9399

94100
self.defaults = {}
101+
self.lower_to_original = {}
95102

96103
self.ssh_config_file = ssh_config_file
97104

@@ -111,6 +118,7 @@ def load(self):
111118

112119
with open(self.ssh_config_file) as fd:
113120
config.parse(fd)
121+
self.lower_to_original = config.lower_to_original
114122

115123
for entry in config.__dict__.get("_config"):
116124
if entry.get("host") == ["*"]:
@@ -218,12 +226,12 @@ def dump(self):
218226
sub_content = ""
219227
for value_ in value:
220228
sub_content += " {0} {1}\n".format(
221-
key, value_
229+
self.lower_to_original.get(key) or key, value_
222230
)
223231
host_item_content += sub_content
224232
else:
225233
host_item_content += " {0} {1}\n".format(
226-
key, value
234+
self.lower_to_original.get(key) or key, value
227235
)
228236
file_content += host_item_content
229237

tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_advanced_add(self):
170170
with open(self.config_file) as f:
171171
# check that property is really flushed out to the config?
172172
content = f.read().encode('ascii')
173-
self.assertIn(b'identityfile "/tmp/idfilecheck.rsa"', content)
173+
self.assertIn(b'IdentityFile "/tmp/idfilecheck.rsa"', content)
174174
self.assertIn(b"stricthostkeychecking yes", content)
175175
self.assertIn(b"userknownhostsfile /dev/advanced_test", content)
176176

@@ -184,7 +184,7 @@ def test_add_with_idfile(self):
184184

185185
with open(self.config_file) as f:
186186
content = f.read().encode('ascii')
187-
self.assertIn(b'identityfile "/tmp/idfileonlycheck.rsa"', content)
187+
self.assertIn(b'IdentityFile "/tmp/idfileonlycheck.rsa"', content)
188188

189189
def test_basic_edit(self):
190190
out, err, rc = self.run_cmd('edit aws.apache [email protected] {0}'.format(self.config_arg))
@@ -215,8 +215,8 @@ def test_update(self):
215215

216216
with open(self.config_file) as f:
217217
content = f.read().encode('ascii')
218-
self.assertIn(b"user daghan", content) # see daghan: http://instagram.com/p/lfPMW_qVja
219-
self.assertIn(b"port 42000", content)
218+
self.assertIn(b"User daghan", content) # see daghan: http://instagram.com/p/lfPMW_qVja
219+
self.assertIn(b"Port 42000", content)
220220

221221
def test_update_regex(self):
222222

0 commit comments

Comments
 (0)