Skip to content

Commit addd6c8

Browse files
authored
feat: Add Name() to source and destination clients (#29)
* feat: add Name() to source and destination clients * Add separate name and version grpc calls
1 parent 70e59fb commit addd6c8

File tree

14 files changed

+759
-197
lines changed

14 files changed

+759
-197
lines changed

clients/destination.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
type DestinationClient struct {
1616
pbClient pb.DestinationClient
17-
// this can be used if we have a plugin which is compiled in so we dont need to do any grpc requests
17+
// this can be used if we have a plugin which is compiled in, so we don't need to do any grpc requests
1818
localClient plugins.DestinationPlugin
1919
}
2020

@@ -30,6 +30,28 @@ func NewLocalDestinationClient(p plugins.DestinationPlugin) *DestinationClient {
3030
}
3131
}
3232

33+
func (c *DestinationClient) Name(ctx context.Context) (string, error) {
34+
if c.localClient != nil {
35+
return c.localClient.Name(), nil
36+
}
37+
res, err := c.pbClient.GetName(ctx, &pb.GetName_Request{})
38+
if err != nil {
39+
return "", fmt.Errorf("failed to get name: %w", err)
40+
}
41+
return res.Name, nil
42+
}
43+
44+
func (c *DestinationClient) Version(ctx context.Context) (string, error) {
45+
if c.localClient != nil {
46+
return c.localClient.Version(), nil
47+
}
48+
res, err := c.pbClient.GetVersion(ctx, &pb.GetVersion_Request{})
49+
if err != nil {
50+
return "", fmt.Errorf("failed to get version: %w", err)
51+
}
52+
return res.Version, nil
53+
}
54+
3355
func (c *DestinationClient) GetExampleConfig(ctx context.Context) (string, error) {
3456
if c.localClient != nil {
3557
return c.localClient.ExampleConfig(), nil

clients/source.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ func NewSourceClient(cc grpc.ClientConnInterface) *SourceClient {
2828
}
2929
}
3030

31-
func (c *SourceClient) GetTables(ctx context.Context) ([]*schema.Table, error) {
32-
res, err := c.pbClient.GetTables(ctx, &pb.GetTables_Request{})
31+
func (c *SourceClient) Name(ctx context.Context) (string, error) {
32+
res, err := c.pbClient.GetName(ctx, &pb.GetName_Request{})
3333
if err != nil {
34-
return nil, err
34+
return "", fmt.Errorf("failed to get name: %w", err)
3535
}
36-
var tables []*schema.Table
37-
if err := json.Unmarshal(res.Tables, &tables); err != nil {
38-
return nil, err
36+
return res.Name, nil
37+
}
38+
39+
func (c *SourceClient) Version(ctx context.Context) (string, error) {
40+
res, err := c.pbClient.GetVersion(ctx, &pb.GetVersion_Request{})
41+
if err != nil {
42+
return "", fmt.Errorf("failed to get version: %w", err)
3943
}
40-
return tables, nil
44+
return res.Version, nil
4145
}
4246

4347
func (c *SourceClient) ExampleConfig(ctx context.Context) (string, error) {
@@ -48,6 +52,18 @@ func (c *SourceClient) ExampleConfig(ctx context.Context) (string, error) {
4852
return res.Config, nil
4953
}
5054

55+
func (c *SourceClient) GetTables(ctx context.Context) ([]*schema.Table, error) {
56+
res, err := c.pbClient.GetTables(ctx, &pb.GetTables_Request{})
57+
if err != nil {
58+
return nil, err
59+
}
60+
var tables []*schema.Table
61+
if err := json.Unmarshal(res.Tables, &tables); err != nil {
62+
return nil, err
63+
}
64+
return tables, nil
65+
}
66+
5167
func (c *SourceClient) Sync(ctx context.Context, spec specs.Source, res chan<- *schema.Resource) error {
5268
b, err := json.Marshal(spec)
5369
if err != nil {

0 commit comments

Comments
 (0)