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

Commit a6a5f8e

Browse files
committed
preserve CamelCase
1 parent 095627c commit a6a5f8e

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

storm/parsers/ssh_config_parser.py

Lines changed: 12 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()
@@ -111,6 +117,7 @@ def load(self):
111117

112118
with open(self.ssh_config_file) as fd:
113119
config.parse(fd)
120+
self.lower_to_original = config.lower_to_original
114121

115122
for entry in config.__dict__.get("_config"):
116123
if entry.get("host") == ["*"]:
@@ -218,12 +225,12 @@ def dump(self):
218225
sub_content = ""
219226
for value_ in value:
220227
sub_content += " {0} {1}\n".format(
221-
key, value_
228+
self.lower_to_original.get(key) or key, value_
222229
)
223230
host_item_content += sub_content
224231
else:
225232
host_item_content += " {0} {1}\n".format(
226-
key, value
233+
self.lower_to_original.get(key) or key, value
227234
)
228235
file_content += host_item_content
229236

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)