Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

SDK Improvements #41

Merged
merged 12 commits into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 26 additions & 2 deletions cqproto/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cqproto

import (
"context"
"encoding/json"

"github.com/cloudquery/cq-provider-sdk/cqproto/internal"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
Expand Down Expand Up @@ -38,13 +39,19 @@ func (g GRPCClient) GetProviderConfig(ctx context.Context, _ *GetProviderConfigR
}

func (g GRPCClient) ConfigureProvider(ctx context.Context, request *ConfigureProviderRequest) (*ConfigureProviderResponse, error) {
fieldsData, err := json.Marshal(request.ExtraFields)
if err != nil {
return nil, err
}
res, err := g.client.ConfigureProvider(ctx, &internal.ConfigureProvider_Request{
CloudqueryVersion: request.CloudQueryVersion,
Connection: &internal.ConnectionDetails{
Type: internal.ConnectionType_POSTGRES,
Dsn: request.Connection.DSN,
},
Config: request.Config,
Config: request.Config,
DisableDelete: request.DisableDelete,
ExtraFields: fieldsData,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -102,13 +109,20 @@ func (g *GRPCServer) GetProviderConfig(ctx context.Context, _ *internal.GetProvi
}

func (g *GRPCServer) ConfigureProvider(ctx context.Context, request *internal.ConfigureProvider_Request) (*internal.ConfigureProvider_Response, error) {

var eFields = make(map[string]interface{})
if err := json.Unmarshal(request.GetExtraFields(), &eFields); err != nil {
roneli marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}
resp, err := g.Impl.ConfigureProvider(ctx, &ConfigureProviderRequest{
CloudQueryVersion: request.GetCloudqueryVersion(),
Connection: ConnectionDetails{
Type: string(request.Connection.GetType()),
DSN: request.Connection.GetDsn(),
},
Config: request.Config,
Config: request.Config,
DisableDelete: request.DisableDelete,
ExtraFields: eFields,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -161,11 +175,18 @@ func tableFromProto(v *internal.Table) *schema.Table {
for i, r := range v.GetRelations() {
rels[i] = tableFromProto(r)
}

var opts schema.TableCreationOptions
if o := v.GetOptions(); o != nil {
opts.PrimaryKeys = o.GetPrimaryKeys()
}

return &schema.Table{
Name: v.GetName(),
Description: v.GetDescription(),
Columns: cols,
Relations: rels,
Options: opts,
}
}

Expand Down Expand Up @@ -198,5 +219,8 @@ func tableToProto(in *schema.Table) *internal.Table {
Description: in.Description,
Columns: cols,
Relations: rels,
Options: &internal.TableCreationOptions{
PrimaryKeys: in.Options.PrimaryKeys,
},
}
}
Loading