Skip to content

Commit

Permalink
bugfix for when an entry is added with a hostname that is a substring…
Browse files Browse the repository at this point in the history
… of an existing entry's hostname, the former is not added because storm thinks it exists already
  • Loading branch information
jeunito committed Apr 29, 2014
1 parent 7e681ba commit 42fa6ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions storm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def edit_entry(self, name, host, user, port, id_file, custom_options=[]):
return True

def update_entry(self, name, **kwargs):
if not self.is_host_in(name):
if not self.is_host_in(name, regexp_match = True):
raise StormValueError('{0} doesn\'t exists in your sshconfig. use storm add command to add.'.format(name))

self.ssh_config.update_host(name, kwargs)
Expand Down Expand Up @@ -113,9 +113,9 @@ def get_options(self, host, user, port, id_file, custom_options):

return options

def is_host_in(self, host):
def is_host_in(self, host, regexp_match = False):
import re
for host_ in self.ssh_config.config_data:
if host_.get("host") == host or re.match(host, host_.get("host")):
if host_.get("host") == host or (regexp_match and re.match(host, host_.get("host"))):
return True
return False
3 changes: 2 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ def test_update_host(self):

def test_add_host(self):
self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub')
self.storm.add_entry('goog', 'google.com', 'root', '22', '/tmp/tmp.pub')
self.storm.ssh_config.write_to_ssh_config()

for item in self.storm.ssh_config.config_data:
if item.get("host") == 'google':
if item.get("host") == 'google' or item.get("host") == 'goog':
self.assertEqual(item.get("options").get("port"), '22')
self.assertEqual(item.get("options").get("identityfile"), '/tmp/tmp.pub')

Expand Down

0 comments on commit 42fa6ea

Please sign in to comment.