Skip to content
Closed
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
22 changes: 22 additions & 0 deletions clients/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io"
"net"
"os"
Expand Down Expand Up @@ -193,6 +195,26 @@ func (c *DestinationClient) Initialize(ctx context.Context, spec specs.Destinati
return nil
}

func (c *DestinationClient) Validate(ctx context.Context, spec specs.Destination) (warnings, errors []string, err error) {
b, err := json.Marshal(spec)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal destination spec: %w", err)
}
resp, err := c.pbClient.Validate(ctx, &pb.ValidateDestination_Request{
Spec: b,
})
if err != nil {
st, ok := status.FromError(err)
if ok && st.Code() == codes.Unimplemented {
// Backwards-compatibility with older plugin versions that don't support Validate().
// In this case, we only return one warning: that the plugin should be updated.
return []string{"the version of this plugin is outdated and should be updated"}, nil, nil

Choose a reason for hiding this comment

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

Nit: Maybe temper the wording a bit.
Some advanced features might not be supported by the current version of the CLI, and might lead to breaks in future. Please update using (this link)

Copy link
Member Author

@hermanschaaf hermanschaaf Oct 11, 2022

Choose a reason for hiding this comment

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

Thanks, good suggestion - I was struggling to find the right wording here :)

}
return nil, nil, fmt.Errorf("failed to call Validate: %w", err)
}
return resp.Warnings, resp.Errors, nil
}

func (c *DestinationClient) Migrate(ctx context.Context, tables []*schema.Table) error {
b, err := json.Marshal(tables)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions clients/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io"
"net"
"os"
Expand Down Expand Up @@ -195,6 +197,26 @@ func (c *SourceClient) GetTables(ctx context.Context) ([]*schema.Table, error) {
return tables, nil
}

func (c *SourceClient) Validate(ctx context.Context, spec specs.Source) (warnings, errors []string, err error) {
Copy link
Member

@disq disq Oct 11, 2022

Choose a reason for hiding this comment

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

Apart from the errors shadow/nit, could maybe consider returning a ValidateResult struct instead of the triple return values? But then it would be very similar to the grpc structs, ValidateDestination_Response etc. Maybe there's a better way? Pass a logger (as interface) and let it log? It's a bunch of lines, wouldn't need any formatting on the CLI side anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'd be good with a struct; it's more extensible in the long run too. I don't think it's an issue that it's similar to ValidateDestination_Response.

b, err := json.Marshal(spec)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal source spec: %w", err)
}
resp, err := c.pbClient.Validate(ctx, &pb.ValidateSource_Request{
Spec: b,
})
if err != nil {
st, ok := status.FromError(err)
if ok && st.Code() == codes.Unimplemented {
// Backwards-compatibility with older plugin versions that don't support Validate().
// In this case, we only return one warning: that the plugin should be updated.
return []string{"the version of this plugin is outdated and should be updated"}, nil, nil
}
return nil, nil, fmt.Errorf("failed to call Validate: %w", err)
}
return resp.Warnings, resp.Errors, nil
}

// Sync start syncing for the source client per the given spec and returning the results
// in the given channel. res is marshaled schema.Resource. We are not unmarshalling this for performance reasons
// as usually this is sent over-the-wire anyway to a destination plugin
Expand Down
2 changes: 1 addition & 1 deletion internal/pb/base.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading