Fix and improve get_hostnames() for configs with Match directives#1991
Open
phil-blain wants to merge 3 commits intoparamiko:mainfrom
Open
Fix and improve get_hostnames() for configs with Match directives#1991phil-blain wants to merge 3 commits intoparamiko:mainfrom
get_hostnames() for configs with Match directives#1991phil-blain wants to merge 3 commits intoparamiko:mainfrom
Conversation
SSHConfig.get_hostnames() is unprepared to be called for configs with 'Match' directives, as this function expects every entry in the config to have a "host" key, which is not the case when the config contains "Match" directives. Improve the function by checking for "matches" entries, and additionnally check if the condition of the 'Match' directive is "host", in which case add the listed hosts to the set of hosts returned.
'ssh_config' specifies keywords are case-insensitive, and their value case-sensitive. The 'Match' criteria (all, host, canonical, etc.) are listed as lowercase but are actually also accepted when capitalized by OpenSSH (maybe because they are labelled criteria "keywords"?). Be lenient and allow them to be capitalized by making sure to lowercase them when we read the config. Capitalize one keyword in a test config for good measure.
Mark Python files as such with the 'diff' Git attribute [1]. This allows
various Git commands (diff, grep, log, blame) to show in which function
changes are located, i.e. the previous commit would be shown as
diff --git a/paramiko/config.py b/paramiko/config.py
index a8891c8..517bce4 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -520,7 +520,7 @@ def _get_matches(self, match):
if type_.startswith("!"):
match["negate"] = True
type_ = type_[1:]
- match["type"] = type_
+ match["type"] = type_.lower()
# all/canonical have no params (everything else does)
if type_ in ("all", "canonical"):
matches.append(match)
Notice how the hunk header indicates the changes are in '_get_matches'.
[1] https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix and improve 'get_hostnames()' for configs with 'Match' directives
SSHConfig.get_hostnames() is unprepared to be called for configs with
'Match' directives, as this function expects every entry in the config
to have a "host" key, which is not the case when the config contains
"Match" directives.
Improve the function by checking for "matches" entries, and
additionnally check if the condition of the 'Match' directive is "host",
in which case add the listed hosts to the set of hosts returned.
Additionnally:
Matchconditions.gitattributesfile for Python-aware Git diffs and suchThis should supersede #1674.