Skip to content

Commit

Permalink
Add support for setting and matching tags in SSH config file
Browse files Browse the repository at this point in the history
  • Loading branch information
ronf committed Jan 19, 2024
1 parent 2d99f8e commit 88e87eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions asyncssh/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def _match_val(self, match: str) -> object:
return self._local_user
elif match == 'user':
return self._options.get('User', self._local_user)
elif match == 'tagged':
return self._options.get('Tag', '')
else:
return None

Expand Down Expand Up @@ -561,6 +563,7 @@ def _set_tokens(self) -> None:
('ServerAliveCountMax', SSHConfig._set_int),
('ServerAliveInterval', SSHConfig._set_int),
('SetEnv', SSHConfig._append_string_list),
('Tag', SSHConfig._set_string),
('TCPKeepAlive', SSHConfig._set_bool),
('User', SSHConfig._set_string),
('UserKnownHostsFile', SSHConfig._set_string_list)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@ def test_set_and_match_user(self):
self.assertEqual(config.get('BindAddress'), 'addr')
self.assertEqual(config.get('Port'), 2222)

def test_tag(self):
"""Test setting and matching a tag"""

config = self._parse_config('Tag tag2\n'
'Match tagged tag1\n'
' Port 1111\n'
'Match tagged tag*\n'
' Port 2222')

self.assertEqual(config.get('Port'), 2222)

def test_port_already_set(self):
"""Test that port is ignored if set outside of the config"""

Expand Down

0 comments on commit 88e87eb

Please sign in to comment.