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

[DRAFT] Improve SSH URL parsing and reporting #4975

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

chrisd8088
Copy link
Contributor

@chrisd8088 chrisd8088 commented Apr 28, 2022

Work in Progress

TODO: improve parsing of bare [...:port] format

check on terminology

check on relative paths in bare format

Git LFS supports both "bare" SSH URLs, of the form user@host:path, and SSH URIs of the form ssh://user@host/path, when parsing its configuration fields. However, we do not at present retain any record of this difference, and so we are not able to reconstruct the original input when reporting SSH endpoints in the git lfs env command.

We also do not report a non-default SSH port, if one was configured, in the output from that command, leading to confusion when the input configuration was a URI like ssh://example.com:1337/path and we report it as example.com:/path, which looks like we have dropped the port entirely.

We therefore add a URIFormat member to our SSHMetadata structure and set this true only when parsing an SSH URI with a ssh:// scheme. We also add a URLFromMetadata() helper function in our ssh package which the git lfs env command can now use to format SSH metadata to match its original input format, including any non-default port number.

As well, we revise one change which was introduced in commit a0190a6 of PR #4446, whereby the lfshttp.EndpointFromBareSshUrl() function always strips off the leading path separator. The code actually only performs this action if the path returned by EndpointFromSshUrl() begins with a slash character, but since that function expects an SSH URI and we construct one as its argument, it will always return an absolute path with a leading separator, and so we always strip that off.

Instead, we now detect whether the configured path in the bare SSH URL is an absolute or relative one before we generate a temporary URI to pass to EndpointFromSshUrl(). We can then remove the leading slash always returned by that function if the original input had a relative path and not otherwise.

We also expand an existing test in the t/t-env.sh file so as to confirm that our changes work as expected with a variety of bare SSH URLs.

Intended to resolve #5184.

@chrisd8088 chrisd8088 added the wip label Apr 28, 2022
@chrisd8088 chrisd8088 requested a review from a team as a code owner April 28, 2022 08:31
@chrisd8088 chrisd8088 marked this pull request as draft November 13, 2022 09:00
Git LFS supports both "bare" SSH URLs, of the form "user@host:path",
and SSH URIs of the form "ssh://user@host/path", when parsing its
configuration fields.  However, we do not at present retain any
record of this difference, and so we are not able to reconstruct
the original input when reporting SSH endpoints in the "git lfs env"
command.

We also do not report a non-default SSH port, if one was configured,
in the output from that command, leading to confusion when the
input configuration was a URI like "ssh://example.com:1337/path"
and we report it as "example.com:/path", which looks like we have
dropped the port entirely.

We therefore add a URIFormat member to our SSHMetadata structure
and set this true only when parsing an SSH URI with a "ssh://"
scheme.  We also add a URLFromMetadata() helper function in our
"ssh" package which the "git lfs env" command can now use to
format SSH metadata to match its original input format, including
any non-default port number.

As well, we revise one change which was introduced in commit
a0190a6 of PR git-lfs#4446, whereby the
lfshttp.EndpointFromBareSshUrl() function always strips off the
leading path separator.  The code actually only performs this
action if the path returned by EndpointFromSshUrl() begins with
a slash character, but since that function expects an SSH URI
and we construct one as its argument, it will always return an
absolute path with a leading separator, and so we always strip
that off.

Instead, we now detect whether the configured path in the bare
SSH URL is an absolute or relative one before we generate a
temporary URI to pass to EndpointFromSshUrl().  We can then remove
the leading slash always returned by that function if the original
input had a relative path and not otherwise.

We also expand an existing test in the t/t-env.sh file so as to
confirm that our changes work as expected with a variety of
bare SSH URLs.
The SSHMetadata structure contains a Port field, so let's
check that consistently in our EndpointFinder tests, even
when it's just an empty string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems with parsing and reporting SSH endpoint connection strings
1 participant