|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class StormConfig(SSHConfig): |
| 16 | + def __init__(self, *a, **kw): |
| 17 | + super(StormConfig, self).__init__(*a, **kw) |
| 18 | + self.lower_to_original = {} |
| 19 | + |
16 | 20 | def parse(self, file_obj): |
17 | 21 | """ |
18 | 22 | Read an OpenSSH config from the given file object. |
@@ -49,19 +53,21 @@ def parse(self, file_obj): |
49 | 53 | if line.lower().strip().startswith('proxycommand'): |
50 | 54 | proxy_re = re.compile(r"^(proxycommand)\s*=*\s*(.*)", re.I) |
51 | 55 | match = proxy_re.match(line) |
52 | | - key, value = match.group(1).lower(), match.group(2) |
| 56 | + key, value = match.group(1), match.group(2) |
53 | 57 | else: |
54 | 58 | key, value = line.split('=', 1) |
55 | | - key = key.strip().lower() |
| 59 | + key = key.strip() |
56 | 60 | else: |
57 | 61 | # find first whitespace, and split there |
58 | 62 | i = 0 |
59 | 63 | while (i < len(line)) and not line[i].isspace(): |
60 | 64 | i += 1 |
61 | 65 | if i == len(line): |
62 | 66 | raise Exception('Unparsable line: %r' % line) |
63 | | - key = line[:i].lower() |
| 67 | + key = line[:i] |
64 | 68 | value = line[i:].lstrip() |
| 69 | + self.lower_to_original[key.lower()] = key |
| 70 | + key = key.lower() |
65 | 71 | if key == 'host': |
66 | 72 | self._config.append(host) |
67 | 73 | value = value.split() |
@@ -111,6 +117,7 @@ def load(self): |
111 | 117 |
|
112 | 118 | with open(self.ssh_config_file) as fd: |
113 | 119 | config.parse(fd) |
| 120 | + self.lower_to_original = config.lower_to_original |
114 | 121 |
|
115 | 122 | for entry in config.__dict__.get("_config"): |
116 | 123 | if entry.get("host") == ["*"]: |
@@ -218,12 +225,12 @@ def dump(self): |
218 | 225 | sub_content = "" |
219 | 226 | for value_ in value: |
220 | 227 | sub_content += " {0} {1}\n".format( |
221 | | - key, value_ |
| 228 | + self.lower_to_original.get(key) or key, value_ |
222 | 229 | ) |
223 | 230 | host_item_content += sub_content |
224 | 231 | else: |
225 | 232 | host_item_content += " {0} {1}\n".format( |
226 | | - key, value |
| 233 | + self.lower_to_original.get(key) or key, value |
227 | 234 | ) |
228 | 235 | file_content += host_item_content |
229 | 236 |
|
|
0 commit comments