Skip to content

Commit

Permalink
plugins validate: cmd skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejWilde committed Apr 20, 2020
1 parent d75ad86 commit 3e41660
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
10 changes: 10 additions & 0 deletions internal/ctl/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ func AddQuietFlag(cmd *cobra.Command, quiet *bool) {
BindBoolVarP(cmd.Flags(), quiet, false, "quiet", "q", "disable output logging")
}

func AddInputFlag(cmd *cobra.Command, required bool, input *string) {
description := "Input data in json format"

if required {
description = requiredDescription(&description)
}

BindStringVarP(cmd.Flags(), input, "", "input", "i", description)
}

func AddDefinitionFilesFlags(cmd *cobra.Command, files *[]string, directory *string, env *string) {
BindStringArrayVarP(cmd.Flags(), files, []string{}, "files", "f", "the connector definitions files (Required if --directory or --env-var not specified)")
BindStringVarP(cmd.Flags(), directory, "", "directory", "d", "the directory containing the connector definitions files (Required if --file or --env-vars not specified)")
Expand Down
1 change: 1 addition & 0 deletions internal/ctl/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func Command() *cobra.Command {

// Add subcommands
pluginsCmd.AddCommand(listPluginsCmd())
pluginsCmd.AddCommand(validatePluginsCmd())

return pluginsCmd
}
62 changes: 62 additions & 0 deletions internal/ctl/plugins/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package plugins

import (
"fmt"

"github.com/90poe/connectctl/internal/ctl"
"github.com/90poe/connectctl/internal/version"
"github.com/90poe/connectctl/pkg/client/connect"
"github.com/90poe/connectctl/pkg/manager"
"github.com/pkg/errors"

"github.com/spf13/cobra"
)

type validatePluginsCmdParams struct {
ClusterURL string
Input string
}

func validatePluginsCmd() *cobra.Command {
params := &validatePluginsCmdParams{}

validateCmd := &cobra.Command{
Use: "validate",
Short: "Validates plugin config",
Long: "",
RunE: func(cmd *cobra.Command, _ []string) error {
return doValidatePlugins(cmd, params)
},
}

ctl.AddClusterFlag(validateCmd, true, &params.ClusterURL)
ctl.AddInputFlag(validateCmd, true, &params.Input)

return validateCmd
}

func doValidatePlugins(_ *cobra.Command, params *validatePluginsCmdParams) error {
config := &manager.Config{
ClusterURL: params.ClusterURL,
Version: version.Version,
}

userAgent := fmt.Sprintf("90poe.io/connectctl/%s", version.Version)

client, err := connect.NewClient(params.ClusterURL, connect.WithUserAgent(userAgent))
if err != nil {
return errors.Wrap(err, "error creating connect client")
}

mngr, err := manager.NewConnectorsManager(client, config)
if err != nil {
return errors.Wrap(err, "error creating connectors manager")
}

//TODO remove
if mngr != nil {
return nil
}

return nil
}
20 changes: 19 additions & 1 deletion pkg/client/connect/plugins.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package connect

import "net/http"
import (
"errors"
"net/http"
)

// This is new and not from the original author

Expand All @@ -24,3 +27,18 @@ func (c *Client) ListPlugins() ([]*Plugin, *http.Response, error) {
response, err := c.get(path, &names)
return names, response, err
}

// ValidatePlugins validates the provided configuration values against the configuration definition.
// See: https://docs.confluent.io/current/connect/references/restapi.html#put--connector-plugins-(string-name)-config-validate
func (c *Client) ValidatePlugins(config ConnectorConfig) ([]*Plugin, *http.Response, error) {
connectorClass, ok := config["connector.class"]
if !ok {
return nil, nil, errors.New("missing required key in config: connector.class")
}
// TODO
path := "connector-plugins"
var names []*Plugin

response, err := c.get(path, &names)
return names, response, err
}

0 comments on commit 3e41660

Please sign in to comment.