MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / runPluginPublish

Function runPluginPublish

cli/cmd/plugin_publish.go:62–175  ·  view source on GitHub ↗
(ctx context.Context, cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

60}
61
62func runPluginPublish(ctx context.Context, cmd *cobra.Command, args []string) error {
63 tc := auth.NewTokenClient()
64 token, err := tc.GetToken()
65 if err != nil {
66 return fmt.Errorf("failed to get auth token: %w", err)
67 }
68
69 uiDir := cmd.Flag("ui-dir").Value.String()
70 if uiDir != "" {
71 fi, err := os.Stat(uiDir)
72 if err != nil {
73 return fmt.Errorf("failed checking UI directory: %w", err)
74 }
75 if !fi.IsDir() {
76 return errors.New("UI directory must be a directory")
77 }
78 }
79
80 distDir := cmd.Flag("dist-dir").Value.String()
81 pkgJSON, err := publish.ReadPackageJSON(distDir)
82 if err != nil {
83 return fmt.Errorf("failed to read package.json: %w", err)
84 }
85
86 if pkgJSON.Team != "" && pkgJSON.Name != "" && len(args) > 0 {
87 log.Warn().Msgf("Passing team and plugin name as an argument is deprecated and no longer needed. Argument %q will be ignored", args[0])
88 }
89
90 teamName, pluginName := pkgJSON.Team, pkgJSON.Name
91 if teamName == "" || pluginName == "" {
92 parts := strings.Split(args[0], "/")
93 if len(parts) != 2 {
94 return errors.New("invalid plugin name. Must be in format <team_name>/<plugin_name>")
95 }
96 teamName, pluginName = parts[0], parts[1]
97 pkgJSON.Team, pkgJSON.Name = teamName, pluginName
98 }
99
100 name := fmt.Sprintf("%s/%s@%s", teamName, pluginName, pkgJSON.Version)
101 fmt.Printf("Publishing plugin %s to CloudQuery Hub...\n", name)
102
103 c, err := api.NewClient(token.Value)
104 if err != nil {
105 return err
106 }
107
108 specJsonSchema, err := publish.GetSpecJsonScheme(distDir)
109 if err != nil {
110 return err
111 }
112
113 // create new draft version
114 err = publish.CreateNewPluginDraftVersion(ctx, c, teamName, pluginName, pkgJSON, specJsonSchema)
115 if err != nil {
116 return fmt.Errorf("failed to create new draft version: %w", err)
117 }
118
119 if pkgJSON.Kind == cloudquery_api.PluginKindSource {

Callers 1

newCmdPluginPublishFunction · 0.85

Calls 5

publishPluginAssetsFunction · 0.85
ErrorfMethod · 0.80
PrintfMethod · 0.80
PrintlnMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected