diff --git a/plugins/source/snyk/client/columns.go b/plugins/source/snyk/client/columns.go new file mode 100644 index 00000000000000..b40498585c9a8b --- /dev/null +++ b/plugins/source/snyk/client/columns.go @@ -0,0 +1,13 @@ +package client + +import "github.com/cloudquery/plugin-sdk/schema" + +var OrganizationID = schema.Column{ + Name: "organization_id", + Type: schema.TypeString, + Resolver: ResolveOrganizationID, + CreationOptions: schema.ColumnCreationOptions{ + PrimaryKey: true, + NotNull: true, + }, +} diff --git a/plugins/source/snyk/resources/services/dependency/dependencies.go b/plugins/source/snyk/resources/services/dependency/dependencies.go index 3fe6456a724a66..d32116d6293d18 100644 --- a/plugins/source/snyk/resources/services/dependency/dependencies.go +++ b/plugins/source/snyk/resources/services/dependency/dependencies.go @@ -13,16 +13,7 @@ func Dependencies() *schema.Table { Description: `https://pkg.go.dev/github.com/pavel-snyk/snyk-sdk-go/snyk#Dependency`, Resolver: fetchDependencies, Multiplex: client.ByOrganization, - Transform: transformers.TransformWithStruct(&snyk.Dependency{}), - Columns: []schema.Column{ - { - Name: "id", - Type: schema.TypeString, - Resolver: schema.PathResolver("ID"), - CreationOptions: schema.ColumnCreationOptions{ - PrimaryKey: true, - }, - }, - }, + Transform: transformers.TransformWithStruct(&snyk.Dependency{}, transformers.WithPrimaryKeys("ID")), + Columns: schema.ColumnList{client.OrganizationID}, } } diff --git a/plugins/source/snyk/resources/services/integration/integrations.go b/plugins/source/snyk/resources/services/integration/integrations.go index 1686a143c94f19..b49a697e6c7eb4 100644 --- a/plugins/source/snyk/resources/services/integration/integrations.go +++ b/plugins/source/snyk/resources/services/integration/integrations.go @@ -14,26 +14,14 @@ func Integrations() *schema.Table { Resolver: fetchIntegrations, PreResourceResolver: getIntegration, Multiplex: client.ByOrganization, - Transform: transformers.TransformWithStruct(&snyk.Integration{}), + Transform: transformers.TransformWithStruct(&snyk.Integration{}, transformers.WithPrimaryKeys("ID")), Columns: []schema.Column{ - { - Name: "organization_id", - Type: schema.TypeString, - Resolver: client.ResolveOrganizationID, - }, + client.OrganizationID, { Name: "settings", Type: schema.TypeJSON, Resolver: getIntegrationSettings, }, - { - Name: "id", - Type: schema.TypeString, - Resolver: schema.PathResolver("ID"), - CreationOptions: schema.ColumnCreationOptions{ - PrimaryKey: true, - }, - }, }, } } diff --git a/plugins/source/snyk/resources/services/organization/organizations.go b/plugins/source/snyk/resources/services/organization/organizations.go index 41bcbb27270213..28e692de3413f0 100644 --- a/plugins/source/snyk/resources/services/organization/organizations.go +++ b/plugins/source/snyk/resources/services/organization/organizations.go @@ -13,16 +13,6 @@ func Organizations() *schema.Table { Description: `https://pkg.go.dev/github.com/pavel-snyk/snyk-sdk-go/snyk#Organization`, Resolver: fetchOrganizations, Multiplex: client.SingleOrganization, - Transform: transformers.TransformWithStruct(&snyk.Organization{}), - Columns: []schema.Column{ - { - Name: "id", - Type: schema.TypeString, - Resolver: schema.PathResolver("ID"), - CreationOptions: schema.ColumnCreationOptions{ - PrimaryKey: true, - }, - }, - }, + Transform: transformers.TransformWithStruct(&snyk.Organization{}, transformers.WithPrimaryKeys("ID")), } } diff --git a/plugins/source/snyk/resources/services/project/projects.go b/plugins/source/snyk/resources/services/project/projects.go index 597e7ef976a306..8bd1d09148ea45 100644 --- a/plugins/source/snyk/resources/services/project/projects.go +++ b/plugins/source/snyk/resources/services/project/projects.go @@ -13,21 +13,7 @@ func Projects() *schema.Table { Description: `https://pkg.go.dev/github.com/pavel-snyk/snyk-sdk-go/snyk#Project`, Resolver: fetchProjects, Multiplex: client.ByOrganization, - Transform: transformers.TransformWithStruct(&snyk.Project{}), - Columns: []schema.Column{ - { - Name: "organization_id", - Type: schema.TypeString, - Resolver: client.ResolveOrganizationID, - }, - { - Name: "id", - Type: schema.TypeString, - Resolver: schema.PathResolver("ID"), - CreationOptions: schema.ColumnCreationOptions{ - PrimaryKey: true, - }, - }, - }, + Transform: transformers.TransformWithStruct(&snyk.Project{}, transformers.WithPrimaryKeys("ID")), + Columns: schema.ColumnList{client.OrganizationID}, } } diff --git a/website/tables/snyk/snyk_dependencies.md b/website/tables/snyk/snyk_dependencies.md index c820fd9f357717..7ccab93ae9bd2b 100644 --- a/website/tables/snyk/snyk_dependencies.md +++ b/website/tables/snyk/snyk_dependencies.md @@ -4,7 +4,7 @@ This table shows data for Snyk Dependencies. https://pkg.go.dev/github.com/pavel-snyk/snyk-sdk-go/snyk#Dependency -The primary key for this table is **id**. +The composite primary key for this table is (**organization_id**, **id**). ## Columns @@ -14,6 +14,7 @@ The primary key for this table is **id**. |_cq_sync_time|Timestamp| |_cq_id|UUID| |_cq_parent_id|UUID| +|organization_id (PK)|String| |id (PK)|String| |name|String| |type|String| diff --git a/website/tables/snyk/snyk_integrations.md b/website/tables/snyk/snyk_integrations.md index aa68bbec25d8aa..efb27b9943f145 100644 --- a/website/tables/snyk/snyk_integrations.md +++ b/website/tables/snyk/snyk_integrations.md @@ -4,7 +4,7 @@ This table shows data for Snyk Integrations. https://pkg.go.dev/github.com/pavel-snyk/snyk-sdk-go/snyk#Integration -The primary key for this table is **id**. +The composite primary key for this table is (**organization_id**, **id**). ## Columns @@ -14,8 +14,8 @@ The primary key for this table is **id**. |_cq_sync_time|Timestamp| |_cq_id|UUID| |_cq_parent_id|UUID| -|organization_id|String| +|organization_id (PK)|String| |settings|JSON| -|id (PK)|String| |credentials|JSON| +|id (PK)|String| |type|String| \ No newline at end of file diff --git a/website/tables/snyk/snyk_organizations.md b/website/tables/snyk/snyk_organizations.md index 63817947f6b089..9192a3b5574382 100644 --- a/website/tables/snyk/snyk_organizations.md +++ b/website/tables/snyk/snyk_organizations.md @@ -14,8 +14,8 @@ The primary key for this table is **id**. |_cq_sync_time|Timestamp| |_cq_id|UUID| |_cq_parent_id|UUID| -|id (PK)|String| |group|JSON| +|id (PK)|String| |name|String| |slug|String| |url|String| \ No newline at end of file diff --git a/website/tables/snyk/snyk_projects.md b/website/tables/snyk/snyk_projects.md index a9e90f5b8a5761..79afd53c5c0b38 100644 --- a/website/tables/snyk/snyk_projects.md +++ b/website/tables/snyk/snyk_projects.md @@ -4,7 +4,7 @@ This table shows data for Snyk Projects. https://pkg.go.dev/github.com/pavel-snyk/snyk-sdk-go/snyk#Project -The primary key for this table is **id**. +The composite primary key for this table is (**organization_id**, **id**). ## Columns @@ -14,7 +14,7 @@ The primary key for this table is **id**. |_cq_sync_time|Timestamp| |_cq_id|UUID| |_cq_parent_id|UUID| -|organization_id|String| +|organization_id (PK)|String| |id (PK)|String| |name|String| |origin|String| \ No newline at end of file