Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions command/common/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ func HandleError(err error) error {
}
return nil
}

func CheckLogin(config *shared.Config) error {
if config == nil || config.Auth == nil || config.Auth.Account == nil || config.Auth.Account.Id == "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should've been a method on the config

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair. i'll do it as a follow-up

return shared.ErrUnauthorized
}
return nil
}
13 changes: 11 additions & 2 deletions command/connect/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (c *Command) init() error {
// Got a client now communicating over RPC.
c.connect = raw.(Connect)

// All commands require login first
c.Command.PersistentPreRun = func(cmd *cobra.Command, args []string) {
if err := common.CheckLogin(c.Config); err != nil {
common.HandleError(err)
os.Exit(0) // TODO: this should be 1 but that prints "exit status 1" to the console
}
}

createCmd := &cobra.Command{
Use: "create <name>",
Short: "Create a connector.",
Expand Down Expand Up @@ -110,7 +118,8 @@ func (c *Command) init() error {
}

func (c *Command) list(cmd *cobra.Command, args []string) error {
connectors, err := c.connect.List(context.Background())
req := &schedv1.ConnectCluster{AccountId: c.Config.Auth.Account.Id}
connectors, err := c.connect.List(context.Background(), req)
if err != nil {
return common.HandleError(err)
}
Expand Down Expand Up @@ -155,7 +164,7 @@ func (c *Command) create(cmd *cobra.Command, args []string) error {
}

func (c *Command) describe(cmd *cobra.Command, args []string) error {
req := &schedv1.ConnectCluster{Name: args[0]}
req := &schedv1.ConnectCluster{AccountId: c.Config.Auth.Account.Id, Name: args[0]}
connector, err := c.connect.Describe(context.Background(), req)
if err != nil {
return common.HandleError(err)
Expand Down
6 changes: 3 additions & 3 deletions command/connect/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type GRPCClient struct {
client proto.ConnectClient
}

func (c *GRPCClient) List(ctx context.Context) ([]*schedv1.ConnectCluster, error) {
resp, err := c.client.List(ctx, &schedv1.GetConnectClustersRequest{})
func (c *GRPCClient) List(ctx context.Context, cluster *schedv1.ConnectCluster) ([]*schedv1.ConnectCluster, error) {
resp, err := c.client.List(ctx, &schedv1.GetConnectClustersRequest{Cluster: cluster})
if err != nil {
return nil, shared.ConvertGRPCError(err)
}
Expand Down Expand Up @@ -43,7 +43,7 @@ type GRPCServer struct {
}

func (s *GRPCServer) List(ctx context.Context, req *schedv1.GetConnectClustersRequest) (*schedv1.GetConnectClustersReply, error) {
r, err := s.Impl.List(ctx)
r, err := s.Impl.List(ctx, req.Cluster)
return &schedv1.GetConnectClustersReply{Clusters: r}, err
}

Expand Down
2 changes: 1 addition & 1 deletion command/connect/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type Connect interface {
List(ctx context.Context) ([]*schedv1.ConnectCluster, error)
List(ctx context.Context, cluster *schedv1.ConnectCluster) ([]*schedv1.ConnectCluster, error)
Describe(ctx context.Context, cluster *schedv1.ConnectCluster) (*schedv1.ConnectCluster, error)
CreateS3Sink(ctx context.Context, config *schedv1.ConnectS3SinkClusterConfig) (*schedv1.ConnectS3SinkCluster, error)
}
Expand Down
4 changes: 2 additions & 2 deletions http/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func NewConnectService(client *Client) *ConnectService {
}

// List returns the authenticated user's connect clusters within a given account.
func (s *ConnectService) List(accountID string) ([]*schedv1.ConnectCluster, *http.Response, error) {
func (s *ConnectService) List(cluster *schedv1.ConnectCluster) ([]*schedv1.ConnectCluster, *http.Response, error) {
reply := new(schedv1.GetConnectClustersReply)
resp, err := s.sling.New().Get("/api/connectors?account_id="+accountID).Receive(reply, reply)
resp, err := s.sling.New().Get("/api/connectors").QueryStruct(cluster).Receive(reply, reply)
if err != nil {
return nil, resp, errors.Wrap(err, "unable to fetch connectors")
}
Expand Down
14 changes: 3 additions & 11 deletions plugin/confluent-connect-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
var impl *Connect
{
client := chttp.NewClientWithJWT(context.Background(), config.AuthToken, config.AuthURL, config.Logger)
impl = &Connect{Logger: logger, Config: config, Client: client}
impl = &Connect{Logger: logger, Client: client}
}

plugin.Serve(&plugin.ServeConfig{
Expand All @@ -63,25 +63,17 @@ func main() {

type Connect struct {
Logger *log.Logger
Config *shared.Config
Client *chttp.Client
}

func (c *Connect) List(ctx context.Context) ([]*schedv1.ConnectCluster, error) {
func (c *Connect) List(ctx context.Context, cluster *schedv1.ConnectCluster) ([]*schedv1.ConnectCluster, error) {
c.Logger.Log("msg", "connect.List()")
if c.Config.Auth == nil {
return nil, shared.ErrUnauthorized
}
ret, _, err := c.Client.Connect.List(c.Config.Auth.Account.Id)
ret, _, err := c.Client.Connect.List(cluster)
return ret, shared.ConvertAPIError(err)
}

func (c *Connect) Describe(ctx context.Context, cluster *schedv1.ConnectCluster) (*schedv1.ConnectCluster, error) {
c.Logger.Log("msg", "connect.Describe()")
if c.Config.Auth == nil {
return nil, shared.ErrUnauthorized
}
cluster.AccountId = c.Config.Auth.Account.Id
ret, _, err := c.Client.Connect.Describe(cluster)
return ret, shared.ConvertAPIError(err)
}
Expand Down