Skip to content

Commit

Permalink
Custom config for destinations (#100)
Browse files Browse the repository at this point in the history
* Custom config for destinations

* E2E tests for custom destination config
  • Loading branch information
beevital authored Jan 29, 2024
1 parent 32592ae commit 93e79cb
Show file tree
Hide file tree
Showing 12 changed files with 799 additions and 339 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v0.8.1...HEAD)
## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v0.8.2...HEAD)

## [0.8.2](https://github.com/fivetran/go-fivetran/compare/v0.8.1...v0.8.2)

## Added
Support for custom config (`map[string]interface{}`) for destinations:
- `DestinationCreateService.ConfigCustom` and `DestinationCreateService.DoCustom` methods
- `DestinationModifyService.ConfigCustom` and `DestinationModifyService.DoCustom` methods
- `DestinationDetailsService.DoCustom` method

## [0.8.1](https://github.com/fivetran/go-fivetran/compare/v0.8.0...v0.8.1)

Expand Down
32 changes: 16 additions & 16 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"fmt"
"net/http"

"github.com/fivetran/go-fivetran/connectors"
"github.com/fivetran/go-fivetran/certificates"
connectcard "github.com/fivetran/go-fivetran/connect_card"
"github.com/fivetran/go-fivetran/connectors"
"github.com/fivetran/go-fivetran/dbt"
"github.com/fivetran/go-fivetran/destinations"
externallogging "github.com/fivetran/go-fivetran/external_logging"
"github.com/fivetran/go-fivetran/fingerprints"
"github.com/fivetran/go-fivetran/groups"
httputils "github.com/fivetran/go-fivetran/http_utils"
privatelinks "github.com/fivetran/go-fivetran/private_links"
"github.com/fivetran/go-fivetran/roles"
"github.com/fivetran/go-fivetran/teams"
"github.com/fivetran/go-fivetran/users"
"github.com/fivetran/go-fivetran/external_logging"
"github.com/fivetran/go-fivetran/destinations"
"github.com/fivetran/go-fivetran/dbt"
"github.com/fivetran/go-fivetran/webhooks"
"github.com/fivetran/go-fivetran/teams"
"github.com/fivetran/go-fivetran/roles"
"github.com/fivetran/go-fivetran/connect_card"
"github.com/fivetran/go-fivetran/private_links"
httputils "github.com/fivetran/go-fivetran/http_utils"
)

// Client holds client configuration
Expand All @@ -35,7 +35,7 @@ const defaultBaseURL = "https://api.fivetran.com/v1"
const restAPIv2 = "application/json;version=2"

// WARNING: Update Agent version on each release!
const defaultUserAgent = "Go-Fivetran/0.7.8"
const defaultUserAgent = "Go-Fivetran/0.8.2"

// New receives API Key and API Secret, and returns a new Client with the
// default HTTP client
Expand Down Expand Up @@ -523,7 +523,7 @@ func (c *Client) NewRolesList() *roles.RolesListService {
}

func (c *Client) NewConnectCard() *connectcard.ConnectCardService {
return &connectcard.ConnectCardService{HttpService: c.NewHttpService()}
return &connectcard.ConnectCardService{HttpService: c.NewHttpService()}
}

/* Connectors */
Expand All @@ -550,15 +550,15 @@ func (c *Client) NewConnectorSetupTests() *connectors.ConnectorSetupTestsService
}

func (c *Client) NewConnectorColumnConfigListService() *connectors.ConnectorColumnConfigListService {
return &connectors.ConnectorColumnConfigListService{HttpService: c.NewHttpService()}
return &connectors.ConnectorColumnConfigListService{HttpService: c.NewHttpService()}
}

func (c *Client) NewConnectorColumnConfigModifyService() *connectors.ConnectorColumnConfigModifyService {
return &connectors.ConnectorColumnConfigModifyService{HttpService: c.NewHttpService()}
return &connectors.ConnectorColumnConfigModifyService{HttpService: c.NewHttpService()}
}

func (c *Client) NewConnectorDatabaseSchemaConfigModifyService() *connectors.ConnectorDatabaseSchemaConfigModifyService {
return &connectors.ConnectorDatabaseSchemaConfigModifyService{HttpService: c.NewHttpService()}
return &connectors.ConnectorDatabaseSchemaConfigModifyService{HttpService: c.NewHttpService()}
}

func (c *Client) NewConnectorReSyncTable() *connectors.ConnectorReSyncTableService {
Expand All @@ -578,7 +578,7 @@ func (c *Client) NewConnectorSchemaUpdateService() *connectors.ConnectorSchemaCo
}

func (c *Client) NewConnectorTableConfigModifyService() *connectors.ConnectorTableConfigModifyService {
return &connectors.ConnectorTableConfigModifyService{HttpService: c.NewHttpService()}
return &connectors.ConnectorTableConfigModifyService{HttpService: c.NewHttpService()}
}

func (c *Client) NewConnectorsSourceMetadata() *connectors.ConnectorsSourceMetadataService {
Expand All @@ -600,4 +600,4 @@ func (c *Client) NewPrivateLinksDetails() *privatelinks.PrivateLinksDetailsServi

func (c *Client) NewPrivateLinksModify() *privatelinks.PrivateLinksModifyService {
return &privatelinks.PrivateLinksModifyService{HttpService: c.NewHttpService()}
}
}
43 changes: 32 additions & 11 deletions destinations/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,48 @@ package destinations
import "github.com/fivetran/go-fivetran/common"

type DestinationDetailsBase struct {
ID string `json:"id"`
GroupID string `json:"group_id"`
Service string `json:"service"`
Region string `json:"region"`
TimeZoneOffset string `json:"time_zone_offset"`
SetupStatus string `json:"setup_status"`
Config DestinationConfigResponse `json:"config"`
ID string `json:"id"`
GroupID string `json:"group_id"`
Service string `json:"service"`
Region string `json:"region"`
TimeZoneOffset string `json:"time_zone_offset"`
SetupStatus string `json:"setup_status"`
}

type DestinationDetailsWithSetupTestsResponse struct {
common.CommonResponse
Data struct {
DestinationDetailsBase
Config DestinationConfigResponse `json:"config"`
SetupTests []common.SetupTestResponse `json:"setup_tests"`
} `json:"data"`
}

type DestinationDetailsWithSetupTestsCustomResponse struct {
common.CommonResponse
Data struct {
DestinationDetailsBase
Config map[string]interface{} `json:"config"`
SetupTests []common.SetupTestResponse `json:"setup_tests"`
} `json:"data"`
}

type DestinationDetailsResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data DestinationDetailsBase `json:"data"`
Code string `json:"code"`
Message string `json:"message"`
Data struct {
DestinationDetailsBase
Config DestinationConfigResponse `json:"config"`
} `json:"data"`
}

type DestinationDetailsCustomResponse struct {
Code string `json:"code"`
Message string `json:"message"`
Data struct {
DestinationDetailsBase
Config map[string]interface{} `json:"config"`
} `json:"data"`
}

type destinationCreateRequest struct {
Expand All @@ -49,4 +70,4 @@ type destinationModifyRequest struct {
type destinationSetupTestsRequest struct {
TrustCertificates *bool `json:"trust_certificates,omitempty"`
TrustFingerprints *bool `json:"trust_fingerprints,omitempty"`
}
}
61 changes: 43 additions & 18 deletions destinations/destination_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,12 @@ type DestinationCreateService struct {
region *string
timeZoneOffset *string
config *DestinationConfig
configCustom *map[string]interface{}
trustCertificates *bool
trustFingerprints *bool
runSetupTests *bool
}

func (s *DestinationCreateService) request() *destinationCreateRequest {
var config interface{}
if s.config != nil {
config = s.config.Request()
}

return &destinationCreateRequest{
GroupID: s.groupID,
Service: s.service,
Region: s.region,
TimeZoneOffset: s.timeZoneOffset,
Config: config,
TrustCertificates: s.trustCertificates,
TrustFingerprints: s.trustFingerprints,
RunSetupTests: s.runSetupTests,
}
}

func (s *DestinationCreateService) GroupID(value string) *DestinationCreateService {
s.groupID = &value
return s
Expand All @@ -63,6 +46,11 @@ func (s *DestinationCreateService) Config(value *DestinationConfig) *Destination
return s
}

func (s *DestinationCreateService) ConfigCustom(value *map[string]interface{}) *DestinationCreateService {
s.configCustom = value
return s
}

func (s *DestinationCreateService) TrustCertificates(value bool) *DestinationCreateService {
s.trustCertificates = &value
return s
Expand All @@ -83,3 +71,40 @@ func (s *DestinationCreateService) Do(ctx context.Context) (DestinationDetailsWi
err := s.HttpService.Do(ctx, "POST", "/destinations", s.request(), nil, 201, &response)
return response, err
}

func (s *DestinationCreateService) DoCustom(ctx context.Context) (DestinationDetailsWithSetupTestsCustomResponse, error) {
var response DestinationDetailsWithSetupTestsCustomResponse
err := s.HttpService.Do(ctx, "POST", "/destinations", s.requestCustom(), nil, 201, &response)
return response, err
}

func (s *DestinationCreateService) request() *destinationCreateRequest {
var config interface{}
if s.config != nil {
config = s.config.Request()
}

return &destinationCreateRequest{
GroupID: s.groupID,
Service: s.service,
Region: s.region,
TimeZoneOffset: s.timeZoneOffset,
Config: config,
TrustCertificates: s.trustCertificates,
TrustFingerprints: s.trustFingerprints,
RunSetupTests: s.runSetupTests,
}
}

func (s *DestinationCreateService) requestCustom() *destinationCreateRequest {
return &destinationCreateRequest{
GroupID: s.groupID,
Service: s.service,
Region: s.region,
TimeZoneOffset: s.timeZoneOffset,
Config: s.configCustom,
TrustCertificates: s.trustCertificates,
TrustFingerprints: s.trustFingerprints,
RunSetupTests: s.runSetupTests,
}
}
Loading

0 comments on commit 93e79cb

Please sign in to comment.