Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Notable Changes

### CLI
* Recognize `ssh://` template URLs in `databricks bundle init` ([#5891](https://github.com/databricks/cli/pull/5891)).

### Bundles

Expand Down
14 changes: 8 additions & 6 deletions libs/template/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import (
"github.com/databricks/cli/libs/git"
)

// See https://git-scm.com/docs/git-clone#_git_urls for the set of supported
// Git URL forms. We deliberately exclude deprecated/insecure protocols (git, http, ftp[s]).
var gitUrlPrefixes = []string{
"https://",
"ssh://",
// recognize git@ without ssh:// protocol because this is very common
"git@",
}

func IsRepoUrl(url string) bool {
result := false
func IsGitRepoUrl(url string) bool {
for _, prefix := range gitUrlPrefixes {
if strings.HasPrefix(url, prefix) {
result = true
break
return true
}
}
return result
return false
}

// ResolveReader resolves a template path/URL to a Reader (built-in, git or local)
Expand All @@ -30,7 +32,7 @@ func ResolveReader(templatePathOrUrl, templateDir, ref string) (Reader, bool) {
return tmpl.Reader, false
}

if IsRepoUrl(templatePathOrUrl) {
if IsGitRepoUrl(templatePathOrUrl) {
return NewGitReader(templatePathOrUrl, ref, templateDir, git.Clone), true
}

Expand Down
22 changes: 16 additions & 6 deletions libs/template/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,22 @@ func TestTemplateResolverForCustomPath(t *testing.T) {
assert.Equal(t, "/config/file", tmpl.Writer.(*defaultWriter).configPath)
}

func TestBundleInitIsRepoUrl(t *testing.T) {
assert.True(t, IsRepoUrl("git@github.com:databricks/cli.git"))
assert.True(t, IsRepoUrl("https://github.com/databricks/cli.git"))

assert.False(t, IsRepoUrl("./local"))
assert.False(t, IsRepoUrl("foo"))
func TestBundleInitIsGitRepoUrl(t *testing.T) {
// Supported
assert.True(t, IsGitRepoUrl("git@github.com:databricks/cli.git"))
assert.True(t, IsGitRepoUrl("https://github.com/databricks/cli.git"))
assert.True(t, IsGitRepoUrl("ssh://user@company.ghe.com/databricks/cli.git"))

// Unsupported
assert.False(t, IsGitRepoUrl("git://github.com/databricks/cli.git"))
assert.False(t, IsGitRepoUrl("http://github.com/databricks/cli.git"))
assert.False(t, IsGitRepoUrl("ftp://github.com/databricks/cli.git"))
assert.False(t, IsGitRepoUrl("ftps://github.com/databricks/cli.git"))

// Not git repos
assert.False(t, IsGitRepoUrl("./local"))
assert.False(t, IsGitRepoUrl("foo"))
assert.False(t, IsGitRepoUrl("github.com/databricks/cli.git"))
}

func TestResolveReader(t *testing.T) {
Expand Down
Loading