Repository navigation
Speed up loading of HostKeys - #2254
jack-stanek-hpe wants to merge 1 commit into
Conversation
bskinn
left a comment
There was a problem hiding this comment.
Handful of questions/change requests.
Also, this should be pretty easy to add/augment tests for.
And, this will definitely need a CHANGELOG entry in /sites/www/changelog.rst.
Thanks for the PR!
| return self._hashed_entries | ||
| return self._entries[hostname] |
There was a problem hiding this comment.
Why does this return the entirety of self._hashed_entries when hostname is hashed, instead of a specific subset of _hashed_entries related to hostname?
As opposed to the non-hashed case, where you do return a subset, per self._entries[hostname].
Is it because when things are hashed they are lumped into ._hashed_entries in a way that they can't be separated out by the hostname they relate to?
Adding a comment here on why this works this way would be good.
Additionally, I think you should edit into the HostKeys class docstring some of the description in the long paragraph of your #2251 (comment), to explain the paradigm of how the data is handled/stored.
That would then provide context for inline code comments here and elsewhere.
I'm guessing the class docstring will also need a stub .. versionchanged:: x.y directive added, since this is a substantial change in implementation. bitprophet would update to the correct version if/when he merges.
| """ | ||
|
|
||
| def __init__(self, hostnames=None, key=None): | ||
| def __init__(self, hostnames=None, key=None, lineno=None): |
There was a problem hiding this comment.
Need to document this addition of a lineno parameter, probably in the HostKeyEntry class docstring: What is it for? What is the meaning of the default value of None? Etc.
lineno will also need a .. versionadded:: x.y stub for bitprophet to complete.
Also, with this addition of lineno to the HostKeyEntry class, what's to stop a user from adding an entry programmatically and specifying lineno when they do so? Seems like this would inject the programmatic entry into the middle of the list of entries when exported with save().
Now -- that could be a useful feature! But it needs to be thought about; and, if determined to be desirable, documented and its implications thought through.
This class could also in general use better documentation -- what are the types of hostnames and key. hostnames looks like a list of str; I don't know the guts of paramiko well enough to know for sure what type key should be.... based on some of the code above, looks like a PKey?
|
|
||
| entries = [] | ||
| for e in self._entries: | ||
| for e in chain(self._entries[hostname], self._hashed_entries): |
There was a problem hiding this comment.
| for e in chain(self._entries[hostname], self._hashed_entries): | |
| # We have to search for both hashed and unhashed entries | |
| for e in chain(self._entries[hostname], self._hashed_entries): |
| with open(filename, "w") as f: | ||
| for e in self._entries: | ||
| line = e.to_line() | ||
| all_entries = set(chain(*self._entries.values(), self._hashed_entries)) |
There was a problem hiding this comment.
Is there some risk of loss of information here? E.g., a collision between an otherwise identical hashed and unhashed value (this might not be possible); or, duplicate entries for a hostname (this might also not be possible)?
I think there's not any concern here, but my grip on the data structures is still a bit hazy so I want to raise the question.
|
Also, looks like the CI errors were due to formatting issues. Blacken and those should go away. |
Use a
dictto handle non-hashed keys in theknown_hostsfile to speed up loading and access. Addresses #2251.