Skip to content
Merged
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 plugins/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ func testSyncTable(t *testing.T, tc syncTestCase) {
plugin.SetLogger(zerolog.New(zerolog.NewTestWriter(t)))
spec := specs.Source{
Name: "testSource",
Path: "cloudquery/testSource",
Tables: []string{"*"},
Version: "v1.0.0",
Destinations: []string{"test"},
Expand Down
1 change: 1 addition & 0 deletions serve/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestServeSource(t *testing.T) {
specs.Source{
Name: "testSourcePlugin",
Version: "v1.0.0",
Path: "cloudquery/testSourcePlugin",
Registry: specs.RegistryGithub,
Tables: []string{"*"},
Spec: TestSourcePluginSpec{Accounts: []string{"cloudquery/plugin-sdk"}},
Expand Down
17 changes: 11 additions & 6 deletions specs/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"fmt"
"strings"

"github.com/thoas/go-funk"
)

type WriteMode int
Expand Down Expand Up @@ -32,12 +34,6 @@ func (d *Destination) SetDefaults() {
if d.Registry.String() == "" {
d.Registry = RegistryGithub
}
if d.Path == "" {
d.Path = d.Name
}
if d.Registry == RegistryGithub && !strings.Contains(d.Path, "/") {
d.Path = "cloudquery/" + d.Path
}
}

func (d *Destination) UnmarshalSpec(out interface{}) error {
Expand All @@ -55,6 +51,15 @@ func (d *Destination) Validate() error {
if d.Name == "" {
return fmt.Errorf("name is required")
}
if d.Path == "" {
msg := "path is required"
// give a small hint to help users transition from the old config format that didn't require path
officialPlugins := []string{"postgresql", "csv"}
if funk.ContainsString(officialPlugins, d.Name) {
msg += fmt.Sprintf(". Hint: try setting path to cloudquery/%s in your config", d.Name)
}
return fmt.Errorf(msg)
}

if d.Registry == RegistryGithub {
if d.Version == "" {
Expand Down
3 changes: 3 additions & 0 deletions specs/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ spec:`,
`kind: destination
spec:
name: test
path: cloudquery/test
`,
"version is required",
nil,
Expand All @@ -127,6 +128,7 @@ spec:
`kind: destination
spec:
name: test
path: cloudquery/test
version: 1.1.0
`,
"version must start with v",
Expand Down Expand Up @@ -167,6 +169,7 @@ spec:
`kind: destination
spec:
name: test
path: cloudquery/test
version: v1.1.0
`,
"",
Expand Down
17 changes: 11 additions & 6 deletions specs/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"fmt"
"strings"

"github.com/thoas/go-funk"
)

const (
Expand Down Expand Up @@ -43,12 +45,6 @@ func (s *Source) SetDefaults() {
if s.Registry.String() == "" {
s.Registry = RegistryGithub
}
if s.Path == "" {
s.Path = s.Name
}
if s.Registry == RegistryGithub && !strings.Contains(s.Path, "/") {
s.Path = "cloudquery/" + s.Path
}
if s.Tables == nil {
s.Tables = []string{"*"}
}
Expand Down Expand Up @@ -79,6 +75,15 @@ func (s *Source) Validate() error {
if s.Name == "" {
return fmt.Errorf("name is required")
}
if s.Path == "" {
msg := "path is required"
// give a small hint to help users transition from the old config format that didn't require path
officialPlugins := []string{"aws", "azure", "gcp", "digitalocean", "github", "heroku", "k8s", "okta", "terraform", "cloudflare"}
if funk.ContainsString(officialPlugins, s.Name) {
msg += fmt.Sprintf(". Hint: try setting path to cloudquery/%s in your config", s.Name)
Copy link
Member

Choose a reason for hiding this comment

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

giphy

}
return fmt.Errorf(msg)
Copy link
Member

@disq disq Nov 7, 2022

Choose a reason for hiding this comment

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

Should be errors.New because if msg contains % it will fail weirdly (but understandably)

}

if s.Registry == RegistryGithub {
if s.Version == "" {
Expand Down
13 changes: 13 additions & 0 deletions specs/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,21 @@ spec:`,
"name is required",
nil,
},
{
"required_path",
`kind: source
spec:
name: test
`,
"path is required",
nil,
},
{
"required_version",
`kind: source
spec:
name: test
path: cloudquery/test
`,
"version is required",
nil,
Expand All @@ -92,6 +102,7 @@ spec:
`kind: source
spec:
name: test
path: cloudquery/test
version: 1.1.0
`,
"version must start with v",
Expand All @@ -102,6 +113,7 @@ spec:
`kind: source
spec:
name: test
path: cloudquery/test
version: v1.1.0
`,
"at least one destination is required",
Expand All @@ -112,6 +124,7 @@ spec:
`kind: source
spec:
name: test
path: cloudquery/test
version: v1.1.0
destinations: ["test"]
`,
Expand Down
1 change: 1 addition & 0 deletions specs/testdata/multiple_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spec:
kind: destination
spec:
name: postgresql
path: cloudquery/postgresql
version: v1.6.3
spec:
connection_string: postgresql://postgres:pass@localhost:5432/postgres