fastly/cli

[FEATURE REQUEST] Support Git URLs as parameters for `--from`

Closed this issue · 3 comments

Is your feature request related to a problem? Please describe.
When specifying a starter kit by URL to a private repository and having everything set up to use Git URLs all the way, the CLI doesn’t work as the parsing of the URL fails.

could not read --from URL: parse "git@github.com:fastly/compute-starter-kit-rust-empty.git": first path segment in URL cannot contain colon

Describe the solution you'd like
Support Git URLs beside traditional HTTPS URLs.

Describe alternatives you've considered
Tried to patch the behavior by using the git-urls Parse method. This changed the error as now the parsing works, but the download itself fails a bit further down.

failed to get package 'ssh://git@github.com/fastly/compute-starter-kit-rust-empty.git': Get "ssh://git@github.com/fastly/compute-starter-kit-rust-empty.git": unsupported protocol scheme "ssh"

Additional context
In order to see what happens, I extended the test scenarios like this:

diff --git a/pkg/commands/compute/init_test.go b/pkg/commands/compute/init_test.go
index 5ed37bcd..ecf918ea 100644
--- a/pkg/commands/compute/init_test.go
+++ b/pkg/commands/compute/init_test.go
@@ -168,6 +168,25 @@ func TestInit(t *testing.T) {
 				"SUCCESS: Initialized package",
 			},
 		},
+		{
+			name: "with --from set to starter kit repository with SSH URL",
+			args: args("compute init --from git@github.com:fastly/compute-starter-kit-rust-empty.git"),
+			configFile: config.File{
+				StarterKits: config.StarterKitLanguages{
+					Rust: []config.StarterKit{
+						{
+							Name: "Default",
+							Path: "git@github.com:fastly/compute-starter-kit-rust-empty.git",
+						},
+					},
+				},
+			},
+			wantOutput: []string{
+				"Fetching package template",
+				"Reading fastly.toml",
+				"SUCCESS: Initialized package",
+			},
+		},
 		{
 			name: "with --from set to zip archive",
 			args: args("compute init --from https://github.com/fastly/compute-starter-kit-rust-default/archive/refs/heads/main.zip"),

And a run of TEST_COMPUTE_INIT=1 go test -run TestInit ./pkg/commands/compute/init_test.go exposed the same behavior that I experienced when running the CLI initially with a Git URL as --from.

If you want to open a PR which has the work you've done so far, I'm certain we could collaborate on getting this to work.

Hi Kevin (@kpfleming). The whole approach would add extra complexity due to the different authentication schemes in place. Also, my tiny little baby steps towards supporting SSH URLs (as used by Git) might only open a door to a territory that is out of the scope of what Fastly CLI was planned and aiming for. If you honestly think a draft PR would help to start a conversation here, I’m happy to create it.

During my short investigation yesterday I didn't see it as being a super-complex change, but now that I think about it if Git isn't setup properly then the result of attempting to clone the repo could cause Git to prompt for authentication credentials, and that might end up being very messy.

Since the alternative is to clone the private repo manually first and then point --from at that directory, it's probably best that we don't try to tackle this :-)