Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve ssh hostname aliases with ssh -G #84

Merged
merged 3 commits into from Nov 2, 2022
Merged

Resolve ssh hostname aliases with ssh -G #84

merged 3 commits into from Nov 2, 2022

Conversation

mislav
Copy link
Contributor

@mislav mislav commented Oct 21, 2022

Going through the ssh executable ensures that hostnames get resolved using ssh's exact mechanism and alleviates the need for manually parsing and interpreting ssh configuration files.

I learned this trick from @cmbrose in cli/cli#5958.

Ref. cli/cli#6455

Going through the `ssh` executable ensures that hostnames get resolved using ssh's exact mechanism and alleviates the need for manually parsing and interpreting ssh configuration files.
Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good. This way of resolving SSH hostname aliases is much better than before IMO. I just left one comment regarding the caching mechanism that I would like to see addressed.

Comment on lines +46 to +50
t.cacheMu.RLock()
cached, cacheFound := t.cacheMap[strings.ToLower(hostname)]
t.cacheMu.RUnlock()
if cacheFound {
return cached, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell this cache is never actually populated in this method. I am wondering about its purpose though. We can rectify this and start populating the cache or I think it would be okay to just allow the users of this package to implement the caching since our implementation is just an in-memory map. What are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. If the cache is not populated, that was an oversight on my part.

I do think that an in-memory cache would be beneficial since Translate() is typically used to translate many URLs at once: think of a git repo that has multiple SSH remotes—Translate will be called 2 times per each remote. Since most remotes will be to the same hostname, a built-in cache avoids shelling out to ssh repeatedly.

@mislav mislav enabled auto-merge (squash) November 1, 2022 19:28
@mislav mislav requested a review from samcoe November 1, 2022 19:31
Copy link
Contributor

@samcoe samcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making the requested changes!

@mislav mislav merged commit 5d098ef into trunk Nov 2, 2022
@mislav mislav deleted the ssh-resolve branch November 2, 2022 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants