@@ -18,7 +18,6 @@ import (
1818
1919 cloudquery_api "github.com/cloudquery/cloudquery-api-go"
2020 "github.com/cloudquery/cloudquery/cli/internal/auth"
21- "github.com/cloudquery/plugin-sdk/v4/plugin"
2221 "github.com/spf13/cobra"
2322)
2423
@@ -69,13 +68,16 @@ type PackageJSONVersion struct {
6968 SchemaVersion int `json:"schema_version"`
7069}
7170
71+ type Kind = cloudquery_api.PluginKind
72+
7273type PackageJSONV1 struct {
73- Name string `json:"name"`
74- Message string `json:"message"`
75- Version string `json:"version"`
76- Protocols []int `json:"protocols"`
77- SupportedTargets []TargetBuild `json:"supported_targets"`
78- PackageType plugin.PackageType `json:"package_type"`
74+ Name string `json:"name"`
75+ Message string `json:"message"`
76+ Version string `json:"version"`
77+ Kind cloudquery_api.PluginKind `json:"kind"`
78+ Protocols []int `json:"protocols"`
79+ SupportedTargets []TargetBuild `json:"supported_targets"`
80+ PackageType string `json:"package_type"`
7981}
8082
8183type TargetBuild struct {
@@ -121,18 +123,20 @@ func runPublish(ctx context.Context, cmd *cobra.Command, args []string) error {
121123 return fmt .Errorf ("failed to create new draft version: %w" , err )
122124 }
123125
124- // upload table schemas
125- fmt .Println ("Uploading table schemas..." )
126- tablesJSONPath := filepath .Join (distDir , "tables.json" )
127- err = uploadTableSchemas (ctx , c , teamName , pluginName , pkgJSON .Version , tablesJSONPath )
128- if err != nil {
129- return fmt .Errorf ("failed to upload table schemas: %w" , err )
126+ if pkgJSON .Kind == cloudquery_api .Source {
127+ // upload table schemas
128+ fmt .Println ("Uploading table schemas..." )
129+ tablesJSONPath := filepath .Join (distDir , "tables.json" )
130+ err = uploadTableSchemas (ctx , c , teamName , pluginName , tablesJSONPath , pkgJSON )
131+ if err != nil {
132+ return fmt .Errorf ("failed to upload table schemas: %w" , err )
133+ }
130134 }
131135
132136 // upload docs
133137 fmt .Println ("Uploading docs..." )
134138 docsDir := filepath .Join (distDir , "docs" )
135- err = uploadDocs (ctx , c , teamName , pluginName , pkgJSON . Version , docsDir )
139+ err = uploadDocs (ctx , c , teamName , pluginName , docsDir , pkgJSON )
136140 if err != nil {
137141 return fmt .Errorf ("failed to upload docs: %w" , err )
138142 }
@@ -141,7 +145,7 @@ func runPublish(ctx context.Context, cmd *cobra.Command, args []string) error {
141145 fmt .Println ("Uploading binaries..." )
142146 for _ , t := range pkgJSON .SupportedTargets {
143147 fmt .Printf ("- Uploading %s_%s...\n " , t .OS , t .Arch )
144- err = uploadBinary (ctx , c , teamName , pluginName , pkgJSON . Version , t .OS , t .Arch , path .Join (distDir , t .Path ))
148+ err = uploadBinary (ctx , c , teamName , pluginName , t .OS , t .Arch , path .Join (distDir , t .Path ), pkgJSON )
145149 if err != nil {
146150 return fmt .Errorf ("failed to upload binary: %w" , err )
147151 }
@@ -156,7 +160,7 @@ func runPublish(ctx context.Context, cmd *cobra.Command, args []string) error {
156160 if finalize {
157161 fmt .Println ("Finalizing plugin version..." )
158162 draft := false
159- resp , err := c .UpdatePluginVersionWithResponse (ctx , teamName , pluginName , pkgJSON .Version , cloudquery_api.UpdatePluginVersionJSONRequestBody {
163+ resp , err := c .UpdatePluginVersionWithResponse (ctx , teamName , pkgJSON . Kind , pluginName , pkgJSON .Version , cloudquery_api.UpdatePluginVersionJSONRequestBody {
160164 Draft : & draft ,
161165 })
162166 if err != nil {
@@ -191,7 +195,7 @@ func createNewDraftVersion(ctx context.Context, c *cloudquery_api.ClientWithResp
191195 SupportedTargets : targets ,
192196 Checksums : checksums ,
193197 }
194- resp , err := c .CreatePluginVersionWithResponse (ctx , teamName , pluginName , pkgJSON .Version , body )
198+ resp , err := c .CreatePluginVersionWithResponse (ctx , teamName , pkgJSON . Kind , pluginName , pkgJSON .Version , body )
195199 if err != nil {
196200 return fmt .Errorf ("failed to create plugin version: %w" , err )
197201 }
@@ -205,20 +209,20 @@ func createNewDraftVersion(ctx context.Context, c *cloudquery_api.ClientWithResp
205209 return nil
206210}
207211
208- func uploadTableSchemas (ctx context.Context , c * cloudquery_api.ClientWithResponses , teamName , pluginName , version , tablesJSONPath string ) error {
212+ func uploadTableSchemas (ctx context.Context , c * cloudquery_api.ClientWithResponses , teamName , pluginName , tablesJSONPath string , pkgJSON PackageJSONV1 ) error {
209213 b , err := os .ReadFile (tablesJSONPath )
210214 if err != nil {
211215 return fmt .Errorf ("failed to read tables.json: %w" , err )
212216 }
213- tables := make ([]cloudquery_api.PluginTable , 0 )
217+ tables := make ([]cloudquery_api.PluginTableCreate , 0 )
214218 err = json .Unmarshal (b , & tables )
215219 if err != nil {
216220 return fmt .Errorf ("failed to parse tables.json: %w" , err )
217221 }
218222 body := cloudquery_api.CreatePluginVersionTablesJSONRequestBody {
219223 Tables : tables ,
220224 }
221- resp , err := c .CreatePluginVersionTablesWithResponse (ctx , teamName , pluginName , version , body )
225+ resp , err := c .CreatePluginVersionTablesWithResponse (ctx , teamName , pkgJSON . Kind , pluginName , pkgJSON . Version , body )
222226 if err != nil {
223227 return fmt .Errorf ("failed to upload table schemas: %w" , err )
224228 }
@@ -247,12 +251,12 @@ func errorFromHTTPResponse(httpResp *http.Response, resp any) error {
247251 return fmt .Errorf ("error code: %v" , httpResp .StatusCode )
248252}
249253
250- func uploadDocs (ctx context.Context , c * cloudquery_api.ClientWithResponses , teamName , pluginName , version , docsDir string ) error {
254+ func uploadDocs (ctx context.Context , c * cloudquery_api.ClientWithResponses , teamName , pluginName , docsDir string , pkgJSON PackageJSONV1 ) error {
251255 dirEntries , err := os .ReadDir (docsDir )
252256 if err != nil {
253257 return fmt .Errorf ("failed to read docs directory: %w" , err )
254258 }
255- pages := make ([]cloudquery_api.PluginDocsPage , 0 , len (dirEntries ))
259+ pages := make ([]cloudquery_api.PluginDocsPageCreate , 0 , len (dirEntries ))
256260 for _ , dirEntry := range dirEntries {
257261 if dirEntry .IsDir () {
258262 continue
@@ -274,7 +278,7 @@ func uploadDocs(ctx context.Context, c *cloudquery_api.ClientWithResponses, team
274278 return fmt .Errorf ("failed to parse ordinal_position in %s: %w" , dirEntry .Name (), err )
275279 }
276280 }
277- pages = append (pages , cloudquery_api.PluginDocsPage {
281+ pages = append (pages , cloudquery_api.PluginDocsPageCreate {
278282 Content : contentStr ,
279283 Name : strings .TrimSuffix (dirEntry .Name (), ".md" ),
280284 OrdinalPosition : & ordinal ,
@@ -284,7 +288,7 @@ func uploadDocs(ctx context.Context, c *cloudquery_api.ClientWithResponses, team
284288 body := cloudquery_api.CreatePluginVersionDocsJSONRequestBody {
285289 Pages : pages ,
286290 }
287- resp , err := c .CreatePluginVersionDocsWithResponse (ctx , teamName , pluginName , version , body )
291+ resp , err := c .CreatePluginVersionDocsWithResponse (ctx , teamName , pkgJSON . Kind , pluginName , pkgJSON . Version , body )
288292 if err != nil {
289293 return fmt .Errorf ("failed to upload docs: %w" , err )
290294 }
@@ -294,9 +298,9 @@ func uploadDocs(ctx context.Context, c *cloudquery_api.ClientWithResponses, team
294298 return nil
295299}
296300
297- func uploadBinary (ctx context.Context , c * cloudquery_api.ClientWithResponses , teamName , pluginName , version , goos , goarch , localPath string ) error {
301+ func uploadBinary (ctx context.Context , c * cloudquery_api.ClientWithResponses , teamName , pluginName , goos , goarch , localPath string , pkgJSON PackageJSONV1 ) error {
298302 target := goos + "_" + goarch
299- resp , err := c .UploadPluginAssetWithResponse (ctx , teamName , pluginName , version , target )
303+ resp , err := c .UploadPluginAssetWithResponse (ctx , teamName , pkgJSON . Kind , pluginName , pkgJSON . Version , target )
300304 if err != nil {
301305 return fmt .Errorf ("failed to upload binary: %w" , err )
302306 }
@@ -314,11 +318,7 @@ func uploadBinary(ctx context.Context, c *cloudquery_api.ClientWithResponses, te
314318 return fmt .Errorf ("upload response is nil, failed to upload binary" )
315319 }
316320 uploadURL := resp .JSON201 .Url
317- if uploadURL == nil {
318- return fmt .Errorf ("upload URL is nil, failed to upload binary" )
319- }
320-
321- err = uploadFile (* uploadURL , localPath )
321+ err = uploadFile (uploadURL , localPath )
322322 if err != nil {
323323 return fmt .Errorf ("failed to upload file: %w" , err )
324324 }
0 commit comments