Added support for parsing 'Include' directive in ssh config file.#872
Added support for parsing 'Include' directive in ssh config file.#872FDT2k wants to merge 3 commits intoparamiko:mainfrom
Conversation
3 similar comments
paramiko/config.py
Outdated
| self._config = [] | ||
|
|
||
| def parse(self, file_obj): | ||
| def parse(self, file_obj,parsed_files=None): |
There was a problem hiding this comment.
style nit: space after comma
paramiko/config.py
Outdated
|
|
||
| path = value | ||
| # according to SSH documentation if the path is relative, we look forward in ~/.ssh | ||
| if path[0] != '/' and path[0]!='~': |
There was a problem hiding this comment.
style nit: spaces around !=
There was a problem hiding this comment.
you may want to use os.path.isabs() for the first part of this condition, to perhaps enable better compatibility with windows
paramiko/config.py
Outdated
| raise Exception("Include loop detected in ssh config file: %s" %path) | ||
| with open(filename) as fd: | ||
| parsed_files.append(path); | ||
| self.parse(fd,parsed_files) |
There was a problem hiding this comment.
more minor style nits - space after comma, no semicolon at end of the previous line, spaces around % three lines up
|
Overall looks good to me. |
|
Worth documenting here that this is a new feature in ssh 7.3p1, and this PR does seem to reproduce it pretty closely. |
| for filename in glob.iglob(path): | ||
| if os.path.isfile(filename): | ||
| if filename in parsed_files: | ||
| raise Exception("Include loop detected in ssh config file: %s" % filename) |
There was a problem hiding this comment.
This should be some more specific exception class, using just Exception is almost never useful (it's impossible to catch without catching everything else too!); not sure what works best though. Maybe ValueError, or a new custom exception class (meh).
|
This is a comparatively easy part of the code to test so I'd love it if tests could be added. |
|
Was gonna drop this as a line comment but not sure I trust github to display it even after the code is modified, and it got complex enough to be a permanent part of the discussion. It's re: the treatment of the file path stuff on line 87: That's not how I'd interpreting the current OpenSSH docs...it's just stating that it allows normal shell-like globbing and user home directory references (e.g. What they mean by "assuming
Also, that brings up another wrinkle, namely the detection of whether the current file being parsed is a "user" or "system" configuration file (and they do not even mention how it is expected to behave if it is a runtime-specified file...). Need to think about that, I could see a few different ways to handle it:
|
|
I think the relative locations handling here is correct. My ssh config uses I tried adding |
|
I would be happy to help out by adding some unit testing here, but it does not seem as straight forward to add the tests as it is for the other config tests. I would either need to add mock as a requirement to the project, or drop some test config files into the repo to be able to parse finding and reading the actual files (although I would not be able to test ~ this way). Do you have a preference on those two options, or a better option I didn't think of? |
|
This PR makes me super happy!! I'd love to see this get merged in the nearish future and I'm happy to help contribute some tests if @FDT2k would be amenable to PRs against this PR :-) It seems like the work that needs doing here is:
|
|
@bitprophet @ploxiln looks like both @tescalada and I are willing to help get this PR over the finish 🏆 I just wanted to say thanks for maintaining this awesome project and all the love and attention you've put into this. Whenever you all have a minute, we'd love to get your two cents on the items @tescalada and I asked about. Thanks again!!! |
|
This doesn't support globs, such as this:
This leads to |
|
How about a merge ? 🙏 |
|
Any update on this PR? |
|
Rebased against current master, works fine.
Original author @FDT2k implementation is correct : I compared file expansion with native openssh client on Debian stable.
Good catch, please see #1194.
I cannot reproduce your issue : importing patterns with wildcards patterns work fine here. It seems you are trying to import a file multiple times. (see 9d183fe#diff-a58d9daf5b4cbdffb4dee739593a7813R101) |
|
How about a merge ? 🙏 |
|
@FDT2k this is such a useful feature. Would you mind working in the one comment of the review. |
|
i cleaned this up and added a test (#1892) |
|
this PR should be closed in favor of #1892. |
|
Yup, rolling into #1892 |
Just added support for parsing the Include directive in ssh config file.