From fba239091cb89d05b8fd2a1134ad84ec3fe31ae2 Mon Sep 17 00:00:00 2001 From: Herman Schaaf Date: Mon, 7 Nov 2022 16:21:44 +0000 Subject: [PATCH] Make path required --- plugins/source_test.go | 1 + serve/source_test.go | 1 + specs/destination.go | 17 +++++++++++------ specs/destination_test.go | 3 +++ specs/source.go | 17 +++++++++++------ specs/source_test.go | 13 +++++++++++++ specs/testdata/multiple_sources.yml | 1 + 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/plugins/source_test.go b/plugins/source_test.go index 8cd7dedaec..14b11f958c 100644 --- a/plugins/source_test.go +++ b/plugins/source_test.go @@ -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"}, diff --git a/serve/source_test.go b/serve/source_test.go index 75f2342542..02e15a4917 100644 --- a/serve/source_test.go +++ b/serve/source_test.go @@ -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"}}, diff --git a/specs/destination.go b/specs/destination.go index 20b01072ea..1ea6b22aa8 100644 --- a/specs/destination.go +++ b/specs/destination.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "strings" + + "github.com/thoas/go-funk" ) type WriteMode int @@ -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 { @@ -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 == "" { diff --git a/specs/destination_test.go b/specs/destination_test.go index a8fbdad8a1..1331cc3b61 100644 --- a/specs/destination_test.go +++ b/specs/destination_test.go @@ -118,6 +118,7 @@ spec:`, `kind: destination spec: name: test + path: cloudquery/test `, "version is required", nil, @@ -127,6 +128,7 @@ spec: `kind: destination spec: name: test + path: cloudquery/test version: 1.1.0 `, "version must start with v", @@ -167,6 +169,7 @@ spec: `kind: destination spec: name: test + path: cloudquery/test version: v1.1.0 `, "", diff --git a/specs/source.go b/specs/source.go index 6e4d5a3e6d..90fb75fc67 100644 --- a/specs/source.go +++ b/specs/source.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "strings" + + "github.com/thoas/go-funk" ) const ( @@ -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{"*"} } @@ -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) + } + return fmt.Errorf(msg) + } if s.Registry == RegistryGithub { if s.Version == "" { diff --git a/specs/source_test.go b/specs/source_test.go index 840f4722be..1b712d978f 100644 --- a/specs/source_test.go +++ b/specs/source_test.go @@ -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, @@ -92,6 +102,7 @@ spec: `kind: source spec: name: test + path: cloudquery/test version: 1.1.0 `, "version must start with v", @@ -102,6 +113,7 @@ spec: `kind: source spec: name: test + path: cloudquery/test version: v1.1.0 `, "at least one destination is required", @@ -112,6 +124,7 @@ spec: `kind: source spec: name: test + path: cloudquery/test version: v1.1.0 destinations: ["test"] `, diff --git a/specs/testdata/multiple_sources.yml b/specs/testdata/multiple_sources.yml index b6b198860a..626513dd00 100644 --- a/specs/testdata/multiple_sources.yml +++ b/specs/testdata/multiple_sources.yml @@ -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