diff --git a/CHANGELOG.md b/CHANGELOG.md index 89ffbe6b..ca00b7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,22 +5,79 @@ 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.4...HEAD) +## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v0.8.6...HEAD) -## [0.8.4](https://github.com/fivetran/go-fivetran/compare/v0.8.3...v0.8.4) +## [0.8.6](https://github.com/fivetran/go-fivetran/compare/v0.8.5...v0.8.6) + +## Added + +Supported the following Fivetran API endpoints for Local Processing Agent Management: +- [Create a Local Processing Agent](https://fivetran.com/docs/rest-api/local-processing-agent-management#createalocalprocessingagent) +- [List Local Processing Agents](/docs/rest-api/local-processing-agent-management#listlocalprocessingagents) +- [Retrieve Local Processing Agent Details](/docs/rest-api/local-processing-agent-management#retrievelocalprocessingagentdetails) +- [Delete a Local Processing Agent](/docs/rest-api/local-processing-agent-management#deletealocalprocessingagent) +- [Regenerate authentication keys for a Local Processing Agent](/docs/rest-api/local-processing-agent-management#regeneratekeys) + +Supported the following Fivetran API endpoints for Private Links Management:: +- [List all Private Links within Account](https://fivetran.com/docs/rest-api/private-links-management#listallprivatelinkswithinaccount) + +Added fields to support setting up Local Processing Agent in Destination API: +- `DestinationCreateService.localProcessingAgentId` +- `DestinationModifyService.localProcessingAgentId` +- `DestinationDetailsService.localProcessingAgentId` + +Added fields to support setting up Private Link in Destination API: +- `DestinationCreateService.privateLinkId` +- `DestinationModifyService.privateLinkId` +- `DestinationDetailsService.privateLinkId` + +Added fields to support setting up Networking Method in Destination API: +- `DestinationCreateService.networkingMethod` +- `DestinationModifyService.networkingMethod` +- `DestinationDetailsService.networkingMethod` + +Added fields to support setting up Local Processing Agent in Connector API: +- `ConnectorCreateService.localProcessingAgentId` +- `ConnectorModifyService.localProcessingAgentId` +- `ConnectorDetailsService.localProcessingAgentId` + +Added fields to support setting up Proxy Agent in Connector API: +- `ConnectorCreateService.proxyAgentId` +- `ConnectorModifyService.proxyAgentId` +- `ConnectorDetailsService.proxyAgentId` + +Added fields to support setting up Private Link in Connector API: +- `ConnectorCreateService.privateLinkId` +- `ConnectorModifyService.privateLinkId` +- `ConnectorDetailsService.privateLinkId` + +Added fields to support setting up Networking Method in Connector API: +- `ConnectorCreateService.networkingMethod` +- `ConnectorModifyService.networkingMethod` +- `ConnectorDetailsService.networkingMethod` + +## Removed +Removed the following deprecated Fivetran API endpoints for Proxy Agents Management: +- [Attach connection to the proxy agent](https://fivetran.com/docs/rest-api/proxy-management#attachconnectiontotheproxyagent) +- [Detach connection from the proxy agent](https://fivetran.com/docs/rest-api/proxy-management#detachconnectionformtheproxyagent) + +Removed the following deprecated Fivetran API endpoints for Private Links Management: +- [List all Private Links within Group](https://fivetran.com/docs/rest-api/private-links-management#listallprivatelinkswithingroup) + +## [0.8.5](https://github.com/fivetran/go-fivetran/compare/v0.8.4...v0.8.5) ## Added Supported the following Fivetran API endpoints for Proxy Agents Management: -- [Create a Proxy Agent](/docs/rest-api/proxy-management#createaproxyagent) -- [List all Proxy Agents](/docs/rest-api/proxy-management#listallproxyagents) -- [Retrieve Proxy Agent Details](/docs/rest-api/proxy-management#retrieveproxyagentdetails) -- [Delete a Proxy Agent](/docs/rest-api/proxy-management#deleteaproxyagent) -- [Return all connections attached to the proxy agent](/docs/rest-api/proxy-management#returnsallconnectionsattachedtotheproxyagent) -- [Attach connection to the proxy agent](/docs/rest-api/proxy-management#attachconnectiontotheproxyagent) -- [Detach connection from the proxy agent](/docs/rest-api/proxy-management#detachconnectionformtheproxyagent) +- [Create a Proxy Agent](https://fivetran.com/docs/rest-api/proxy-management#createaproxyagent) +- [List all Proxy Agents](https://fivetran.com/docs/rest-api/proxy-management#listallproxyagents) +- [Retrieve Proxy Agent Details](https://fivetran.com/docs/rest-api/proxy-management#retrieveproxyagentdetails) +- [Delete a Proxy Agent](https://fivetran.com/docs/rest-api/proxy-management#deleteaproxyagent) +- [Return all connections attached to the proxy agent](https://fivetran.com/docs/rest-api/proxy-management#returnsallconnectionsattachedtotheproxyagent) +- [Attach connection to the proxy agent](https://fivetran.com/docs/rest-api/proxy-management#attachconnectiontotheproxyagent) +- [Detach connection from the proxy agent](https://fivetran.com/docs/rest-api/proxy-management#detachconnectionformtheproxyagent) -## [0.8.3](https://github.com/fivetran/go-fivetran/compare/v0.8.2...v0.8.3) +## [0.8.4](https://github.com/fivetran/go-fivetran/compare/v0.8.3...v0.8.4) ## Added Added fields to support Shift my UTC offset with daylight savings time (US Only) in Destination API: @@ -30,7 +87,7 @@ Added fields to support Shift my UTC offset with daylight savings time (US Only) Removed unneccessary field `service` from Private Links API `PrivateLinksCreateService` -## [0.8.2](https://github.com/fivetran/go-fivetran/compare/v0.8.1...v0.8.2) +## [0.8.3](https://github.com/fivetran/go-fivetran/compare/v0.8.2...v0.8.3) ## Added Support for custom config (`map[string]interface{}`) for destinations: @@ -38,7 +95,7 @@ Support for custom config (`map[string]interface{}`) for destinations: - `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) +## [0.8.2](https://github.com/fivetran/go-fivetran/compare/v0.8.0...v0.8.2) ## Added diff --git a/README.md b/README.md index e77c99f8..ebab7cd8 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,7 @@ REST API Endpoint | REST API Version | SDK Service/Config REST API Endpoint | REST API Version | SDK Service/Config --- | --- | --- [Create a Private Link](https://fivetran.com/docs/rest-api/private-links-management#createaprivatelink) | v1 | [PrivateLinksCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksCreateService) -[List all Private Links within Group](https://fivetran.com/docs/rest-api/private-links-management#listallprivatelinkswithingroup) | v1 | [GroupListPrivateLinksService](https://pkg.go.dev/github.com/fivetran/go-fivetran#GroupListPrivateLinksService) +[List all Private Links within Account](https://fivetran.com/docs/rest-api/private-links-management#listallprivatelinkswithinaccount) | v1 | [PrivateLinkListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinkListService) [Retrieve Private Link Details](https://fivetran.com/docs/rest-api/private-links-management#retrieveprivatelinkdetails) | v1 | [PrivateLinksDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksDetailsService) [Update a Private Link](https://fivetran.com/docs/rest-api/private-links-management#updateaprivatelink) | v1 | [PrivateLinksModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksModifyService) [Delete a Private Link](https://fivetran.com/docs/rest-api/private-links-management#deleteaprivatelink) | v1 | [PrivateLinksDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#PrivateLinksDeleteService) @@ -272,8 +272,15 @@ REST API Endpoint | REST API Version | SDK Service/Config [Retrieve Proxy Agent Details](/docs/rest-api/proxy-management#retrieveproxyagentdetails) | v1 | [ProxyDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyDetailsService) [Delete a Proxy Agent](/docs/rest-api/proxy-management#deleteaproxyagent) | v1 | [ProxyDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyDeleteService) [Return all connections attached to the proxy agent](/docs/rest-api/proxy-management#returnsallconnectionsattachedtotheproxyagent) | v1 | [ProxyConnectionMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyConnectionMembershipsListService) -[Attach connection to the proxy agent](/docs/rest-api/proxy-management#attachconnectiontotheproxyagent) | v1 | [ProxyConnectionMembershipCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyConnectionMembershipCreateService) -[Detach connection from the proxy agent](/docs/rest-api/proxy-management#detachconnectionformtheproxyagent) | v1 | [ProxyConnectionMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyConnectionMembershipDeleteService) + +### [Local Processing Agent Management](https://fivetran.com/docs/rest-api/local-processing-agent-management#localprocessingagentmanagement) +REST API Endpoint | REST API Version | SDK Service/Config +--- | --- | --- +[Create a Local Processing Agent](https://fivetran.com/docs/rest-api/local-processing-agent-management#createalocalprocessingagent) | v1 | [LocalProcessingAgentCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#LocalProcessingAgentCreateService) +[List Local Processing Agents](/docs/rest-api/local-processing-agent-management#listlocalprocessingagents) | v1 | [LocalProcessingAgentListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#LocalProcessingAgentListService) +[Retrieve Local Processing Agent Details](/docs/rest-api/local-processing-agent-management#retrievelocalprocessingagentdetails) | v1 | [LocalProcessingAgentDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#LocalProcessingAgentDetailsService) +[Delete a Local Processing Agent](/docs/rest-api/local-processing-agent-management#deletealocalprocessingagent) | v1 | [LocalProcessingAgentDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#LocalProcessingAgentDeleteService) +[Regenerate authentication keys for a Local Processing Agent](/docs/rest-api/local-processing-agent-management#regeneratekeys) | v1 | [LocalProcessingAgentReAuthService](https://pkg.go.dev/github.com/fivetran/go-fivetran#LocalProcessingAgentReAuthService) ## Support diff --git a/client.go b/client.go index c9b0e738..8b2d6541 100644 --- a/client.go +++ b/client.go @@ -14,7 +14,8 @@ import ( "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" + privatelink "github.com/fivetran/go-fivetran/private_link" + localprocessingagent "github.com/fivetran/go-fivetran/local_processing_agent" "github.com/fivetran/go-fivetran/roles" "github.com/fivetran/go-fivetran/teams" "github.com/fivetran/go-fivetran/users" @@ -36,7 +37,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.8.4" +const defaultUserAgent = "Go-Fivetran/0.8.6" // New receives API Key and API Secret, and returns a new Client with the // default HTTP client @@ -233,10 +234,6 @@ func (c *Client) NewGroupListUsers() *groups.GroupListUsersService { return &groups.GroupListUsersService{HttpService: c.NewHttpService()} } -func (c *Client) NewGroupListPrivateLinks() *groups.GroupListPrivateLinksService { - return &groups.GroupListPrivateLinksService{HttpService: c.NewHttpService()} -} - func (c *Client) NewGroupsList() *groups.GroupsListService { return &groups.GroupsListService{HttpService: c.NewHttpService()} } @@ -587,20 +584,24 @@ func (c *Client) NewConnectorsSourceMetadata() *connectors.ConnectorsSourceMetad } /* Private Links */ -func (c *Client) NewPrivateLinksCreate() *privatelinks.PrivateLinksCreateService { - return &privatelinks.PrivateLinksCreateService{HttpService: c.NewHttpService()} +func (c *Client) NewPrivateLinkCreate() *privatelink.PrivateLinkCreateService { + return &privatelink.PrivateLinkCreateService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewPrivateLinkDelete() *privatelink.PrivateLinkDeleteService { + return &privatelink.PrivateLinkDeleteService{HttpService: c.NewHttpService()} } -func (c *Client) NewPrivateLinksDelete() *privatelinks.PrivateLinksDeleteService { - return &privatelinks.PrivateLinksDeleteService{HttpService: c.NewHttpService()} +func (c *Client) NewPrivateLinkList() *privatelink.PrivateLinkListService { + return &privatelink.PrivateLinkListService{HttpService: c.NewHttpService()} } -func (c *Client) NewPrivateLinksDetails() *privatelinks.PrivateLinksDetailsService { - return &privatelinks.PrivateLinksDetailsService{HttpService: c.NewHttpService()} +func (c *Client) NewPrivateLinkDetails() *privatelink.PrivateLinkDetailsService { + return &privatelink.PrivateLinkDetailsService{HttpService: c.NewHttpService()} } -func (c *Client) NewPrivateLinksModify() *privatelinks.PrivateLinksModifyService { - return &privatelinks.PrivateLinksModifyService{HttpService: c.NewHttpService()} +func (c *Client) NewPrivateLinkModify() *privatelink.PrivateLinkModifyService { + return &privatelink.PrivateLinkModifyService{HttpService: c.NewHttpService()} } /* Proxy */ @@ -620,14 +621,27 @@ func (c *Client) NewProxyDelete() *proxy.ProxyDeleteService { return &proxy.ProxyDeleteService{HttpService: c.NewHttpService()} } -func (c *Client) NewProxyConnectionMembershipCreate() *proxy.ProxyConnectionMembershipCreateService { - return &proxy.ProxyConnectionMembershipCreateService{HttpService: c.NewHttpService()} -} - func (c *Client) NewProxyConnectionMembershipsList() *proxy.ProxyConnectionMembershipsListService { return &proxy.ProxyConnectionMembershipsListService{HttpService: c.NewHttpService()} } -func (c *Client) NewProxyConnectionMembershipDelete() *proxy.ProxyConnectionMembershipDeleteService { - return &proxy.ProxyConnectionMembershipDeleteService{HttpService: c.NewHttpService()} +/* Local Processing Agent */ +func (c *Client) NewLocalProcessingAgentCreate() *localprocessingagent.LocalProcessingAgentCreateService { + return &localprocessingagent.LocalProcessingAgentCreateService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewLocalProcessingAgentDelete() *localprocessingagent.LocalProcessingAgentDeleteService { + return &localprocessingagent.LocalProcessingAgentDeleteService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewLocalProcessingAgentDetails() *localprocessingagent.LocalProcessingAgentDetailsService { + return &localprocessingagent.LocalProcessingAgentDetailsService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewLocalProcessingAgentList() *localprocessingagent.LocalProcessingAgentListService { + return &localprocessingagent.LocalProcessingAgentListService{HttpService: c.NewHttpService()} +} + +func (c *Client) NewLocalProcessingAgentReAuth() *localprocessingagent.LocalProcessingAgentReAuthService { + return &localprocessingagent.LocalProcessingAgentReAuthService{HttpService: c.NewHttpService()} } \ No newline at end of file diff --git a/connectors/common_types.go b/connectors/common_types.go index e174cb13..4c58283e 100644 --- a/connectors/common_types.go +++ b/connectors/common_types.go @@ -1,123 +1,131 @@ package connectors import ( - "time" + "time" - "github.com/fivetran/go-fivetran/common" + "github.com/fivetran/go-fivetran/common" ) type DetailsResponseDataCommon struct { - ID string `json:"id"` - GroupID string `json:"group_id"` - Service string `json:"service"` - ServiceVersion *int `json:"service_version"` - Schema string `json:"schema"` - ConnectedBy string `json:"connected_by"` - CreatedAt time.Time `json:"created_at"` - SucceededAt time.Time `json:"succeeded_at"` - FailedAt time.Time `json:"failed_at"` - SyncFrequency *int `json:"sync_frequency"` - ScheduleType string `json:"schedule_type"` - Paused *bool `json:"paused"` - PauseAfterTrial *bool `json:"pause_after_trial"` - DailySyncTime string `json:"daily_sync_time"` - Status StatusResponse `json:"status"` + ID string `json:"id"` + GroupID string `json:"group_id"` + Service string `json:"service"` + ServiceVersion *int `json:"service_version"` + Schema string `json:"schema"` + ConnectedBy string `json:"connected_by"` + CreatedAt time.Time `json:"created_at"` + SucceededAt time.Time `json:"succeeded_at"` + FailedAt time.Time `json:"failed_at"` + SyncFrequency *int `json:"sync_frequency"` + ScheduleType string `json:"schedule_type"` + Paused *bool `json:"paused"` + PauseAfterTrial *bool `json:"pause_after_trial"` + DailySyncTime string `json:"daily_sync_time"` + PrivateLinkId string `json:"private_link_id"` + LocalProcessingAgentId string `json:"local_processing_agent_id"` + ProxyAgentId string `json:"proxy_agent_id"` + NetworkingMethod string `json:"networking_method"` + Status StatusResponse `json:"status"` } type DetailsAndSetupTestsResponseDataCommon struct { - DetailsResponseDataCommon - SetupTests []common.SetupTestResponse `json:"setup_tests"` + DetailsResponseDataCommon + SetupTests []common.SetupTestResponse `json:"setup_tests"` } type StatusResponse struct { - SetupState string `json:"setup_state"` - SyncState string `json:"sync_state"` - UpdateState string `json:"update_state"` - IsHistoricalSync *bool `json:"is_historical_sync"` - Tasks []common.CommonResponse `json:"tasks"` - Warnings []common.CommonResponse `json:"warnings"` + SetupState string `json:"setup_state"` + SyncState string `json:"sync_state"` + UpdateState string `json:"update_state"` + IsHistoricalSync *bool `json:"is_historical_sync"` + Tasks []common.CommonResponse `json:"tasks"` + Warnings []common.CommonResponse `json:"warnings"` } type DetailsWithConfigResponse struct { - common.CommonResponse - Data struct { - DetailsAndSetupTestsResponseDataCommon - Config ConnectorConfigResponse `json:"config"` - } `json:"data"` + common.CommonResponse + Data struct { + DetailsAndSetupTestsResponseDataCommon + Config ConnectorConfigResponse `json:"config"` + } `json:"data"` } type DetailsWithCustomConfigResponse struct { - common.CommonResponse - Data struct { - DetailsAndSetupTestsResponseDataCommon - Config map[string]interface{} `json:"config"` - } `json:"data"` + common.CommonResponse + Data struct { + DetailsAndSetupTestsResponseDataCommon + Config map[string]interface{} `json:"config"` + } `json:"data"` } type DetailsWithCustomMergedConfigResponse struct { - common.CommonResponse - Data struct { - DetailsAndSetupTestsResponseDataCommon - CustomConfig map[string]interface{} `json:"config"` - Config ConnectorConfigResponse // no mapping here - } `json:"data"` + common.CommonResponse + Data struct { + DetailsAndSetupTestsResponseDataCommon + CustomConfig map[string]interface{} `json:"config"` + Config ConnectorConfigResponse // no mapping here + } `json:"data"` } type DetailsWithConfigNoTestsResponse struct { - common.CommonResponse - Data struct { - DetailsResponseDataCommon - Config ConnectorConfigResponse `json:"config"` - } `json:"data"` + common.CommonResponse + Data struct { + DetailsResponseDataCommon + Config ConnectorConfigResponse `json:"config"` + } `json:"data"` } type DetailsWithCustomConfigNoTestsResponse struct { - common.CommonResponse - Data struct { - DetailsResponseDataCommon - Config map[string]interface{} `json:"config"` - } `json:"data"` + common.CommonResponse + Data struct { + DetailsResponseDataCommon + Config map[string]interface{} `json:"config"` + } `json:"data"` } type DetailsWithCustomMergedConfigNoTestsResponse struct { - common.CommonResponse - Data struct { - DetailsResponseDataCommon - CustomConfig map[string]interface{} `json:"config"` - Config ConnectorConfigResponse // no mapping here - } `json:"data"` + common.CommonResponse + Data struct { + DetailsResponseDataCommon + CustomConfig map[string]interface{} `json:"config"` + Config ConnectorConfigResponse // no mapping here + } `json:"data"` } type ConnectorSchemaDetailsResponse struct { - common.CommonResponse - Data struct { - SchemaChangeHandling string `json:"schema_change_handling"` - Schemas map[string]*ConnectorSchemaConfigSchemaResponse `json:"schemas"` - } `json:"data"` + common.CommonResponse + Data struct { + SchemaChangeHandling string `json:"schema_change_handling"` + Schemas map[string]*ConnectorSchemaConfigSchemaResponse `json:"schemas"` + } `json:"data"` } type connectorCreateRequestBase struct { - Service *string `json:"service,omitempty"` - GroupID *string `json:"group_id,omitempty"` - TrustCertificates *bool `json:"trust_certificates,omitempty"` - TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` - RunSetupTests *bool `json:"run_setup_tests,omitempty"` - Paused *bool `json:"paused,omitempty"` - SyncFrequency *int `json:"sync_frequency,omitempty"` - DailySyncTime *string `json:"daily_sync_time,omitempty"` - PauseAfterTrial *bool `json:"pause_after_trial,omitempty"` + Service *string `json:"service,omitempty"` + GroupID *string `json:"group_id,omitempty"` + TrustCertificates *bool `json:"trust_certificates,omitempty"` + TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` + RunSetupTests *bool `json:"run_setup_tests,omitempty"` + Paused *bool `json:"paused,omitempty"` + SyncFrequency *int `json:"sync_frequency,omitempty"` + DailySyncTime *string `json:"daily_sync_time,omitempty"` + PauseAfterTrial *bool `json:"pause_after_trial,omitempty"` + ProxyAgentId *string `json:"proxy_agent_id,omitempty"` + PrivateLinkId *string `json:"private_link_id,omitempty"` + LocalProcessingAgentId *string `json:"local_processing_agent_id,omitempty"` + NetworkingMethod *string `json:"networking_method,omitempty"` } type connectorCreateRequest struct { - connectorCreateRequestBase - Config any `json:"config,omitempty"` - Auth any `json:"auth,omitempty"` + connectorCreateRequestBase + Config any `json:"config,omitempty"` + Auth any `json:"auth,omitempty"` } type connectorCustomCreateRequest struct { - connectorCreateRequestBase - Config *map[string]interface{} `json:"config,omitempty"` - Auth *map[string]interface{} `json:"auth,omitempty"` + connectorCreateRequestBase + Config *map[string]interface{} `json:"config,omitempty"` + Auth *map[string]interface{} `json:"auth,omitempty"` } type connectorSchemaConfigModifyRequest struct { @@ -137,43 +145,47 @@ type connectorColumnConfigModifyRequest struct { } type connectorModifyRequestBase struct { - Paused *bool `json:"paused,omitempty"` - SyncFrequency *int `json:"sync_frequency,omitempty"` - DailySyncTime *string `json:"daily_sync_time,omitempty"` - TrustCertificates *bool `json:"trust_certificates,omitempty"` - TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` - IsHistoricalSync *bool `json:"is_historical_sync,omitempty"` - ScheduleType *string `json:"schedule_type,omitempty"` - RunSetupTests *bool `json:"run_setup_tests,omitempty"` - PauseAfterTrial *bool `json:"pause_after_trial,omitempty"` + Paused *bool `json:"paused,omitempty"` + SyncFrequency *int `json:"sync_frequency,omitempty"` + DailySyncTime *string `json:"daily_sync_time,omitempty"` + TrustCertificates *bool `json:"trust_certificates,omitempty"` + TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` + IsHistoricalSync *bool `json:"is_historical_sync,omitempty"` + ScheduleType *string `json:"schedule_type,omitempty"` + RunSetupTests *bool `json:"run_setup_tests,omitempty"` + PauseAfterTrial *bool `json:"pause_after_trial,omitempty"` + ProxyAgentId *string `json:"proxy_agent_id,omitempty"` + PrivateLinkId *string `json:"private_link_id,omitempty"` + LocalProcessingAgentId *string `json:"local_processing_agent_id,omitempty"` + NetworkingMethod *string `json:"networking_method,omitempty"` } type connectorModifyRequest struct { - connectorModifyRequestBase - Config any `json:"config,omitempty"` - Auth any `json:"auth,omitempty"` + connectorModifyRequestBase + Config any `json:"config,omitempty"` + Auth any `json:"auth,omitempty"` } type connectorCustomModifyRequest struct { - connectorModifyRequestBase - Config *map[string]interface{} `json:"config,omitempty"` - Auth *map[string]interface{} `json:"auth,omitempty"` + connectorModifyRequestBase + Config *map[string]interface{} `json:"config,omitempty"` + Auth *map[string]interface{} `json:"auth,omitempty"` } type connectorSchemaReloadRequest struct { - ExcludeMode *string `json:"exclude_mode,omitempty"` + ExcludeMode *string `json:"exclude_mode,omitempty"` } type connectorSchemaConfigUpdateRequest struct { - SchemaChangeHandling *string `json:"schema_change_handling,omitempty"` - Schemas map[string]*ConnectorSchemaConfigSchemaRequest `json:"schemas,omitempty"` + SchemaChangeHandling *string `json:"schema_change_handling,omitempty"` + Schemas map[string]*ConnectorSchemaConfigSchemaRequest `json:"schemas,omitempty"` } type connectorSetupTestsRequest struct { - TrustCertificates *bool `json:"trust_certificates,omitempty"` - TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` + TrustCertificates *bool `json:"trust_certificates,omitempty"` + TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` } @@ -184,17 +196,17 @@ type connectorTableConfigModifyRequest struct { } type ConnectorsSourceMetadataResponse struct { - common.CommonResponse - Data struct { - Items []struct { - ID string `json:"id"` - Name string `json:"name"` - Type string `json:"type"` - Description string `json:"description"` - IconURL string `json:"icon_url"` - LinkToDocs string `json:"link_to_docs"` - LinkToErd string `json:"link_to_erd"` - } `json:"items"` - NextCursor string `json:"next_cursor"` - } `json:"data"` + common.CommonResponse + Data struct { + Items []struct { + ID string `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + Description string `json:"description"` + IconURL string `json:"icon_url"` + LinkToDocs string `json:"link_to_docs"` + LinkToErd string `json:"link_to_erd"` + } `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` } diff --git a/connectors/connector_create.go b/connectors/connector_create.go index e2457734..f51933e7 100644 --- a/connectors/connector_create.go +++ b/connectors/connector_create.go @@ -1,10 +1,10 @@ package connectors import ( - "context" + "context" - "github.com/fivetran/go-fivetran/utils" - httputils "github.com/fivetran/go-fivetran/http_utils" + "github.com/fivetran/go-fivetran/utils" + httputils "github.com/fivetran/go-fivetran/http_utils" ) // ConnectorCreateService implements the Connector Management, Create a Connector API. @@ -12,190 +12,218 @@ import ( type ConnectorCreateService struct { httputils.HttpService - service *string - groupID *string - trustCertificates *bool - trustFingerprints *bool - runSetupTests *bool - paused *bool - syncFrequency *int - dailySyncTime *string - pauseAfterTrial *bool - config *ConnectorConfig - auth *ConnectorAuth - configCustom *map[string]interface{} - authCustom *map[string]interface{} + service *string + groupID *string + trustCertificates *bool + trustFingerprints *bool + runSetupTests *bool + paused *bool + syncFrequency *int + dailySyncTime *string + pauseAfterTrial *bool + localProcessingAgentId *string + networkingMethod *string + privateLinkId *string + proxyAgentId *string + config *ConnectorConfig + auth *ConnectorAuth + configCustom *map[string]interface{} + authCustom *map[string]interface{} } func (s *ConnectorCreateService) requestBase() connectorCreateRequestBase { - return connectorCreateRequestBase{ - Service: s.service, - GroupID: s.groupID, - TrustCertificates: s.trustCertificates, - TrustFingerprints: s.trustFingerprints, - RunSetupTests: s.runSetupTests, - Paused: s.paused, - SyncFrequency: s.syncFrequency, - DailySyncTime: s.dailySyncTime, - PauseAfterTrial: s.pauseAfterTrial, - } + return connectorCreateRequestBase{ + Service: s.service, + GroupID: s.groupID, + TrustCertificates: s.trustCertificates, + TrustFingerprints: s.trustFingerprints, + RunSetupTests: s.runSetupTests, + Paused: s.paused, + SyncFrequency: s.syncFrequency, + DailySyncTime: s.dailySyncTime, + PauseAfterTrial: s.pauseAfterTrial, + PrivateLinkId: s.privateLinkId, + LocalProcessingAgentId: s.localProcessingAgentId, + NetworkingMethod: s.networkingMethod, + ProxyAgentId: s.proxyAgentId, + } } func (s *ConnectorCreateService) request() *connectorCreateRequest { - var config interface{} - if s.config != nil { - config = s.config.Request() - } + var config interface{} + if s.config != nil { + config = s.config.Request() + } - var auth interface{} - if s.auth != nil { - auth = s.auth.Request() - } + var auth interface{} + if s.auth != nil { + auth = s.auth.Request() + } - r := &connectorCreateRequest{ - connectorCreateRequestBase: s.requestBase(), - Config: config, - Auth: auth, - } + r := &connectorCreateRequest{ + connectorCreateRequestBase: s.requestBase(), + Config: config, + Auth: auth, + } - return r + return r } func (s *ConnectorCreateService) requestCustom() *connectorCustomCreateRequest { - return &connectorCustomCreateRequest{ - connectorCreateRequestBase: s.requestBase(), - Config: s.configCustom, - Auth: s.authCustom, - } + return &connectorCustomCreateRequest{ + connectorCreateRequestBase: s.requestBase(), + Config: s.configCustom, + Auth: s.authCustom, + } } func (s *ConnectorCreateService) requestCustomMerged() (*connectorCustomCreateRequest, error) { - currentConfig := s.configCustom - - if s.config != nil { - var err error - currentConfig, err = s.config.Merge(currentConfig) - if err != nil { - return nil, err - } - } - - currentAuth := s.authCustom - if s.auth != nil { - var err error - currentAuth, err = s.auth.Merge(currentAuth) - if err != nil { - return nil, err - } - } - - return &connectorCustomCreateRequest{ - connectorCreateRequestBase: s.requestBase(), - Config: currentConfig, - Auth: currentAuth, - }, nil + currentConfig := s.configCustom + + if s.config != nil { + var err error + currentConfig, err = s.config.Merge(currentConfig) + if err != nil { + return nil, err + } + } + + currentAuth := s.authCustom + if s.auth != nil { + var err error + currentAuth, err = s.auth.Merge(currentAuth) + if err != nil { + return nil, err + } + } + + return &connectorCustomCreateRequest{ + connectorCreateRequestBase: s.requestBase(), + Config: currentConfig, + Auth: currentAuth, + }, nil } func (s *ConnectorCreateService) Service(value string) *ConnectorCreateService { - s.service = &value - return s + s.service = &value + return s } func (s *ConnectorCreateService) GroupID(value string) *ConnectorCreateService { - s.groupID = &value - return s + s.groupID = &value + return s +} + +func (s *ConnectorCreateService) LocalProcessingAgentId(value string) *ConnectorCreateService { + s.localProcessingAgentId = &value + return s +} + +func (s *ConnectorCreateService) ProxyAgentId(value string) *ConnectorCreateService { + s.proxyAgentId = &value + return s +} + +func (s *ConnectorCreateService) PrivateLinkId(value string) *ConnectorCreateService { + s.privateLinkId = &value + return s +} + +func (s *ConnectorCreateService) NetworkingMethod(value string) *ConnectorCreateService { + s.networkingMethod = &value + return s } func (s *ConnectorCreateService) TrustCertificates(value bool) *ConnectorCreateService { - s.trustCertificates = &value - return s + s.trustCertificates = &value + return s } func (s *ConnectorCreateService) TrustFingerprints(value bool) *ConnectorCreateService { - s.trustFingerprints = &value - return s + s.trustFingerprints = &value + return s } func (s *ConnectorCreateService) RunSetupTests(value bool) *ConnectorCreateService { - s.runSetupTests = &value - return s + s.runSetupTests = &value + return s } func (s *ConnectorCreateService) Paused(value bool) *ConnectorCreateService { - s.paused = &value - return s + s.paused = &value + return s } func (s *ConnectorCreateService) SyncFrequency(value int) *ConnectorCreateService { - s.syncFrequency = &value - return s + s.syncFrequency = &value + return s } func (s *ConnectorCreateService) DailySyncTime(value string) *ConnectorCreateService { - s.dailySyncTime = &value - return s + s.dailySyncTime = &value + return s } func (s *ConnectorCreateService) PauseAfterTrial(value bool) *ConnectorCreateService { - s.pauseAfterTrial = &value - return s + s.pauseAfterTrial = &value + return s } func (s *ConnectorCreateService) Config(value *ConnectorConfig) *ConnectorCreateService { - s.config = value - return s + s.config = value + return s } func (s *ConnectorCreateService) ConfigCustom(value *map[string]interface{}) *ConnectorCreateService { - s.configCustom = value - return s + s.configCustom = value + return s } func (s *ConnectorCreateService) Auth(value *ConnectorAuth) *ConnectorCreateService { - s.auth = value - return s + s.auth = value + return s } func (s *ConnectorCreateService) AuthCustom(value *map[string]interface{}) *ConnectorCreateService { - s.authCustom = value - return s + s.authCustom = value + return s } func (s *ConnectorCreateService) do(ctx context.Context, req, response any) error { - err := s.HttpService.Do(ctx, "POST", "/connectors", req, nil, 201, &response) - return err + err := s.HttpService.Do(ctx, "POST", "/connectors", req, nil, 201, &response) + return err } func (s *ConnectorCreateService) Do(ctx context.Context) (DetailsWithConfigResponse, error) { - var response DetailsWithConfigResponse + var response DetailsWithConfigResponse - err := s.do(ctx, s.request(), &response) + err := s.do(ctx, s.request(), &response) - return response, err + return response, err } func (s *ConnectorCreateService) DoCustom(ctx context.Context) (DetailsWithCustomConfigResponse, error) { - var response DetailsWithCustomConfigResponse + var response DetailsWithCustomConfigResponse - err := s.do(ctx, s.requestCustom(), &response) + err := s.do(ctx, s.requestCustom(), &response) - return response, err + return response, err } func (s *ConnectorCreateService) DoCustomMerged(ctx context.Context) (DetailsWithCustomMergedConfigResponse, error) { - var response DetailsWithCustomMergedConfigResponse + var response DetailsWithCustomMergedConfigResponse - req, err := s.requestCustomMerged() + req, err := s.requestCustomMerged() - if err != nil { - return response, err - } + if err != nil { + return response, err + } - err = s.do(ctx, req, &response) + err = s.do(ctx, req, &response) - if err == nil { - err = utils.FetchFromMap(&response.Data.CustomConfig, &response.Data.Config) - } + if err == nil { + err = utils.FetchFromMap(&response.Data.CustomConfig, &response.Data.Config) + } - return response, err + return response, err } diff --git a/connectors/connector_create_test.go b/connectors/connector_create_test.go index 638d6439..ab972fbb 100644 --- a/connectors/connector_create_test.go +++ b/connectors/connector_create_test.go @@ -1,334 +1,358 @@ package connectors_test import ( - "context" - "net/http" - "testing" + "context" + "net/http" + "testing" - "github.com/fivetran/go-fivetran" - "github.com/fivetran/go-fivetran/connectors" - - "github.com/fivetran/go-fivetran/tests/mock" + "github.com/fivetran/go-fivetran" + "github.com/fivetran/go-fivetran/connectors" + + "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" + testutils "github.com/fivetran/go-fivetran/test_utils" ) const ( - CONNECTOR_SERVICE = "test_service" - SYNC_FREQUENCY = 5 + CONNECTOR_SERVICE = "test_service" + SYNC_FREQUENCY = 5 ) func TestNewConnectorSecretsListMappingMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/connectors").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertConnectorRequest(t, body) - response := mock.NewResponse(req, http.StatusCreated, prepareConnectorCreateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorCreate(). - Service(CONNECTOR_SERVICE). - GroupID("test_id"). - SyncFrequency(SYNC_FREQUENCY). - Config(prepareConnectorConfig()). - Auth(prepareConnectorAuth()). - Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertConnectorResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/connectors").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertConnectorRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareConnectorCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorCreate(). + Service(CONNECTOR_SERVICE). + GroupID("test_id"). + SyncFrequency(SYNC_FREQUENCY). + LocalProcessingAgentId("lpa_id"). + ProxyAgentId("proxy_id"). + PrivateLinkId("private_link_id"). + NetworkingMethod("networking_method"). + Config(prepareConnectorConfig()). + Auth(prepareConnectorAuth()). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertConnectorResponse(t, response) } func TestNewConnectorCustomSecretsListMappingMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/connectors").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertConnectorRequest(t, body) - response := mock.NewResponse(req, http.StatusCreated, prepareConnectorCreateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorCreate(). - Service(CONNECTOR_SERVICE). - GroupID("test_id"). - SyncFrequency(SYNC_FREQUENCY). - ConfigCustom(prepareConnectorCustomConfig()). - AuthCustom(prepareConnectorCustomAuth()). - DoCustom(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - assertConnectorCustomResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/connectors").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertConnectorRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareConnectorCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorCreate(). + Service(CONNECTOR_SERVICE). + GroupID("test_id"). + SyncFrequency(SYNC_FREQUENCY). + LocalProcessingAgentId("lpa_id"). + ProxyAgentId("proxy_id"). + PrivateLinkId("private_link_id"). + NetworkingMethod("networking_method"). + ConfigCustom(prepareConnectorCustomConfig()). + AuthCustom(prepareConnectorCustomAuth()). + DoCustom(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertConnectorCustomResponse(t, response) } func TestNewConnectorCustomMergedMappingMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/connectors").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertConnectorRequest(t, body) - response := mock.NewResponse(req, http.StatusCreated, prepareConnectorCustomMergedCreateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorCreate(). - Service(CONNECTOR_SERVICE). - GroupID("test_id"). - SyncFrequency(SYNC_FREQUENCY). - Config(prepareConnectorConfig()). - ConfigCustom(prepareConnectorCustomMergedConfig()). - AuthCustom(prepareConnectorCustomAuth()). - DoCustomMerged(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - assertConnectorCustomMergedResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/connectors").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertConnectorRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareConnectorCustomMergedCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorCreate(). + Service(CONNECTOR_SERVICE). + GroupID("test_id"). + SyncFrequency(SYNC_FREQUENCY). + LocalProcessingAgentId("lpa_id"). + ProxyAgentId("proxy_id"). + PrivateLinkId("private_link_id"). + NetworkingMethod("networking_method"). + Config(prepareConnectorConfig()). + ConfigCustom(prepareConnectorCustomMergedConfig()). + AuthCustom(prepareConnectorCustomAuth()). + DoCustomMerged(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertConnectorCustomMergedResponse(t, response) } func prepareConnectorCreateResponse() string { - return `{ - "code": "Success", - "message": "Connector has been created", - "data": { - "id": "speak_inexpensive", - "group_id": "projected_sickle", - "service": "criteo", - "service_version": 0, - "schema": "criteo", - "paused": true, - "pause_after_trial": true, - "connected_by": "interment_burdensome", - "created_at": "2018-12-01T15:43:29.013729Z", - "succeeded_at": null, - "failed_at": null, - "sync_frequency": 1440, - "daily_sync_time": "03:00", - "status": { - "setup_state": "incomplete", - "sync_state": "scheduled", - "update_state": "on_schedule", - "is_historical_sync": true, - "tasks": [], - "warnings": [] - }, - "setup_tests": [{ - "title": "Validate Login", - "status": "FAILED", - "message": "Invalid login credentials" - }], - "config": { - "secrets_list": [ - { - "key": "key", - "value": "value" - } - ] - } - } - }` + return `{ + "code": "Success", + "message": "Connector has been created", + "data": { + "id": "speak_inexpensive", + "group_id": "projected_sickle", + "service": "criteo", + "service_version": 0, + "schema": "criteo", + "paused": true, + "pause_after_trial": true, + "connected_by": "interment_burdensome", + "created_at": "2018-12-01T15:43:29.013729Z", + "succeeded_at": null, + "failed_at": null, + "sync_frequency": 1440, + "daily_sync_time": "03:00", + "local_processing_agent_id": "lpa_id", + "proxy_agent_id": "proxy_id", + "private_link_id": "private_link_id", + "networking_method": "networking_method", + "status": { + "setup_state": "incomplete", + "sync_state": "scheduled", + "update_state": "on_schedule", + "is_historical_sync": true, + "tasks": [], + "warnings": [] + }, + "setup_tests": [{ + "title": "Validate Login", + "status": "FAILED", + "message": "Invalid login credentials" + }], + "config": { + "secrets_list": [ + { + "key": "key", + "value": "value" + } + ] + } + } + }` } func prepareConnectorCustomMergedCreateResponse() string { - return `{ - "code": "Success", - "message": "Connector has been created", - "data": { - "id": "speak_inexpensive", - "group_id": "projected_sickle", - "service": "criteo", - "service_version": 0, - "schema": "criteo", - "paused": true, - "pause_after_trial": true, - "connected_by": "interment_burdensome", - "created_at": "2018-12-01T15:43:29.013729Z", - "succeeded_at": null, - "failed_at": null, - "sync_frequency": 1440, - "daily_sync_time": "03:00", - "status": { - "setup_state": "incomplete", - "sync_state": "scheduled", - "update_state": "on_schedule", - "is_historical_sync": true, - "tasks": [], - "warnings": [] - }, - "setup_tests": [{ - "title": "Validate Login", - "status": "FAILED", - "message": "Invalid login credentials" - }], - "config": { - "secrets_list": [ - { - "key": "key", - "value": "value" - } - ], - "fake_field": "unmapped-value", - "fake_list": [ - { - "user": "user", - "password": "******" - } - ] - } - } - }` + return `{ + "code": "Success", + "message": "Connector has been created", + "data": { + "id": "speak_inexpensive", + "group_id": "projected_sickle", + "service": "criteo", + "service_version": 0, + "schema": "criteo", + "paused": true, + "pause_after_trial": true, + "connected_by": "interment_burdensome", + "created_at": "2018-12-01T15:43:29.013729Z", + "succeeded_at": null, + "failed_at": null, + "sync_frequency": 1440, + "daily_sync_time": "03:00", + "local_processing_agent_id": "lpa_id", + "proxy_agent_id": "proxy_id", + "private_link_id": "private_link_id", + "networking_method": "networking_method", + "status": { + "setup_state": "incomplete", + "sync_state": "scheduled", + "update_state": "on_schedule", + "is_historical_sync": true, + "tasks": [], + "warnings": [] + }, + "setup_tests": [{ + "title": "Validate Login", + "status": "FAILED", + "message": "Invalid login credentials" + }], + "config": { + "secrets_list": [ + { + "key": "key", + "value": "value" + } + ], + "fake_field": "unmapped-value", + "fake_list": [ + { + "user": "user", + "password": "******" + } + ] + } + } + }` } func prepareConnectorConfig() *connectors.ConnectorConfig { - config := fivetran.NewConnectorConfig() - secretsList := make([]*connectors.FunctionSecret, 0) - secretsList = append(secretsList, fivetran.NewFunctionSecret().Key("key").Value("value")) - config.SecretsList(secretsList) - return config + config := fivetran.NewConnectorConfig() + secretsList := make([]*connectors.FunctionSecret, 0) + secretsList = append(secretsList, fivetran.NewFunctionSecret().Key("key").Value("value")) + config.SecretsList(secretsList) + return config } func prepareConnectorAuth() *connectors.ConnectorAuth { - auth := fivetran.NewConnectorAuth() + auth := fivetran.NewConnectorAuth() - clientAccess := fivetran.NewConnectorAuthClientAccess().ClientID("client_id").ClientSecret("client_secret") - auth.ClientAccess(clientAccess) + clientAccess := fivetran.NewConnectorAuthClientAccess().ClientID("client_id").ClientSecret("client_secret") + auth.ClientAccess(clientAccess) - return auth + return auth } func prepareConnectorCustomMergedConfig() *map[string]interface{} { - config := make(map[string]interface{}) - fakeList := make([]interface{}, 0) + config := make(map[string]interface{}) + fakeList := make([]interface{}, 0) - user := make(map[string]interface{}) - user["user"] = "user" - user["password"] = "password" + user := make(map[string]interface{}) + user["user"] = "user" + user["password"] = "password" - fakeList = append(fakeList, user) + fakeList = append(fakeList, user) - config["fake_list"] = fakeList - config["fake_field"] = "unmapped-value" + config["fake_list"] = fakeList + config["fake_field"] = "unmapped-value" - return &config + return &config } func prepareConnectorCustomConfig() *map[string]interface{} { - config := make(map[string]interface{}) - secretsList := make([]interface{}, 0) + config := make(map[string]interface{}) + secretsList := make([]interface{}, 0) - secret := make(map[string]interface{}) - secret["key"] = "key" - secret["value"] = "value" + secret := make(map[string]interface{}) + secret["key"] = "key" + secret["value"] = "value" - secretsList = append(secretsList, secret) + secretsList = append(secretsList, secret) - config["secrets_list"] = secretsList + config["secrets_list"] = secretsList - return &config + return &config } func prepareConnectorCustomAuth() *map[string]interface{} { - auth := make(map[string]interface{}) - clientAccess := make(map[string]interface{}) + auth := make(map[string]interface{}) + clientAccess := make(map[string]interface{}) - clientAccess["client_id"] = "client_id" - clientAccess["client_secret"] = "client_secret" + clientAccess["client_id"] = "client_id" + clientAccess["client_secret"] = "client_secret" - auth["client_access"] = clientAccess + auth["client_access"] = clientAccess - return &auth + return &auth } func assertConnectorRequest(t *testing.T, request map[string]interface{}) { - testutils.AssertKey(t, "service", request, CONNECTOR_SERVICE) - testutils.AssertKey(t, "group_id", request, "test_id") - testutils.AssertKey(t, "sync_frequency", request, float64(5)) + testutils.AssertKey(t, "service", request, CONNECTOR_SERVICE) + testutils.AssertKey(t, "group_id", request, "test_id") + testutils.AssertKey(t, "sync_frequency", request, float64(5)) + testutils.AssertKey(t, "local_processing_agent_id", request, "lpa_id") + testutils.AssertKey(t, "proxy_agent_id", request, "proxy_id") + testutils.AssertKey(t, "private_link_id", request, "private_link_id") + testutils.AssertKey(t, "networking_method", request, "networking_method") - config, ok := request["config"].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + config, ok := request["config"].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - secretsList, ok := config["secrets_list"].([]interface{}) - testutils.AssertEqual(t, ok, true) + secretsList, ok := config["secrets_list"].([]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertEqual(t, len(secretsList), int(1)) + testutils.AssertEqual(t, len(secretsList), int(1)) - secret, ok := secretsList[0].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + secret, ok := secretsList[0].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertKey(t, "key", secret, "key") - testutils.AssertKey(t, "value", secret, "value") + testutils.AssertKey(t, "key", secret, "key") + testutils.AssertKey(t, "value", secret, "value") - auth, ok := request["auth"].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + auth, ok := request["auth"].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - clientAccess, ok := auth["client_access"].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + clientAccess, ok := auth["client_access"].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertKey(t, "client_id", clientAccess, "client_id") - testutils.AssertKey(t, "client_secret", clientAccess, "client_secret") + testutils.AssertKey(t, "client_id", clientAccess, "client_id") + testutils.AssertKey(t, "client_secret", clientAccess, "client_secret") } func assertConnectorResponse(t *testing.T, response connectors.DetailsWithConfigResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertNotEmpty(t, response.Message) + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertNotEmpty(t, response.Message) - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") } func assertConnectorCustomResponse(t *testing.T, response connectors.DetailsWithCustomConfigResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertNotEmpty(t, response.Message) + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertNotEmpty(t, response.Message) - testutils.AssertKey(t, "key", response.Data.Config["secrets_list"].([]interface{})[0].(map[string]interface{}), "key") - testutils.AssertKey(t, "value", response.Data.Config["secrets_list"].([]interface{})[0].(map[string]interface{}), "value") + testutils.AssertKey(t, "key", response.Data.Config["secrets_list"].([]interface{})[0].(map[string]interface{}), "key") + testutils.AssertKey(t, "value", response.Data.Config["secrets_list"].([]interface{})[0].(map[string]interface{}), "value") } func assertConnectorCustomMergedResponse(t *testing.T, response connectors.DetailsWithCustomMergedConfigResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertNotEmpty(t, response.Message) + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertNotEmpty(t, response.Message) - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") - testutils.AssertKey(t, "user", response.Data.CustomConfig["fake_list"].([]interface{})[0].(map[string]interface{}), "user") - testutils.AssertKey(t, "password", response.Data.CustomConfig["fake_list"].([]interface{})[0].(map[string]interface{}), "******") - testutils.AssertKey(t, "fake_field", response.Data.CustomConfig, "unmapped-value") + testutils.AssertKey(t, "user", response.Data.CustomConfig["fake_list"].([]interface{})[0].(map[string]interface{}), "user") + testutils.AssertKey(t, "password", response.Data.CustomConfig["fake_list"].([]interface{})[0].(map[string]interface{}), "******") + testutils.AssertKey(t, "fake_field", response.Data.CustomConfig, "unmapped-value") } diff --git a/connectors/connector_details_test.go b/connectors/connector_details_test.go index 9aa461af..ba26707c 100644 --- a/connectors/connector_details_test.go +++ b/connectors/connector_details_test.go @@ -1,184 +1,188 @@ package connectors_test import ( - "context" - "net/http" - "testing" + "context" + "net/http" + "testing" - "github.com/fivetran/go-fivetran/connectors" - - "github.com/fivetran/go-fivetran/tests/mock" + "github.com/fivetran/go-fivetran/connectors" + + "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" + testutils "github.com/fivetran/go-fivetran/test_utils" ) func TestConnectorDetailsMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodGet, "/v1/connectors/connector_id").ThenCall( - - func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, prepareConnectorDetailsResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorDetails().ConnectorID("connector_id").Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertConnectorDetailsResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/connectors/connector_id").ThenCall( + + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareConnectorDetailsResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorDetails().ConnectorID("connector_id").Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertConnectorDetailsResponse(t, response) } func TestCustomConnectorDetailsMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodGet, "/v1/connectors/connector_id").ThenCall( - - func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, prepareConnectorDetailsResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorDetails().ConnectorID("connector_id").DoCustom(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertCustomConnectorDetailsResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/connectors/connector_id").ThenCall( + + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareConnectorDetailsResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorDetails().ConnectorID("connector_id").DoCustom(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertCustomConnectorDetailsResponse(t, response) } func TestCustomMergedConnectorDetailsMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodGet, "/v1/connectors/connector_id").ThenCall( - - func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, prepareConnectorDetailsResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorDetails().ConnectorID("connector_id").DoCustomMerged(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertCustomMergedConnectorDetailsResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/connectors/connector_id").ThenCall( + + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareConnectorDetailsResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorDetails().ConnectorID("connector_id").DoCustomMerged(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertCustomMergedConnectorDetailsResponse(t, response) } func prepareConnectorDetailsResponse() string { - return `{ - "code": "Success", - "data": { - "id": "speak_inexpensive", - "group_id": "projected_sickle", - "service": "criteo", - "service_version": 0, - "schema": "criteo", - "paused": true, - "pause_after_trial": true, - "connected_by": "interment_burdensome", - "created_at": "2018-12-01T15:43:29.013729Z", - "succeeded_at": null, - "failed_at": null, - "sync_frequency": 1440, - "daily_sync_time": "03:00", - "status": { - "setup_state": "incomplete", - "sync_state": "scheduled", - "update_state": "on_schedule", - "is_historical_sync": true, - "tasks": [], - "warnings": [] - }, - "setup_tests": [{ - "title": "Validate Login", - "status": "FAILED", - "message": "Invalid login credentials" - }], - "config": { - "share_url": "share_url", - "is_keypair": true, - "secrets_list": [ - { - "key": "key", - "value": "value" - } - ], - "fake_field": "unmapped-value" - } - } - }` + return `{ + "code": "Success", + "data": { + "id": "speak_inexpensive", + "group_id": "projected_sickle", + "service": "criteo", + "service_version": 0, + "schema": "criteo", + "paused": true, + "pause_after_trial": true, + "connected_by": "interment_burdensome", + "created_at": "2018-12-01T15:43:29.013729Z", + "succeeded_at": null, + "failed_at": null, + "sync_frequency": 1440, + "daily_sync_time": "03:00", + "local_processing_agent_id": "lpa_id", + "proxy_agent_id": "proxy_id", + "private_link_id": "private_link_id", + "networking_method": "networking_method", + "status": { + "setup_state": "incomplete", + "sync_state": "scheduled", + "update_state": "on_schedule", + "is_historical_sync": true, + "tasks": [], + "warnings": [] + }, + "setup_tests": [{ + "title": "Validate Login", + "status": "FAILED", + "message": "Invalid login credentials" + }], + "config": { + "share_url": "share_url", + "is_keypair": true, + "secrets_list": [ + { + "key": "key", + "value": "value" + } + ], + "fake_field": "unmapped-value" + } + } + }` } func assertConnectorDetailsResponse(t *testing.T, response connectors.DetailsWithConfigNoTestsResponse) { - testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") - testutils.AssertEqual(t, response.Data.Config.ShareURL, "share_url") - testutils.AssertEqual(t, *response.Data.Config.IsKeypair, true) + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") + testutils.AssertEqual(t, response.Data.Config.ShareURL, "share_url") + testutils.AssertEqual(t, *response.Data.Config.IsKeypair, true) } func assertCustomConnectorDetailsResponse(t *testing.T, response connectors.DetailsWithCustomConfigNoTestsResponse) { - testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertKey(t, "share_url", response.Data.Config, "share_url") - testutils.AssertKey(t, "is_keypair", response.Data.Config, true) + testutils.AssertKey(t, "share_url", response.Data.Config, "share_url") + testutils.AssertKey(t, "is_keypair", response.Data.Config, true) - secretsList, ok := response.Data.Config["secrets_list"].([]interface{}) + secretsList, ok := response.Data.Config["secrets_list"].([]interface{}) - testutils.AssertEqual(t, ok, true) - testutils.AssertEqual(t, len(secretsList), 1) + testutils.AssertEqual(t, ok, true) + testutils.AssertEqual(t, len(secretsList), 1) - secret := secretsList[0].(map[string]interface{}) + secret := secretsList[0].(map[string]interface{}) - testutils.AssertKey(t, "key", secret, "key") - testutils.AssertKey(t, "value", secret, "value") + testutils.AssertKey(t, "key", secret, "key") + testutils.AssertKey(t, "value", secret, "value") } func assertCustomMergedConnectorDetailsResponse(t *testing.T, response connectors.DetailsWithCustomMergedConfigNoTestsResponse) { - testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertHasNoKey(t, response.Data.CustomConfig, "share_url") - testutils.AssertHasNoKey(t, response.Data.CustomConfig, "is_keypair") - testutils.AssertHasNoKey(t, response.Data.CustomConfig, "secrets_list") + testutils.AssertHasNoKey(t, response.Data.CustomConfig, "share_url") + testutils.AssertHasNoKey(t, response.Data.CustomConfig, "is_keypair") + testutils.AssertHasNoKey(t, response.Data.CustomConfig, "secrets_list") - testutils.AssertKeyValue(t, response.Data.CustomConfig, "fake_field", "unmapped-value") + testutils.AssertKeyValue(t, response.Data.CustomConfig, "fake_field", "unmapped-value") - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") - testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") - testutils.AssertEqual(t, response.Data.Config.ShareURL, "share_url") - testutils.AssertEqual(t, *response.Data.Config.IsKeypair, true) + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Key, "key") + testutils.AssertEqual(t, response.Data.Config.SecretsList[0].Value, "value") + testutils.AssertEqual(t, response.Data.Config.ShareURL, "share_url") + testutils.AssertEqual(t, *response.Data.Config.IsKeypair, true) } diff --git a/connectors/connector_modify.go b/connectors/connector_modify.go index 00052047..081a8dfa 100644 --- a/connectors/connector_modify.go +++ b/connectors/connector_modify.go @@ -1,209 +1,237 @@ package connectors import ( - "context" - "fmt" + "context" + "fmt" - "github.com/fivetran/go-fivetran/utils" - httputils "github.com/fivetran/go-fivetran/http_utils" + "github.com/fivetran/go-fivetran/utils" + httputils "github.com/fivetran/go-fivetran/http_utils" ) // ConnectorModifyService implements the Connector Management, Modify a Connector API. // Ref. https://fivetran.com/docs/rest-api/connectors#modifyaconnector type ConnectorModifyService struct { httputils.HttpService - connectorID *string - paused *bool - syncFrequency *int - dailySyncTime *string - trustCertificates *bool - trustFingerprints *bool - isHistoricalSync *bool - scheduleType *string - runSetupTests *bool - pauseAfterTrial *bool - config *ConnectorConfig - auth *ConnectorAuth - configCustom *map[string]interface{} - authCustom *map[string]interface{} + connectorID *string + paused *bool + syncFrequency *int + dailySyncTime *string + trustCertificates *bool + trustFingerprints *bool + isHistoricalSync *bool + scheduleType *string + runSetupTests *bool + pauseAfterTrial *bool + localProcessingAgentId *string + networkingMethod *string + privateLinkId *string + proxyAgentId *string + config *ConnectorConfig + auth *ConnectorAuth + configCustom *map[string]interface{} + authCustom *map[string]interface{} } func (s *ConnectorModifyService) requestBase() connectorModifyRequestBase { - return connectorModifyRequestBase{ - Paused: s.paused, - SyncFrequency: s.syncFrequency, - DailySyncTime: s.dailySyncTime, - TrustCertificates: s.trustCertificates, - TrustFingerprints: s.trustFingerprints, - IsHistoricalSync: s.isHistoricalSync, - ScheduleType: s.scheduleType, - RunSetupTests: s.runSetupTests, - PauseAfterTrial: s.pauseAfterTrial, - } + return connectorModifyRequestBase{ + Paused: s.paused, + SyncFrequency: s.syncFrequency, + DailySyncTime: s.dailySyncTime, + TrustCertificates: s.trustCertificates, + TrustFingerprints: s.trustFingerprints, + IsHistoricalSync: s.isHistoricalSync, + ScheduleType: s.scheduleType, + RunSetupTests: s.runSetupTests, + PauseAfterTrial: s.pauseAfterTrial, + PrivateLinkId: s.privateLinkId, + LocalProcessingAgentId: s.localProcessingAgentId, + NetworkingMethod: s.networkingMethod, + ProxyAgentId: s.proxyAgentId, + } } func (s *ConnectorModifyService) request() *connectorModifyRequest { - var config interface{} - if s.config != nil { - config = s.config.Request() - } + var config interface{} + if s.config != nil { + config = s.config.Request() + } - var auth interface{} - if s.auth != nil { - auth = s.auth.Request() - } + var auth interface{} + if s.auth != nil { + auth = s.auth.Request() + } - return &connectorModifyRequest{ - connectorModifyRequestBase: s.requestBase(), - Config: config, - Auth: auth, - } + return &connectorModifyRequest{ + connectorModifyRequestBase: s.requestBase(), + Config: config, + Auth: auth, + } } func (s *ConnectorModifyService) requestCustom() *connectorCustomModifyRequest { - return &connectorCustomModifyRequest{ - connectorModifyRequestBase: s.requestBase(), - Config: s.configCustom, - Auth: s.authCustom, - } + return &connectorCustomModifyRequest{ + connectorModifyRequestBase: s.requestBase(), + Config: s.configCustom, + Auth: s.authCustom, + } } func (s *ConnectorModifyService) requestCustomMerged() (*connectorCustomModifyRequest, error) { - currentConfig := s.configCustom - - if s.config != nil { - var err error - currentConfig, err = s.config.Merge(currentConfig) - if err != nil { - return nil, err - } - } - - currentAuth := s.authCustom - if s.auth != nil { - var err error - currentAuth, err = s.auth.Merge(currentAuth) - if err != nil { - return nil, err - } - } - - return &connectorCustomModifyRequest{ - connectorModifyRequestBase: s.requestBase(), - Config: currentConfig, - Auth: currentAuth, - }, nil + currentConfig := s.configCustom + + if s.config != nil { + var err error + currentConfig, err = s.config.Merge(currentConfig) + if err != nil { + return nil, err + } + } + + currentAuth := s.authCustom + if s.auth != nil { + var err error + currentAuth, err = s.auth.Merge(currentAuth) + if err != nil { + return nil, err + } + } + + return &connectorCustomModifyRequest{ + connectorModifyRequestBase: s.requestBase(), + Config: currentConfig, + Auth: currentAuth, + }, nil } func (s *ConnectorModifyService) ConnectorID(value string) *ConnectorModifyService { - s.connectorID = &value - return s + s.connectorID = &value + return s +} + +func (s *ConnectorModifyService) LocalProcessingAgentId(value string) *ConnectorModifyService { + s.localProcessingAgentId = &value + return s +} + +func (s *ConnectorModifyService) ProxyAgentId(value string) *ConnectorModifyService { + s.proxyAgentId = &value + return s +} + +func (s *ConnectorModifyService) PrivateLinkId(value string) *ConnectorModifyService { + s.privateLinkId = &value + return s +} + +func (s *ConnectorModifyService) NetworkingMethod(value string) *ConnectorModifyService { + s.networkingMethod = &value + return s } func (s *ConnectorModifyService) Paused(value bool) *ConnectorModifyService { - s.paused = &value - return s + s.paused = &value + return s } func (s *ConnectorModifyService) SyncFrequency(value int) *ConnectorModifyService { - s.syncFrequency = &value - return s + s.syncFrequency = &value + return s } func (s *ConnectorModifyService) DailySyncTime(value string) *ConnectorModifyService { - s.dailySyncTime = &value - return s + s.dailySyncTime = &value + return s } func (s *ConnectorModifyService) Config(value *ConnectorConfig) *ConnectorModifyService { - s.config = value - return s + s.config = value + return s } func (s *ConnectorModifyService) Auth(value *ConnectorAuth) *ConnectorModifyService { - s.auth = value - return s + s.auth = value + return s } func (s *ConnectorModifyService) ConfigCustom(value *map[string]interface{}) *ConnectorModifyService { - s.configCustom = value - return s + s.configCustom = value + return s } func (s *ConnectorModifyService) AuthCustom(value *map[string]interface{}) *ConnectorModifyService { - s.authCustom = value - return s + s.authCustom = value + return s } func (s *ConnectorModifyService) TrustCertificates(value bool) *ConnectorModifyService { - s.trustCertificates = &value - return s + s.trustCertificates = &value + return s } func (s *ConnectorModifyService) TrustFingerprints(value bool) *ConnectorModifyService { - s.trustFingerprints = &value - return s + s.trustFingerprints = &value + return s } func (s *ConnectorModifyService) IsHistoricalSync(value bool) *ConnectorModifyService { - s.isHistoricalSync = &value - return s + s.isHistoricalSync = &value + return s } func (s *ConnectorModifyService) ScheduleType(value string) *ConnectorModifyService { - s.scheduleType = &value - return s + s.scheduleType = &value + return s } func (s *ConnectorModifyService) RunSetupTests(value bool) *ConnectorModifyService { - s.runSetupTests = &value - return s + s.runSetupTests = &value + return s } func (s *ConnectorModifyService) PauseAfterTrial(value bool) *ConnectorModifyService { - s.pauseAfterTrial = &value - return s + s.pauseAfterTrial = &value + return s } func (s *ConnectorModifyService) do(ctx context.Context, req, response any) error { - if s.connectorID == nil { - return fmt.Errorf("missing required connectorID") - } - url := fmt.Sprintf("/connectors/%v", *s.connectorID) - err := s.HttpService.Do(ctx, "PATCH", url, req, nil, 200, &response) - return err + if s.connectorID == nil { + return fmt.Errorf("missing required connectorID") + } + url := fmt.Sprintf("/connectors/%v", *s.connectorID) + err := s.HttpService.Do(ctx, "PATCH", url, req, nil, 200, &response) + return err } func (s *ConnectorModifyService) Do(ctx context.Context) (DetailsWithConfigResponse, error) { - var response DetailsWithConfigResponse + var response DetailsWithConfigResponse - err := s.do(ctx, s.request(), &response) + err := s.do(ctx, s.request(), &response) - return response, err + return response, err } func (s *ConnectorModifyService) DoCustom(ctx context.Context) (DetailsWithCustomConfigResponse, error) { - var response DetailsWithCustomConfigResponse + var response DetailsWithCustomConfigResponse - err := s.do(ctx, s.requestCustom(), &response) + err := s.do(ctx, s.requestCustom(), &response) - return response, err + return response, err } func (s *ConnectorModifyService) DoCustomMerged(ctx context.Context) (DetailsWithCustomMergedConfigResponse, error) { - var response DetailsWithCustomMergedConfigResponse + var response DetailsWithCustomMergedConfigResponse - req, err := s.requestCustomMerged() + req, err := s.requestCustomMerged() - if err != nil { - return response, err - } + if err != nil { + return response, err + } - err = s.do(ctx, req, &response) + err = s.do(ctx, req, &response) - if err == nil { - err = utils.FetchFromMap(&response.Data.CustomConfig, &response.Data.Config) - } + if err == nil { + err = utils.FetchFromMap(&response.Data.CustomConfig, &response.Data.Config) + } - return response, err + return response, err } diff --git a/connectors/connector_modify_test.go b/connectors/connector_modify_test.go index 70c303e3..747d2204 100644 --- a/connectors/connector_modify_test.go +++ b/connectors/connector_modify_test.go @@ -1,323 +1,357 @@ package connectors_test import ( - "context" - "net/http" - "testing" + "context" + "net/http" + "testing" - "github.com/fivetran/go-fivetran" - "github.com/fivetran/go-fivetran/connectors" - - "github.com/fivetran/go-fivetran/tests/mock" + "github.com/fivetran/go-fivetran" + "github.com/fivetran/go-fivetran/connectors" + + "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" + testutils "github.com/fivetran/go-fivetran/test_utils" ) func TestConnectorUpdateMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPatch, "/v1/connectors/connector_id").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertConnectorUpdateRequest(t, body) - response := mock.NewResponse(req, http.StatusOK, prepareConnectorUpdateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorModify(). - ConnectorID("connector_id"). - Paused(false). - Config(prepareConfigUpdate()). - Auth(prepareConnectorAuth()). - Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertConnectorUpdateResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPatch, "/v1/connectors/connector_id").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertConnectorUpdateRequest(t, body) + response := mock.NewResponse(req, http.StatusOK, prepareConnectorUpdateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorModify(). + ConnectorID("connector_id"). + LocalProcessingAgentId("lpa_id"). + ProxyAgentId("proxy_id"). + PrivateLinkId("private_link_id"). + NetworkingMethod("networking_method"). + Paused(false). + Config(prepareConfigUpdate()). + Auth(prepareConnectorAuth()). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertConnectorUpdateResponse(t, response) } func TestCustomConnectorUpdateMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPatch, "/v1/connectors/connector_id").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertCustomConnectorUpdateRequest(t, body) - response := mock.NewResponse(req, http.StatusOK, prepareConnectorUpdateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorModify(). - ConnectorID("connector_id"). - Paused(false). - ConfigCustom(prepareCustomUpdateConfig()). - AuthCustom(prepareConnectorCustomAuthUpdate()). - DoCustom(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertCustomConnectorUpdateResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPatch, "/v1/connectors/connector_id").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertCustomConnectorUpdateRequest(t, body) + response := mock.NewResponse(req, http.StatusOK, prepareConnectorUpdateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorModify(). + ConnectorID("connector_id"). + LocalProcessingAgentId("lpa_id"). + ProxyAgentId("proxy_id"). + PrivateLinkId("private_link_id"). + NetworkingMethod("networking_method"). + Paused(false). + ConfigCustom(prepareCustomUpdateConfig()). + AuthCustom(prepareConnectorCustomAuthUpdate()). + DoCustom(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertCustomConnectorUpdateResponse(t, response) } func prepareConnectorCustomAuthUpdate() *map[string]interface{} { - auth := make(map[string]interface{}) - clientAccess := make(map[string]interface{}) + auth := make(map[string]interface{}) + clientAccess := make(map[string]interface{}) - clientAccess["client_id"] = "client_id" - clientAccess["client_secret"] = "client_secret" + clientAccess["client_id"] = "client_id" + clientAccess["client_secret"] = "client_secret" - auth["client_access"] = clientAccess - auth["custom_auth"] = "custom_auth" + auth["client_access"] = clientAccess + auth["custom_auth"] = "custom_auth" - return &auth + return &auth } func TestCustomMergedConnectorUpdateMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPatch, "/v1/connectors/connector_id").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertCustomConnectorUpdateRequest(t, body) - response := mock.NewResponse(req, http.StatusOK, prepareConnectorUpdateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewConnectorModify(). - ConnectorID("connector_id"). - Paused(false). - ConfigCustom(prepareCustomMergedUpdateConfigMap()). - Config(prepareCustomMergedConfigUpdate()). - Auth(prepareCustomMergedAuth()). - AuthCustom(prepareConnectorCustomMergedAuthMap()). - DoCustomMerged(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertCustomMergedConnectorUpdateResponse(t, response) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPatch, "/v1/connectors/connector_id").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertCustomConnectorUpdateRequest(t, body) + response := mock.NewResponse(req, http.StatusOK, prepareConnectorUpdateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewConnectorModify(). + ConnectorID("connector_id"). + Paused(false). + LocalProcessingAgentId("lpa_id"). + ProxyAgentId("proxy_id"). + PrivateLinkId("private_link_id"). + NetworkingMethod("networking_method"). + ConfigCustom(prepareCustomMergedUpdateConfigMap()). + Config(prepareCustomMergedConfigUpdate()). + Auth(prepareCustomMergedAuth()). + AuthCustom(prepareConnectorCustomMergedAuthMap()). + DoCustomMerged(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertCustomMergedConnectorUpdateResponse(t, response) } func prepareConnectorCustomMergedAuthMap() *map[string]interface{} { - auth := make(map[string]interface{}) + auth := make(map[string]interface{}) - auth["custom_auth"] = "custom_auth" + auth["custom_auth"] = "custom_auth" - return &auth + return &auth } func prepareCustomUpdateConfig() *map[string]interface{} { - config := make(map[string]interface{}) - secretsList := make([]interface{}, 0) + config := make(map[string]interface{}) + secretsList := make([]interface{}, 0) - secret := make(map[string]interface{}) - secret["key"] = "key" - secret["value"] = "value" + secret := make(map[string]interface{}) + secret["key"] = "key" + secret["value"] = "value" - secretsList = append(secretsList, secret) + secretsList = append(secretsList, secret) - config["secrets_list"] = secretsList - config["share_url"] = "share_url" - config["is_keypair"] = true - config["fake_field"] = "unmapped-value" + config["secrets_list"] = secretsList + config["share_url"] = "share_url" + config["is_keypair"] = true + config["fake_field"] = "unmapped-value" - return &config + return &config } func prepareCustomMergedAuth() *connectors.ConnectorAuth { - auth := fivetran.NewConnectorAuth() + auth := fivetran.NewConnectorAuth() - clientAccess := fivetran.NewConnectorAuthClientAccess().ClientID("client_id").ClientSecret("client_secret") - auth.ClientAccess(clientAccess) + clientAccess := fivetran.NewConnectorAuthClientAccess().ClientID("client_id").ClientSecret("client_secret") + auth.ClientAccess(clientAccess) - return auth + return auth } func prepareCustomMergedUpdateConfigMap() *map[string]interface{} { - config := make(map[string]interface{}) + config := make(map[string]interface{}) - config["share_url"] = "share_url" - config["fake_field"] = "unmapped-value" + config["share_url"] = "share_url" + config["fake_field"] = "unmapped-value" - return &config + return &config } func prepareCustomMergedConfigUpdate() *connectors.ConnectorConfig { - config := fivetran.NewConnectorConfig() - secretsList := make([]*connectors.FunctionSecret, 0) - secretsList = append(secretsList, fivetran.NewFunctionSecret().Key("key").Value("value")) - config. - SecretsList(secretsList). - IsKeypair(true) - - return config + config := fivetran.NewConnectorConfig() + secretsList := make([]*connectors.FunctionSecret, 0) + secretsList = append(secretsList, fivetran.NewFunctionSecret().Key("key").Value("value")) + config. + SecretsList(secretsList). + IsKeypair(true) + + return config } func prepareConfigUpdate() *connectors.ConnectorConfig { - config := fivetran.NewConnectorConfig() - secretsList := make([]*connectors.FunctionSecret, 0) - secretsList = append(secretsList, fivetran.NewFunctionSecret().Key("key").Value("value")) - config. - SecretsList(secretsList). - IsKeypair(true). - ShareURL("share_url") - - return config + config := fivetran.NewConnectorConfig() + secretsList := make([]*connectors.FunctionSecret, 0) + secretsList = append(secretsList, fivetran.NewFunctionSecret().Key("key").Value("value")) + config. + SecretsList(secretsList). + IsKeypair(true). + ShareURL("share_url") + + return config } func prepareConnectorUpdateResponse() string { - return `{ - "code": "Success", - "data": { - "id": "connector_id", - "group_id": "projected_sickle", - "service": "criteo", - "service_version": 0, - "schema": "criteo", - "paused": false, - "pause_after_trial": true, - "connected_by": "interment_burdensome", - "created_at": "2018-12-01T15:43:29.013729Z", - "succeeded_at": null, - "failed_at": null, - "sync_frequency": 1440, - "daily_sync_time": "03:00", - "status": { - "setup_state": "incomplete", - "sync_state": "scheduled", - "update_state": "on_schedule", - "is_historical_sync": true, - "tasks": [], - "warnings": [] - }, - "setup_tests": [{ - "title": "Validate Login", - "status": "FAILED", - "message": "Invalid login credentials" - }], - "config": { - "share_url": "share_url", - "is_keypair": true, - "secrets_list": [ - { - "key": "key", - "value": "value" - } - ], - "fake_field": "unmapped-value" - } - } - }` + return `{ + "code": "Success", + "data": { + "id": "connector_id", + "group_id": "projected_sickle", + "service": "criteo", + "service_version": 0, + "schema": "criteo", + "paused": false, + "pause_after_trial": true, + "connected_by": "interment_burdensome", + "created_at": "2018-12-01T15:43:29.013729Z", + "succeeded_at": null, + "failed_at": null, + "sync_frequency": 1440, + "daily_sync_time": "03:00", + "local_processing_agent_id": "lpa_id", + "proxy_agent_id": "proxy_id", + "private_link_id": "private_link_id", + "networking_method": "networking_method", + "status": { + "setup_state": "incomplete", + "sync_state": "scheduled", + "update_state": "on_schedule", + "is_historical_sync": true, + "tasks": [], + "warnings": [] + }, + "setup_tests": [{ + "title": "Validate Login", + "status": "FAILED", + "message": "Invalid login credentials" + }], + "config": { + "share_url": "share_url", + "is_keypair": true, + "secrets_list": [ + { + "key": "key", + "value": "value" + } + ], + "fake_field": "unmapped-value" + } + } + }` } func assertConnectorConfig(t *testing.T, config connectors.ConnectorConfigResponse) { - testutils.AssertEqual(t, config.SecretsList[0].Key, "key") - testutils.AssertEqual(t, config.SecretsList[0].Value, "value") - testutils.AssertEqual(t, config.ShareURL, "share_url") - testutils.AssertEqual(t, *config.IsKeypair, true) + testutils.AssertEqual(t, config.SecretsList[0].Key, "key") + testutils.AssertEqual(t, config.SecretsList[0].Value, "value") + testutils.AssertEqual(t, config.ShareURL, "share_url") + testutils.AssertEqual(t, *config.IsKeypair, true) } func assertConnectorUpdateResponse(t *testing.T, response connectors.DetailsWithConfigResponse) { - testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, *response.Data.Paused, false) - assertConnectorConfig(t, response.Data.Config) + testutils.AssertEqual(t, *response.Data.Paused, false) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, "lpa_id") + testutils.AssertEqual(t, response.Data.ProxyAgentId, "proxy_id") + testutils.AssertEqual(t, response.Data.PrivateLinkId, "private_link_id") + testutils.AssertEqual(t, response.Data.NetworkingMethod, "networking_method") + + assertConnectorConfig(t, response.Data.Config) } func assertCustomConnectorUpdateResponse(t *testing.T, response connectors.DetailsWithCustomConfigResponse) { - testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, *response.Data.Paused, false) + testutils.AssertEqual(t, *response.Data.Paused, false) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, "lpa_id") + testutils.AssertEqual(t, response.Data.ProxyAgentId, "proxy_id") + testutils.AssertEqual(t, response.Data.PrivateLinkId, "private_link_id") + testutils.AssertEqual(t, response.Data.NetworkingMethod, "networking_method") - testutils.AssertKey(t, "share_url", response.Data.Config, "share_url") - testutils.AssertKey(t, "is_keypair", response.Data.Config, true) + testutils.AssertKey(t, "share_url", response.Data.Config, "share_url") + testutils.AssertKey(t, "is_keypair", response.Data.Config, true) - secretsList, ok := response.Data.Config["secrets_list"].([]interface{}) + secretsList, ok := response.Data.Config["secrets_list"].([]interface{}) - testutils.AssertEqual(t, ok, true) - testutils.AssertEqual(t, len(secretsList), 1) + testutils.AssertEqual(t, ok, true) + testutils.AssertEqual(t, len(secretsList), 1) - secret := secretsList[0].(map[string]interface{}) + secret := secretsList[0].(map[string]interface{}) - testutils.AssertKey(t, "key", secret, "key") - testutils.AssertKey(t, "value", secret, "value") + testutils.AssertKey(t, "key", secret, "key") + testutils.AssertKey(t, "value", secret, "value") } func assertCustomMergedConnectorUpdateResponse(t *testing.T, response connectors.DetailsWithCustomMergedConfigResponse) { - testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, *response.Data.Paused, false) - assertConnectorConfig(t, response.Data.Config) + testutils.AssertEqual(t, *response.Data.Paused, false) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, "lpa_id") + testutils.AssertEqual(t, response.Data.ProxyAgentId, "proxy_id") + testutils.AssertEqual(t, response.Data.PrivateLinkId, "private_link_id") + testutils.AssertEqual(t, response.Data.NetworkingMethod, "networking_method") - testutils.AssertKey(t, "fake_field", response.Data.CustomConfig, "unmapped-value") + assertConnectorConfig(t, response.Data.Config) + testutils.AssertKey(t, "fake_field", response.Data.CustomConfig, "unmapped-value") } func assertConnectorUpdateRequest(t *testing.T, request map[string]interface{}) { - testutils.AssertKeyValue(t, request, "paused", false) - config, ok := request["config"].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + testutils.AssertKeyValue(t, request, "paused", false) + testutils.AssertKeyValue(t, request, "local_processing_agent_id", "lpa_id") + testutils.AssertKeyValue(t, request, "proxy_agent_id", "proxy_id") + testutils.AssertKeyValue(t, request, "private_link_id", "private_link_id") + testutils.AssertKeyValue(t, request, "networking_method", "networking_method") + + config, ok := request["config"].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertKeyValue(t, config, "is_keypair", true) - testutils.AssertKeyValue(t, config, "share_url", "share_url") + testutils.AssertKeyValue(t, config, "is_keypair", true) + testutils.AssertKeyValue(t, config, "share_url", "share_url") - secretsList, ok := config["secrets_list"].([]interface{}) - testutils.AssertEqual(t, ok, true) + secretsList, ok := config["secrets_list"].([]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertEqual(t, len(secretsList), int(1)) + testutils.AssertEqual(t, len(secretsList), int(1)) - secret, ok := secretsList[0].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + secret, ok := secretsList[0].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertKey(t, "key", secret, "key") - testutils.AssertKey(t, "value", secret, "value") + testutils.AssertKey(t, "key", secret, "key") + testutils.AssertKey(t, "value", secret, "value") - auth, ok := request["auth"].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + auth, ok := request["auth"].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - clientAccess, ok := auth["client_access"].(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + clientAccess, ok := auth["client_access"].(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertKey(t, "client_id", clientAccess, "client_id") - testutils.AssertKey(t, "client_secret", clientAccess, "client_secret") + testutils.AssertKey(t, "client_id", clientAccess, "client_id") + testutils.AssertKey(t, "client_secret", clientAccess, "client_secret") } func assertCustomConnectorUpdateRequest(t *testing.T, request map[string]interface{}) { - assertConnectorUpdateRequest(t, request) - config := request["config"].(map[string]interface{}) - testutils.AssertKey(t, "fake_field", config, "unmapped-value") - auth := request["auth"].(map[string]interface{}) - testutils.AssertKey(t, "custom_auth", auth, "custom_auth") + assertConnectorUpdateRequest(t, request) + config := request["config"].(map[string]interface{}) + testutils.AssertKey(t, "fake_field", config, "unmapped-value") + auth := request["auth"].(map[string]interface{}) + testutils.AssertKey(t, "custom_auth", auth, "custom_auth") } diff --git a/destinations/common_types.go b/destinations/common_types.go index 44586f4d..4664ed10 100644 --- a/destinations/common_types.go +++ b/destinations/common_types.go @@ -3,75 +3,84 @@ 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"` - DaylightSavingTimeEnabled bool `json:"daylight_saving_time_enabled"` + 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"` + PrivateLinkId string `json:"private_link_id"` + LocalProcessingAgentId string `json:"local_processing_agent_id"` + NetworkingMethod string `json:"networking_method"` + DaylightSavingTimeEnabled bool `json:"daylight_saving_time_enabled"` } type DestinationDetailsWithSetupTestsResponse struct { - common.CommonResponse - Data struct { - DestinationDetailsBase - Config DestinationConfigResponse `json:"config"` - SetupTests []common.SetupTestResponse `json:"setup_tests"` - } `json:"data"` + 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"` + 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 struct { - DestinationDetailsBase - Config DestinationConfigResponse `json:"config"` - } `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"` + Code string `json:"code"` + Message string `json:"message"` + Data struct { + DestinationDetailsBase + Config map[string]interface{} `json:"config"` + } `json:"data"` } type destinationCreateRequest struct { - GroupID *string `json:"group_id,omitempty"` - Service *string `json:"service,omitempty"` - Region *string `json:"region,omitempty"` - TimeZoneOffset *string `json:"time_zone_offset,omitempty"` - Config any `json:"config,omitempty"` - TrustCertificates *bool `json:"trust_certificates,omitempty"` - TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` - RunSetupTests *bool `json:"run_setup_tests,omitempty"` - DaylightSavingTimeEnabled *bool `json:"daylight_saving_time_enabled,omitempty"` - + GroupID *string `json:"group_id,omitempty"` + Service *string `json:"service,omitempty"` + Region *string `json:"region,omitempty"` + TimeZoneOffset *string `json:"time_zone_offset,omitempty"` + Config any `json:"config,omitempty"` + TrustCertificates *bool `json:"trust_certificates,omitempty"` + TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` + RunSetupTests *bool `json:"run_setup_tests,omitempty"` + DaylightSavingTimeEnabled *bool `json:"daylight_saving_time_enabled,omitempty"` + PrivateLinkId *string `json:"private_link_id,omitempty"` + LocalProcessingAgentId *string `json:"local_processing_agent_id,omitempty"` + NetworkingMethod *string `json:"networking_method,omitempty"` + } type destinationModifyRequest struct { - Region *string `json:"region,omitempty"` - TimeZoneOffset *string `json:"time_zone_offset,omitempty"` - Config any `json:"config,omitempty"` - TrustCertificates *bool `json:"trust_certificates,omitempty"` - TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` - RunSetupTests *bool `json:"run_setup_tests,omitempty"` - DaylightSavingTimeEnabled *bool `json:"daylight_saving_time_enabled,omitempty"` + Region *string `json:"region,omitempty"` + TimeZoneOffset *string `json:"time_zone_offset,omitempty"` + Config any `json:"config,omitempty"` + TrustCertificates *bool `json:"trust_certificates,omitempty"` + TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` + RunSetupTests *bool `json:"run_setup_tests,omitempty"` + DaylightSavingTimeEnabled *bool `json:"daylight_saving_time_enabled,omitempty"` + PrivateLinkId *string `json:"private_link_id,omitempty"` + LocalProcessingAgentId *string `json:"local_processing_agent_id,omitempty"` + NetworkingMethod *string `json:"networking_method,omitempty"` } type destinationSetupTestsRequest struct { - TrustCertificates *bool `json:"trust_certificates,omitempty"` - TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` + TrustCertificates *bool `json:"trust_certificates,omitempty"` + TrustFingerprints *bool `json:"trust_fingerprints,omitempty"` } diff --git a/destinations/destination_create.go b/destinations/destination_create.go index a5f786b6..8dd7b231 100644 --- a/destinations/destination_create.go +++ b/destinations/destination_create.go @@ -1,118 +1,142 @@ package destinations import ( - "context" + "context" - httputils "github.com/fivetran/go-fivetran/http_utils" + httputils "github.com/fivetran/go-fivetran/http_utils" ) // DestinationCreateService implements the Destination Management, Create a Destination API. // Ref. https://fivetran.com/docs/rest-api/destinations#createadestination type DestinationCreateService struct { - httputils.HttpService - groupID *string - service *string - region *string - timeZoneOffset *string - config *DestinationConfig - configCustom *map[string]interface{} - trustCertificates *bool - trustFingerprints *bool - runSetupTests *bool - daylightSavingTimeEnabled *bool + httputils.HttpService + groupID *string + service *string + region *string + timeZoneOffset *string + config *DestinationConfig + configCustom *map[string]interface{} + trustCertificates *bool + trustFingerprints *bool + runSetupTests *bool + daylightSavingTimeEnabled *bool + localProcessingAgentId *string + networkingMethod *string + privateLinkId *string } func (s *DestinationCreateService) GroupID(value string) *DestinationCreateService { - s.groupID = &value - return s + s.groupID = &value + return s } func (s *DestinationCreateService) Service(value string) *DestinationCreateService { - s.service = &value - return s + s.service = &value + return s } func (s *DestinationCreateService) Region(value string) *DestinationCreateService { - s.region = &value - return s + s.region = &value + return s } func (s *DestinationCreateService) TimeZoneOffset(value string) *DestinationCreateService { - s.timeZoneOffset = &value - return s + s.timeZoneOffset = &value + return s } func (s *DestinationCreateService) Config(value *DestinationConfig) *DestinationCreateService { - s.config = value - return s + s.config = value + return s } func (s *DestinationCreateService) ConfigCustom(value *map[string]interface{}) *DestinationCreateService { - s.configCustom = value - return s + s.configCustom = value + return s } func (s *DestinationCreateService) TrustCertificates(value bool) *DestinationCreateService { - s.trustCertificates = &value - return s + s.trustCertificates = &value + return s } func (s *DestinationCreateService) TrustFingerprints(value bool) *DestinationCreateService { - s.trustFingerprints = &value - return s + s.trustFingerprints = &value + return s } func (s *DestinationCreateService) RunSetupTests(value bool) *DestinationCreateService { - s.runSetupTests = &value - return s + s.runSetupTests = &value + return s } func (s *DestinationCreateService) DaylightSavingTimeEnabled(value bool) *DestinationCreateService { - s.daylightSavingTimeEnabled = &value - return s + s.daylightSavingTimeEnabled = &value + return s +} + +func (s *DestinationCreateService) LocalProcessingAgentId(value string) *DestinationCreateService { + s.localProcessingAgentId = &value + return s +} + +func (s *DestinationCreateService) PrivateLinkId(value string) *DestinationCreateService { + s.privateLinkId = &value + return s +} + +func (s *DestinationCreateService) NetworkingMethod(value string) *DestinationCreateService { + s.networkingMethod = &value + return s } func (s *DestinationCreateService) Do(ctx context.Context) (DestinationDetailsWithSetupTestsResponse, error) { - var response DestinationDetailsWithSetupTestsResponse - err := s.HttpService.Do(ctx, "POST", "/destinations", s.request(), nil, 201, &response) - return response, err + var response DestinationDetailsWithSetupTestsResponse + 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 + 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, - DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, - } + 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, + DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, + PrivateLinkId: s.privateLinkId, + LocalProcessingAgentId: s.localProcessingAgentId, + NetworkingMethod: s.networkingMethod, + } } 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, - DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, - } + 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, + DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, + PrivateLinkId: s.privateLinkId, + LocalProcessingAgentId: s.localProcessingAgentId, + NetworkingMethod: s.networkingMethod, + } } diff --git a/destinations/destination_create_test.go b/destinations/destination_create_test.go index bcb7832a..99ec14b6 100644 --- a/destinations/destination_create_test.go +++ b/destinations/destination_create_test.go @@ -1,152 +1,161 @@ package destinations_test import ( - "context" - "fmt" - "net/http" - "strconv" - "testing" + "context" + "fmt" + "net/http" + "strconv" + "testing" - "github.com/fivetran/go-fivetran" - "github.com/fivetran/go-fivetran/destinations" + "github.com/fivetran/go-fivetran" + "github.com/fivetran/go-fivetran/destinations" - "github.com/fivetran/go-fivetran/tests/mock" + "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" + testutils "github.com/fivetran/go-fivetran/test_utils" ) const ( - SERVICE = "test_service" - ID = "test_id" - REGION = "GCP_US_EAST4" - TIME_ZONE = "-5" - SETUP_STATUS = "connected" - TEST_TITLE = "Test Title" - TEST_STATUS = "PASSED" - TEST_MESSAGE = "Test message" - HOST = "your.host" - PORT = 443 - DATABASE = "fivetran" - AUTH = "PASSWORD" - USER = "fivetran_user" - MASKED = "******" - CONNECTION_TYPE = "Directly" - TUNNEL_HOST = "tunnel.host" - TUNNEL_PORT = "334" - TUNNEL_USER = "tunnel_user" - PROJECT_ID = "project_id_value" - DATA_SET_LOCATION = "data_Set_location_value" - LOCATION = "data_Set_location_value" - BUCKET = "your-bucket" - SERVER_HOST_NAME = "server.host.name" - HTTP_PATH = "http.path" - CREATE_EXTERNAL_TABLES = true - EXTERNAL_LOCATION = "group_id" - AUTH_TYPE = "auth_type_value" - ROLE_ARN = "role:arn-xxx" - PUBLIC_KEY = "public_key_value" - CLUSTER_ID = "cluster_id_value" - CLUSTER_REGION = "cluster_region_value" - PASSWORD = "password" - PRIVATE_KEY = "private_key" - SECRET_KEY = "secret_key" - TRUST_CERTIFICATES = true - TRUST_FINGERPRINTS = true - RUN_SETUP_TESTS = true - DAYLIGHTSAVINGTIMEENABLED = true - PERSONAL_ACCESS_TOKEN = "PAT" - ROLE = "role" - PASSPHRASE = "passphrase" - IS_PRIVATE_KEY_ENCRYPTED = true - CATALOG = "catalog" - FIVETRAN_ROLE_ARN = "fivetran_role_arn" - PREFIX_PATH = "prefix_path" - STORAGE_ACCOUNT_NAME = "storage_account_name" - CONTAINER_NAME = "container_name" - TENANT_ID = "tenant_id" - CLIENT_ID = "client_id" - SECRET_VALUE = "secret_value" - WORKSPACE_NAME = "workspace_name" - LAKEHOUSE_NAME = "lakehouse_name" + SERVICE = "test_service" + ID = "test_id" + REGION = "GCP_US_EAST4" + TIME_ZONE = "-5" + SETUP_STATUS = "connected" + TEST_TITLE = "Test Title" + TEST_STATUS = "PASSED" + TEST_MESSAGE = "Test message" + HOST = "your.host" + PORT = 443 + DATABASE = "fivetran" + AUTH = "PASSWORD" + USER = "fivetran_user" + MASKED = "******" + CONNECTION_TYPE = "Directly" + TUNNEL_HOST = "tunnel.host" + TUNNEL_PORT = "334" + TUNNEL_USER = "tunnel_user" + PROJECT_ID = "project_id_value" + DATA_SET_LOCATION = "data_Set_location_value" + LOCATION = "data_Set_location_value" + BUCKET = "your-bucket" + SERVER_HOST_NAME = "server.host.name" + HTTP_PATH = "http.path" + CREATE_EXTERNAL_TABLES = true + EXTERNAL_LOCATION = "group_id" + AUTH_TYPE = "auth_type_value" + ROLE_ARN = "role:arn-xxx" + PUBLIC_KEY = "public_key_value" + CLUSTER_ID = "cluster_id_value" + CLUSTER_REGION = "cluster_region_value" + PASSWORD = "password" + PRIVATE_KEY = "private_key" + SECRET_KEY = "secret_key" + TRUST_CERTIFICATES = true + TRUST_FINGERPRINTS = true + RUN_SETUP_TESTS = true + DAYLIGHTSAVINGTIMEENABLED = true + PERSONAL_ACCESS_TOKEN = "PAT" + ROLE = "role" + PASSPHRASE = "passphrase" + IS_PRIVATE_KEY_ENCRYPTED = true + CATALOG = "catalog" + FIVETRAN_ROLE_ARN = "fivetran_role_arn" + PREFIX_PATH = "prefix_path" + STORAGE_ACCOUNT_NAME = "storage_account_name" + CONTAINER_NAME = "container_name" + TENANT_ID = "tenant_id" + CLIENT_ID = "client_id" + SECRET_VALUE = "secret_value" + WORKSPACE_NAME = "workspace_name" + LAKEHOUSE_NAME = "lakehouse_name" + LOCALPROCESSINGAGENTID = "lpa_id" + PRIVATELINKID = "private_link_id" + NETWORKINGMETHOD = "Direct" ) func TestNewDestinationCreateFullMappingMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/destinations").ThenCall( - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertRequest(t, body) - response := mock.NewResponse(req, http.StatusCreated, prepareDestinationResponse()) - return response, nil - }) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/destinations").ThenCall( + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareDestinationResponse()) + return response, nil + }) - // act - response, err := ftClient.NewDestinationCreate(). - Service(SERVICE). - Region(REGION). - TimeZoneOffset(TIME_ZONE). - TrustCertificates(TRUST_CERTIFICATES). - TrustFingerprints(TRUST_FINGERPRINTS). - RunSetupTests(RUN_SETUP_TESTS). - DaylightSavingTimeEnabled(DAYLIGHTSAVINGTIMEENABLED). - GroupID(ID). - Config(prepareConfig()). - Do(context.Background()) + // act + response, err := ftClient.NewDestinationCreate(). + Service(SERVICE). + Region(REGION). + TimeZoneOffset(TIME_ZONE). + TrustCertificates(TRUST_CERTIFICATES). + TrustFingerprints(TRUST_FINGERPRINTS). + RunSetupTests(RUN_SETUP_TESTS). + DaylightSavingTimeEnabled(DAYLIGHTSAVINGTIMEENABLED). + LocalProcessingAgentId(LOCALPROCESSINGAGENTID). + PrivateLinkId(PRIVATELINKID). + NetworkingMethod(NETWORKINGMETHOD). + GroupID(ID). + Config(prepareConfig()). + Do(context.Background()) - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } - // testutils.Assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - assertResponse(t, response) + // testutils.Assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertResponse(t, response) } func TestNewDestinationCreateCustomFullMappingMock(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/destinations").ThenCall( - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertRequest(t, body) - response := mock.NewResponse(req, http.StatusCreated, prepareDestinationResponse()) - return response, nil - }) + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/destinations").ThenCall( + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareDestinationResponse()) + return response, nil + }) - // act - response, err := ftClient.NewDestinationCreate(). - Service(SERVICE). - Region(REGION). - TimeZoneOffset(TIME_ZONE). - TrustCertificates(TRUST_CERTIFICATES). - TrustFingerprints(TRUST_FINGERPRINTS). - RunSetupTests(RUN_SETUP_TESTS). - DaylightSavingTimeEnabled(DAYLIGHTSAVINGTIMEENABLED). - GroupID(ID). - ConfigCustom(prepareConfigCustom()). - DoCustom(context.Background()) + // act + response, err := ftClient.NewDestinationCreate(). + Service(SERVICE). + Region(REGION). + TimeZoneOffset(TIME_ZONE). + TrustCertificates(TRUST_CERTIFICATES). + TrustFingerprints(TRUST_FINGERPRINTS). + RunSetupTests(RUN_SETUP_TESTS). + DaylightSavingTimeEnabled(DAYLIGHTSAVINGTIMEENABLED). + LocalProcessingAgentId(LOCALPROCESSINGAGENTID). + PrivateLinkId(PRIVATELINKID). + NetworkingMethod(NETWORKINGMETHOD). + GroupID(ID). + ConfigCustom(prepareConfigCustom()). + DoCustom(context.Background()) - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } - // testutils.Assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - asserResponseCustom(t, response) + // testutils.Assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + asserResponseCustom(t, response) } func prepareDestinationResponse() string { - return fmt.Sprintf( - `{ + return fmt.Sprintf( + `{ "code":"Created", "message":"Destination has been created", "data":{ @@ -156,6 +165,9 @@ func prepareDestinationResponse() string { "region": "%v", "time_zone_offset": "%v", "daylight_saving_time_enabled": %v, + "local_processing_agent_id": "%v", + "private_link_id": "%v", + "networking_method": "%v", "setup_status": "%v", "setup_tests":[ { @@ -208,314 +220,325 @@ func prepareDestinationResponse() string { } } }`, - ID, // id - ID, // group_id - SERVICE, - REGION, - TIME_ZONE, // time_zone_offset - DAYLIGHTSAVINGTIMEENABLED, - SETUP_STATUS, - TEST_TITLE, - TEST_STATUS, - TEST_MESSAGE, - HOST, - PORT, - DATABASE, - AUTH, - USER, - MASKED, // password - CONNECTION_TYPE, - TUNNEL_HOST, - TUNNEL_PORT, - TUNNEL_USER, - PROJECT_ID, - DATA_SET_LOCATION, - LOCATION, - BUCKET, - SERVER_HOST_NAME, - HTTP_PATH, - MASKED, // personal_access_token - CREATE_EXTERNAL_TABLES, - EXTERNAL_LOCATION, - AUTH_TYPE, - ROLE_ARN, - MASKED, // secret_key - MASKED, // private_key - PUBLIC_KEY, - CLUSTER_ID, - CLUSTER_REGION, - ROLE, - IS_PRIVATE_KEY_ENCRYPTED, - PASSPHRASE, - CATALOG, - FIVETRAN_ROLE_ARN, - PREFIX_PATH, - REGION, - STORAGE_ACCOUNT_NAME, - CONTAINER_NAME, - TENANT_ID, - CLIENT_ID, - SECRET_VALUE, - WORKSPACE_NAME, - LAKEHOUSE_NAME, - ) + ID, // id + ID, // group_id + SERVICE, + REGION, + TIME_ZONE, // time_zone_offset + DAYLIGHTSAVINGTIMEENABLED, + LOCALPROCESSINGAGENTID, + PRIVATELINKID, + NETWORKINGMETHOD, + SETUP_STATUS, + TEST_TITLE, + TEST_STATUS, + TEST_MESSAGE, + HOST, + PORT, + DATABASE, + AUTH, + USER, + MASKED, // password + CONNECTION_TYPE, + TUNNEL_HOST, + TUNNEL_PORT, + TUNNEL_USER, + PROJECT_ID, + DATA_SET_LOCATION, + LOCATION, + BUCKET, + SERVER_HOST_NAME, + HTTP_PATH, + MASKED, // personal_access_token + CREATE_EXTERNAL_TABLES, + EXTERNAL_LOCATION, + AUTH_TYPE, + ROLE_ARN, + MASKED, // secret_key + MASKED, // private_key + PUBLIC_KEY, + CLUSTER_ID, + CLUSTER_REGION, + ROLE, + IS_PRIVATE_KEY_ENCRYPTED, + PASSPHRASE, + CATALOG, + FIVETRAN_ROLE_ARN, + PREFIX_PATH, + REGION, + STORAGE_ACCOUNT_NAME, + CONTAINER_NAME, + TENANT_ID, + CLIENT_ID, + SECRET_VALUE, + WORKSPACE_NAME, + LAKEHOUSE_NAME, + ) } func prepareConfigCustom() *map[string]interface{} { - return &(map[string]interface{}{ - "host": HOST, - "port": PORT, - "database": DATABASE, - "auth": AUTH, - "user": USER, - "password": PASSWORD, - "connection_type": CONNECTION_TYPE, - "tunnel_host": TUNNEL_HOST, - "tunnel_port": TUNNEL_PORT, - "tunnel_user": TUNNEL_USER, - "project_id": PROJECT_ID, - "bucket": BUCKET, - "server_host_name": SERVER_HOST_NAME, - "http_path": HTTP_PATH, - "personal_access_token": PERSONAL_ACCESS_TOKEN, - "create_external_tables": CREATE_EXTERNAL_TABLES, - "external_location": EXTERNAL_LOCATION, - "auth_type": AUTH_TYPE, - "role_arn": ROLE_ARN, - "secret_key": SECRET_KEY, - "private_key": PRIVATE_KEY, - "cluster_id": CLUSTER_ID, - "cluster_region": CLUSTER_REGION, - "role": ROLE, - "is_private_key_encrypted": IS_PRIVATE_KEY_ENCRYPTED, - "passphrase": PASSPHRASE, - "catalog": CATALOG, - "fivetran_role_arn": FIVETRAN_ROLE_ARN, - "region": REGION, - "prefix_path": PREFIX_PATH, - "storage_account_name": STORAGE_ACCOUNT_NAME, - "container_name": CONTAINER_NAME, - "tenant_id": TENANT_ID, - "client_id": CLIENT_ID, - "secret_value": SECRET_VALUE, - "workspace_name": WORKSPACE_NAME, - "lakehouse_name": LAKEHOUSE_NAME, - }) + return &(map[string]interface{}{ + "host": HOST, + "port": PORT, + "database": DATABASE, + "auth": AUTH, + "user": USER, + "password": PASSWORD, + "connection_type": CONNECTION_TYPE, + "tunnel_host": TUNNEL_HOST, + "tunnel_port": TUNNEL_PORT, + "tunnel_user": TUNNEL_USER, + "project_id": PROJECT_ID, + "bucket": BUCKET, + "server_host_name": SERVER_HOST_NAME, + "http_path": HTTP_PATH, + "personal_access_token": PERSONAL_ACCESS_TOKEN, + "create_external_tables": CREATE_EXTERNAL_TABLES, + "external_location": EXTERNAL_LOCATION, + "auth_type": AUTH_TYPE, + "role_arn": ROLE_ARN, + "secret_key": SECRET_KEY, + "private_key": PRIVATE_KEY, + "cluster_id": CLUSTER_ID, + "cluster_region": CLUSTER_REGION, + "role": ROLE, + "is_private_key_encrypted": IS_PRIVATE_KEY_ENCRYPTED, + "passphrase": PASSPHRASE, + "catalog": CATALOG, + "fivetran_role_arn": FIVETRAN_ROLE_ARN, + "region": REGION, + "prefix_path": PREFIX_PATH, + "storage_account_name": STORAGE_ACCOUNT_NAME, + "container_name": CONTAINER_NAME, + "tenant_id": TENANT_ID, + "client_id": CLIENT_ID, + "secret_value": SECRET_VALUE, + "workspace_name": WORKSPACE_NAME, + "lakehouse_name": LAKEHOUSE_NAME, + }) } func prepareConfig() *destinations.DestinationConfig { - config := fivetran.NewDestinationConfig() - config.Host(HOST) - config.Port(PORT) - config.Database(DATABASE) - config.Auth(AUTH) - config.User(USER) - config.Password(PASSWORD) - config.ConnectionType(CONNECTION_TYPE) - config.TunnelHost(TUNNEL_HOST) - config.TunnelPort(TUNNEL_PORT) - config.TunnelUser(TUNNEL_USER) - config.ProjectID(PROJECT_ID) - config.Bucket(BUCKET) - config.ServerHostName(SERVER_HOST_NAME) - config.HTTPPath(HTTP_PATH) - config.PersonalAccessToken(PERSONAL_ACCESS_TOKEN) - config.CreateExternalTables(CREATE_EXTERNAL_TABLES) - config.ExternalLocation(EXTERNAL_LOCATION) - config.AuthType(AUTH_TYPE) - config.RoleArn(ROLE_ARN) - config.SecretKey(SECRET_KEY) - config.PrivateKey(PRIVATE_KEY) - config.ClusterId(CLUSTER_ID) - config.ClusterRegion(CLUSTER_REGION) - config.Role(ROLE) - config.IsPrivateKeyEncrypted(IS_PRIVATE_KEY_ENCRYPTED) - config.Passphrase(PASSPHRASE) - config.Catalog(CATALOG) - config.FivetranRoleArn(FIVETRAN_ROLE_ARN) - config.PrefixPath(PREFIX_PATH) - config.Region(REGION) - config.StorageAccountName(STORAGE_ACCOUNT_NAME) - config.ContainerName(CONTAINER_NAME) - config.TenantId(TENANT_ID) - config.ClientId(CLIENT_ID) - config.SecretValue(SECRET_VALUE) - config.WorkspaceName(WORKSPACE_NAME) - config.LakehouseName(LAKEHOUSE_NAME) + config := fivetran.NewDestinationConfig() + config.Host(HOST) + config.Port(PORT) + config.Database(DATABASE) + config.Auth(AUTH) + config.User(USER) + config.Password(PASSWORD) + config.ConnectionType(CONNECTION_TYPE) + config.TunnelHost(TUNNEL_HOST) + config.TunnelPort(TUNNEL_PORT) + config.TunnelUser(TUNNEL_USER) + config.ProjectID(PROJECT_ID) + config.Bucket(BUCKET) + config.ServerHostName(SERVER_HOST_NAME) + config.HTTPPath(HTTP_PATH) + config.PersonalAccessToken(PERSONAL_ACCESS_TOKEN) + config.CreateExternalTables(CREATE_EXTERNAL_TABLES) + config.ExternalLocation(EXTERNAL_LOCATION) + config.AuthType(AUTH_TYPE) + config.RoleArn(ROLE_ARN) + config.SecretKey(SECRET_KEY) + config.PrivateKey(PRIVATE_KEY) + config.ClusterId(CLUSTER_ID) + config.ClusterRegion(CLUSTER_REGION) + config.Role(ROLE) + config.IsPrivateKeyEncrypted(IS_PRIVATE_KEY_ENCRYPTED) + config.Passphrase(PASSPHRASE) + config.Catalog(CATALOG) + config.FivetranRoleArn(FIVETRAN_ROLE_ARN) + config.PrefixPath(PREFIX_PATH) + config.Region(REGION) + config.StorageAccountName(STORAGE_ACCOUNT_NAME) + config.ContainerName(CONTAINER_NAME) + config.TenantId(TENANT_ID) + config.ClientId(CLIENT_ID) + config.SecretValue(SECRET_VALUE) + config.WorkspaceName(WORKSPACE_NAME) + config.LakehouseName(LAKEHOUSE_NAME) - return config + return config } func assertRequest(t *testing.T, request map[string]interface{}) { - testutils.AssertKey(t, "service", request, SERVICE) - testutils.AssertKey(t, "region", request, REGION) - testutils.AssertKey(t, "time_zone_offset", request, TIME_ZONE) - testutils.AssertKey(t, "trust_certificates", request, TRUST_CERTIFICATES) - testutils.AssertKey(t, "trust_fingerprints", request, TRUST_FINGERPRINTS) - testutils.AssertKey(t, "run_setup_tests", request, RUN_SETUP_TESTS) - testutils.AssertKey(t, "daylight_saving_time_enabled", request, DAYLIGHTSAVINGTIMEENABLED) - - testutils.AssertKey(t, "group_id", request, ID) + testutils.AssertKey(t, "service", request, SERVICE) + testutils.AssertKey(t, "region", request, REGION) + testutils.AssertKey(t, "time_zone_offset", request, TIME_ZONE) + testutils.AssertKey(t, "trust_certificates", request, TRUST_CERTIFICATES) + testutils.AssertKey(t, "trust_fingerprints", request, TRUST_FINGERPRINTS) + testutils.AssertKey(t, "run_setup_tests", request, RUN_SETUP_TESTS) + testutils.AssertKey(t, "daylight_saving_time_enabled", request, DAYLIGHTSAVINGTIMEENABLED) + testutils.AssertKey(t, "local_processing_agent_id", request, LOCALPROCESSINGAGENTID) + testutils.AssertKey(t, "private_link_id", request, PRIVATELINKID) + testutils.AssertKey(t, "networking_method", request, NETWORKINGMETHOD) + testutils.AssertKey(t, "group_id", request, ID) - c, ok := request["config"] - testutils.AssertEqual(t, ok, true) - config, ok := c.(map[string]interface{}) - testutils.AssertEqual(t, ok, true) + c, ok := request["config"] + testutils.AssertEqual(t, ok, true) + config, ok := c.(map[string]interface{}) + testutils.AssertEqual(t, ok, true) - testutils.AssertKey(t, "host", config, HOST) - testutils.AssertKey(t, "port", config, float64(PORT)) // json marshalling stores all numbers as float64 - testutils.AssertKey(t, "database", config, DATABASE) - testutils.AssertKey(t, "auth", config, AUTH) - testutils.AssertKey(t, "user", config, USER) - testutils.AssertKey(t, "password", config, PASSWORD) - testutils.AssertKey(t, "connection_type", config, CONNECTION_TYPE) - testutils.AssertKey(t, "tunnel_host", config, TUNNEL_HOST) - testutils.AssertKey(t, "tunnel_port", config, TUNNEL_PORT) - testutils.AssertKey(t, "tunnel_user", config, TUNNEL_USER) - testutils.AssertKey(t, "project_id", config, PROJECT_ID) - testutils.AssertKey(t, "bucket", config, BUCKET) - testutils.AssertKey(t, "server_host_name", config, SERVER_HOST_NAME) - testutils.AssertKey(t, "http_path", config, HTTP_PATH) - testutils.AssertKey(t, "personal_access_token", config, PERSONAL_ACCESS_TOKEN) - testutils.AssertKey(t, "create_external_tables", config, CREATE_EXTERNAL_TABLES) - testutils.AssertKey(t, "external_location", config, EXTERNAL_LOCATION) - testutils.AssertKey(t, "auth_type", config, AUTH_TYPE) - testutils.AssertKey(t, "role_arn", config, ROLE_ARN) - testutils.AssertKey(t, "secret_key", config, SECRET_KEY) - testutils.AssertKey(t, "private_key", config, PRIVATE_KEY) - testutils.AssertKey(t, "cluster_id", config, CLUSTER_ID) - testutils.AssertKey(t, "cluster_region", config, CLUSTER_REGION) - testutils.AssertKey(t, "role", config, ROLE) - testutils.AssertKey(t, "is_private_key_encrypted", config, IS_PRIVATE_KEY_ENCRYPTED) - testutils.AssertKey(t, "passphrase", config, PASSPHRASE) - testutils.AssertKey(t, "catalog", config, CATALOG) - testutils.AssertKey(t, "fivetran_role_arn", config, FIVETRAN_ROLE_ARN) - testutils.AssertKey(t, "prefix_path", config, PREFIX_PATH) - testutils.AssertKey(t, "region", config, REGION) - testutils.AssertKey(t, "storage_account_name", config, STORAGE_ACCOUNT_NAME) - testutils.AssertKey(t, "container_name", config, CONTAINER_NAME) - testutils.AssertKey(t, "tenant_id", config, TENANT_ID) - testutils.AssertKey(t, "client_id", config, CLIENT_ID) - testutils.AssertKey(t, "secret_value", config, SECRET_VALUE) - testutils.AssertKey(t, "workspace_name", config, WORKSPACE_NAME) - testutils.AssertKey(t, "lakehouse_name", config, LAKEHOUSE_NAME) + testutils.AssertKey(t, "host", config, HOST) + testutils.AssertKey(t, "port", config, float64(PORT)) // json marshalling stores all numbers as float64 + testutils.AssertKey(t, "database", config, DATABASE) + testutils.AssertKey(t, "auth", config, AUTH) + testutils.AssertKey(t, "user", config, USER) + testutils.AssertKey(t, "password", config, PASSWORD) + testutils.AssertKey(t, "connection_type", config, CONNECTION_TYPE) + testutils.AssertKey(t, "tunnel_host", config, TUNNEL_HOST) + testutils.AssertKey(t, "tunnel_port", config, TUNNEL_PORT) + testutils.AssertKey(t, "tunnel_user", config, TUNNEL_USER) + testutils.AssertKey(t, "project_id", config, PROJECT_ID) + testutils.AssertKey(t, "bucket", config, BUCKET) + testutils.AssertKey(t, "server_host_name", config, SERVER_HOST_NAME) + testutils.AssertKey(t, "http_path", config, HTTP_PATH) + testutils.AssertKey(t, "personal_access_token", config, PERSONAL_ACCESS_TOKEN) + testutils.AssertKey(t, "create_external_tables", config, CREATE_EXTERNAL_TABLES) + testutils.AssertKey(t, "external_location", config, EXTERNAL_LOCATION) + testutils.AssertKey(t, "auth_type", config, AUTH_TYPE) + testutils.AssertKey(t, "role_arn", config, ROLE_ARN) + testutils.AssertKey(t, "secret_key", config, SECRET_KEY) + testutils.AssertKey(t, "private_key", config, PRIVATE_KEY) + testutils.AssertKey(t, "cluster_id", config, CLUSTER_ID) + testutils.AssertKey(t, "cluster_region", config, CLUSTER_REGION) + testutils.AssertKey(t, "role", config, ROLE) + testutils.AssertKey(t, "is_private_key_encrypted", config, IS_PRIVATE_KEY_ENCRYPTED) + testutils.AssertKey(t, "passphrase", config, PASSPHRASE) + testutils.AssertKey(t, "catalog", config, CATALOG) + testutils.AssertKey(t, "fivetran_role_arn", config, FIVETRAN_ROLE_ARN) + testutils.AssertKey(t, "prefix_path", config, PREFIX_PATH) + testutils.AssertKey(t, "region", config, REGION) + testutils.AssertKey(t, "storage_account_name", config, STORAGE_ACCOUNT_NAME) + testutils.AssertKey(t, "container_name", config, CONTAINER_NAME) + testutils.AssertKey(t, "tenant_id", config, TENANT_ID) + testutils.AssertKey(t, "client_id", config, CLIENT_ID) + testutils.AssertKey(t, "secret_value", config, SECRET_VALUE) + testutils.AssertKey(t, "workspace_name", config, WORKSPACE_NAME) + testutils.AssertKey(t, "lakehouse_name", config, LAKEHOUSE_NAME) } func asserResponseCustom(t *testing.T, response destinations.DestinationDetailsWithSetupTestsCustomResponse) { - testutils.AssertEqual(t, response.Code, "Created") - testutils.AssertNotEmpty(t, response.Message) + testutils.AssertEqual(t, response.Code, "Created") + testutils.AssertNotEmpty(t, response.Message) - testutils.AssertEqual(t, response.Data.GroupID, ID) - testutils.AssertEqual(t, response.Data.ID, ID) - testutils.AssertEqual(t, response.Data.Region, REGION) - testutils.AssertEqual(t, response.Data.Service, SERVICE) - testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DAYLIGHTSAVINGTIMEENABLED) - testutils.AssertEqual(t, response.Data.SetupStatus, SETUP_STATUS) - testutils.AssertEqual(t, response.Data.TimeZoneOffset, TIME_ZONE) + testutils.AssertEqual(t, response.Data.GroupID, ID) + testutils.AssertEqual(t, response.Data.ID, ID) + testutils.AssertEqual(t, response.Data.Region, REGION) + testutils.AssertEqual(t, response.Data.Service, SERVICE) + testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DAYLIGHTSAVINGTIMEENABLED) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.PrivateLinkId, PRIVATELINKID) + testutils.AssertEqual(t, response.Data.NetworkingMethod, NETWORKINGMETHOD) + testutils.AssertEqual(t, response.Data.SetupStatus, SETUP_STATUS) + testutils.AssertEqual(t, response.Data.TimeZoneOffset, TIME_ZONE) - testutils.AssertEqual(t, len(response.Data.SetupTests), 1) - testutils.AssertEqual(t, response.Data.SetupTests[0].Message, TEST_MESSAGE) - testutils.AssertEqual(t, response.Data.SetupTests[0].Status, TEST_STATUS) - testutils.AssertEqual(t, response.Data.SetupTests[0].Title, TEST_TITLE) + testutils.AssertEqual(t, len(response.Data.SetupTests), 1) + testutils.AssertEqual(t, response.Data.SetupTests[0].Message, TEST_MESSAGE) + testutils.AssertEqual(t, response.Data.SetupTests[0].Status, TEST_STATUS) + testutils.AssertEqual(t, response.Data.SetupTests[0].Title, TEST_TITLE) - testutils.AssertEqual(t, response.Data.Config["auth"], AUTH) - testutils.AssertEqual(t, response.Data.Config["auth_type"], AUTH_TYPE) - testutils.AssertEqual(t, response.Data.Config["bucket"], BUCKET) - testutils.AssertEqual(t, response.Data.Config["cluster_id"], CLUSTER_ID) - testutils.AssertEqual(t, response.Data.Config["cluster_region"], CLUSTER_REGION) - testutils.AssertEqual(t, response.Data.Config["connection_type"], CONNECTION_TYPE) - testutils.AssertEqual(t, response.Data.Config["create_external_tables"], testutils.BoolToStr(CREATE_EXTERNAL_TABLES)) // Inconsistent response - testutils.AssertEqual(t, response.Data.Config["data_set_location"], DATA_SET_LOCATION) - testutils.AssertEqual(t, response.Data.Config["database"], DATABASE) - testutils.AssertEqual(t, response.Data.Config["external_location"], EXTERNAL_LOCATION) - testutils.AssertEqual(t, response.Data.Config["http_path"], HTTP_PATH) - testutils.AssertEqual(t, response.Data.Config["host"], HOST) - testutils.AssertEqual(t, response.Data.Config["password"], MASKED) - testutils.AssertEqual(t, response.Data.Config["personal_access_token"], MASKED) - testutils.AssertEqual(t, response.Data.Config["port"], strconv.Itoa(PORT)) - testutils.AssertEqual(t, response.Data.Config["private_key"], MASKED) - testutils.AssertEqual(t, response.Data.Config["project_id"], PROJECT_ID) - testutils.AssertEqual(t, response.Data.Config["public_key"], PUBLIC_KEY) - testutils.AssertEqual(t, response.Data.Config["role_arn"], ROLE_ARN) - testutils.AssertEqual(t, response.Data.Config["secret_key"], MASKED) - testutils.AssertEqual(t, response.Data.Config["server_host_name"], SERVER_HOST_NAME) - testutils.AssertEqual(t, response.Data.Config["tunnel_host"], TUNNEL_HOST) - testutils.AssertEqual(t, response.Data.Config["tunnel_port"], TUNNEL_PORT) - testutils.AssertEqual(t, response.Data.Config["tunnel_user"], TUNNEL_USER) - testutils.AssertEqual(t, response.Data.Config["user"], USER) - testutils.AssertEqual(t, response.Data.Config["location"], LOCATION) - testutils.AssertEqual(t, response.Data.Config["role"], ROLE) - testutils.AssertEqual(t, response.Data.Config["is_private_key_encrypted"], testutils.BoolToStr(IS_PRIVATE_KEY_ENCRYPTED)) - testutils.AssertEqual(t, response.Data.Config["passphrase"], PASSPHRASE) - testutils.AssertEqual(t, response.Data.Config["catalog"], CATALOG) - testutils.AssertEqual(t, response.Data.Config["fivetran_role_arn"], FIVETRAN_ROLE_ARN) - testutils.AssertEqual(t, response.Data.Config["prefix_path"], PREFIX_PATH) - testutils.AssertEqual(t, response.Data.Config["region"], REGION) - testutils.AssertEqual(t, response.Data.Config["storage_account_name"], STORAGE_ACCOUNT_NAME) - testutils.AssertEqual(t, response.Data.Config["container_name"], CONTAINER_NAME) - testutils.AssertEqual(t, response.Data.Config["tenant_id"], TENANT_ID) - testutils.AssertEqual(t, response.Data.Config["client_id"], CLIENT_ID) - testutils.AssertEqual(t, response.Data.Config["secret_value"], SECRET_VALUE) - testutils.AssertEqual(t, response.Data.Config["workspace_name"], WORKSPACE_NAME) - testutils.AssertEqual(t, response.Data.Config["lakehouse_name"], LAKEHOUSE_NAME) + testutils.AssertEqual(t, response.Data.Config["auth"], AUTH) + testutils.AssertEqual(t, response.Data.Config["auth_type"], AUTH_TYPE) + testutils.AssertEqual(t, response.Data.Config["bucket"], BUCKET) + testutils.AssertEqual(t, response.Data.Config["cluster_id"], CLUSTER_ID) + testutils.AssertEqual(t, response.Data.Config["cluster_region"], CLUSTER_REGION) + testutils.AssertEqual(t, response.Data.Config["connection_type"], CONNECTION_TYPE) + testutils.AssertEqual(t, response.Data.Config["create_external_tables"], testutils.BoolToStr(CREATE_EXTERNAL_TABLES)) // Inconsistent response + testutils.AssertEqual(t, response.Data.Config["data_set_location"], DATA_SET_LOCATION) + testutils.AssertEqual(t, response.Data.Config["database"], DATABASE) + testutils.AssertEqual(t, response.Data.Config["external_location"], EXTERNAL_LOCATION) + testutils.AssertEqual(t, response.Data.Config["http_path"], HTTP_PATH) + testutils.AssertEqual(t, response.Data.Config["host"], HOST) + testutils.AssertEqual(t, response.Data.Config["password"], MASKED) + testutils.AssertEqual(t, response.Data.Config["personal_access_token"], MASKED) + testutils.AssertEqual(t, response.Data.Config["port"], strconv.Itoa(PORT)) + testutils.AssertEqual(t, response.Data.Config["private_key"], MASKED) + testutils.AssertEqual(t, response.Data.Config["project_id"], PROJECT_ID) + testutils.AssertEqual(t, response.Data.Config["public_key"], PUBLIC_KEY) + testutils.AssertEqual(t, response.Data.Config["role_arn"], ROLE_ARN) + testutils.AssertEqual(t, response.Data.Config["secret_key"], MASKED) + testutils.AssertEqual(t, response.Data.Config["server_host_name"], SERVER_HOST_NAME) + testutils.AssertEqual(t, response.Data.Config["tunnel_host"], TUNNEL_HOST) + testutils.AssertEqual(t, response.Data.Config["tunnel_port"], TUNNEL_PORT) + testutils.AssertEqual(t, response.Data.Config["tunnel_user"], TUNNEL_USER) + testutils.AssertEqual(t, response.Data.Config["user"], USER) + testutils.AssertEqual(t, response.Data.Config["location"], LOCATION) + testutils.AssertEqual(t, response.Data.Config["role"], ROLE) + testutils.AssertEqual(t, response.Data.Config["is_private_key_encrypted"], testutils.BoolToStr(IS_PRIVATE_KEY_ENCRYPTED)) + testutils.AssertEqual(t, response.Data.Config["passphrase"], PASSPHRASE) + testutils.AssertEqual(t, response.Data.Config["catalog"], CATALOG) + testutils.AssertEqual(t, response.Data.Config["fivetran_role_arn"], FIVETRAN_ROLE_ARN) + testutils.AssertEqual(t, response.Data.Config["prefix_path"], PREFIX_PATH) + testutils.AssertEqual(t, response.Data.Config["region"], REGION) + testutils.AssertEqual(t, response.Data.Config["storage_account_name"], STORAGE_ACCOUNT_NAME) + testutils.AssertEqual(t, response.Data.Config["container_name"], CONTAINER_NAME) + testutils.AssertEqual(t, response.Data.Config["tenant_id"], TENANT_ID) + testutils.AssertEqual(t, response.Data.Config["client_id"], CLIENT_ID) + testutils.AssertEqual(t, response.Data.Config["secret_value"], SECRET_VALUE) + testutils.AssertEqual(t, response.Data.Config["workspace_name"], WORKSPACE_NAME) + testutils.AssertEqual(t, response.Data.Config["lakehouse_name"], LAKEHOUSE_NAME) } func assertResponse(t *testing.T, response destinations.DestinationDetailsWithSetupTestsResponse) { - testutils.AssertEqual(t, response.Code, "Created") - testutils.AssertNotEmpty(t, response.Message) + testutils.AssertEqual(t, response.Code, "Created") + testutils.AssertNotEmpty(t, response.Message) - testutils.AssertEqual(t, response.Data.GroupID, ID) - testutils.AssertEqual(t, response.Data.ID, ID) - testutils.AssertEqual(t, response.Data.Region, REGION) - testutils.AssertEqual(t, response.Data.Service, SERVICE) - testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DAYLIGHTSAVINGTIMEENABLED) - testutils.AssertEqual(t, response.Data.SetupStatus, SETUP_STATUS) - testutils.AssertEqual(t, response.Data.TimeZoneOffset, TIME_ZONE) + testutils.AssertEqual(t, response.Data.GroupID, ID) + testutils.AssertEqual(t, response.Data.ID, ID) + testutils.AssertEqual(t, response.Data.Region, REGION) + testutils.AssertEqual(t, response.Data.Service, SERVICE) + testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DAYLIGHTSAVINGTIMEENABLED) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.PrivateLinkId, PRIVATELINKID) + testutils.AssertEqual(t, response.Data.NetworkingMethod, NETWORKINGMETHOD) + testutils.AssertEqual(t, response.Data.SetupStatus, SETUP_STATUS) + testutils.AssertEqual(t, response.Data.TimeZoneOffset, TIME_ZONE) - testutils.AssertEqual(t, len(response.Data.SetupTests), 1) - testutils.AssertEqual(t, response.Data.SetupTests[0].Message, TEST_MESSAGE) - testutils.AssertEqual(t, response.Data.SetupTests[0].Status, TEST_STATUS) - testutils.AssertEqual(t, response.Data.SetupTests[0].Title, TEST_TITLE) + testutils.AssertEqual(t, len(response.Data.SetupTests), 1) + testutils.AssertEqual(t, response.Data.SetupTests[0].Message, TEST_MESSAGE) + testutils.AssertEqual(t, response.Data.SetupTests[0].Status, TEST_STATUS) + testutils.AssertEqual(t, response.Data.SetupTests[0].Title, TEST_TITLE) - testutils.AssertEqual(t, response.Data.Config.Auth, AUTH) - testutils.AssertEqual(t, response.Data.Config.AuthType, AUTH_TYPE) - testutils.AssertEqual(t, response.Data.Config.Bucket, BUCKET) - testutils.AssertEqual(t, response.Data.Config.ClusterId, CLUSTER_ID) - testutils.AssertEqual(t, response.Data.Config.ClusterRegion, CLUSTER_REGION) - testutils.AssertEqual(t, response.Data.Config.ConnectionType, CONNECTION_TYPE) - testutils.AssertEqual(t, response.Data.Config.CreateExternalTables, testutils.BoolToStr(CREATE_EXTERNAL_TABLES)) // Inconsistent response - testutils.AssertEqual(t, response.Data.Config.DataSetLocation, DATA_SET_LOCATION) - testutils.AssertEqual(t, response.Data.Config.Database, DATABASE) - testutils.AssertEqual(t, response.Data.Config.ExternalLocation, EXTERNAL_LOCATION) - testutils.AssertEqual(t, response.Data.Config.HTTPPath, HTTP_PATH) - testutils.AssertEqual(t, response.Data.Config.Host, HOST) - testutils.AssertEqual(t, response.Data.Config.Password, MASKED) - testutils.AssertEqual(t, response.Data.Config.PersonalAccessToken, MASKED) - testutils.AssertEqual(t, response.Data.Config.Port, strconv.Itoa(PORT)) - testutils.AssertEqual(t, response.Data.Config.PrivateKey, MASKED) - testutils.AssertEqual(t, response.Data.Config.ProjectID, PROJECT_ID) - testutils.AssertEqual(t, response.Data.Config.PublicKey, PUBLIC_KEY) - testutils.AssertEqual(t, response.Data.Config.RoleArn, ROLE_ARN) - testutils.AssertEqual(t, response.Data.Config.SecretKey, MASKED) - testutils.AssertEqual(t, response.Data.Config.ServerHostName, SERVER_HOST_NAME) - testutils.AssertEqual(t, response.Data.Config.TunnelHost, TUNNEL_HOST) - testutils.AssertEqual(t, response.Data.Config.TunnelPort, TUNNEL_PORT) - testutils.AssertEqual(t, response.Data.Config.TunnelUser, TUNNEL_USER) - testutils.AssertEqual(t, response.Data.Config.User, USER) - testutils.AssertEqual(t, response.Data.Config.Location, LOCATION) - testutils.AssertEqual(t, response.Data.Config.Role, ROLE) - testutils.AssertEqual(t, response.Data.Config.IsPrivateKeyEncrypted, testutils.BoolToStr(IS_PRIVATE_KEY_ENCRYPTED)) - testutils.AssertEqual(t, response.Data.Config.Passphrase, PASSPHRASE) - testutils.AssertEqual(t, response.Data.Config.Catalog, CATALOG) - testutils.AssertEqual(t, response.Data.Config.FivetranRoleArn, FIVETRAN_ROLE_ARN) - testutils.AssertEqual(t, response.Data.Config.PrefixPath, PREFIX_PATH) - testutils.AssertEqual(t, response.Data.Config.Region, REGION) - testutils.AssertEqual(t, response.Data.Config.StorageAccountName, STORAGE_ACCOUNT_NAME) - testutils.AssertEqual(t, response.Data.Config.ContainerName, CONTAINER_NAME) - testutils.AssertEqual(t, response.Data.Config.TenantId, TENANT_ID) - testutils.AssertEqual(t, response.Data.Config.ClientId, CLIENT_ID) - testutils.AssertEqual(t, response.Data.Config.SecretValue, SECRET_VALUE) - testutils.AssertEqual(t, response.Data.Config.WorkspaceName, WORKSPACE_NAME) - testutils.AssertEqual(t, response.Data.Config.LakehouseName, LAKEHOUSE_NAME) + testutils.AssertEqual(t, response.Data.Config.Auth, AUTH) + testutils.AssertEqual(t, response.Data.Config.AuthType, AUTH_TYPE) + testutils.AssertEqual(t, response.Data.Config.Bucket, BUCKET) + testutils.AssertEqual(t, response.Data.Config.ClusterId, CLUSTER_ID) + testutils.AssertEqual(t, response.Data.Config.ClusterRegion, CLUSTER_REGION) + testutils.AssertEqual(t, response.Data.Config.ConnectionType, CONNECTION_TYPE) + testutils.AssertEqual(t, response.Data.Config.CreateExternalTables, testutils.BoolToStr(CREATE_EXTERNAL_TABLES)) // Inconsistent response + testutils.AssertEqual(t, response.Data.Config.DataSetLocation, DATA_SET_LOCATION) + testutils.AssertEqual(t, response.Data.Config.Database, DATABASE) + testutils.AssertEqual(t, response.Data.Config.ExternalLocation, EXTERNAL_LOCATION) + testutils.AssertEqual(t, response.Data.Config.HTTPPath, HTTP_PATH) + testutils.AssertEqual(t, response.Data.Config.Host, HOST) + testutils.AssertEqual(t, response.Data.Config.Password, MASKED) + testutils.AssertEqual(t, response.Data.Config.PersonalAccessToken, MASKED) + testutils.AssertEqual(t, response.Data.Config.Port, strconv.Itoa(PORT)) + testutils.AssertEqual(t, response.Data.Config.PrivateKey, MASKED) + testutils.AssertEqual(t, response.Data.Config.ProjectID, PROJECT_ID) + testutils.AssertEqual(t, response.Data.Config.PublicKey, PUBLIC_KEY) + testutils.AssertEqual(t, response.Data.Config.RoleArn, ROLE_ARN) + testutils.AssertEqual(t, response.Data.Config.SecretKey, MASKED) + testutils.AssertEqual(t, response.Data.Config.ServerHostName, SERVER_HOST_NAME) + testutils.AssertEqual(t, response.Data.Config.TunnelHost, TUNNEL_HOST) + testutils.AssertEqual(t, response.Data.Config.TunnelPort, TUNNEL_PORT) + testutils.AssertEqual(t, response.Data.Config.TunnelUser, TUNNEL_USER) + testutils.AssertEqual(t, response.Data.Config.User, USER) + testutils.AssertEqual(t, response.Data.Config.Location, LOCATION) + testutils.AssertEqual(t, response.Data.Config.Role, ROLE) + testutils.AssertEqual(t, response.Data.Config.IsPrivateKeyEncrypted, testutils.BoolToStr(IS_PRIVATE_KEY_ENCRYPTED)) + testutils.AssertEqual(t, response.Data.Config.Passphrase, PASSPHRASE) + testutils.AssertEqual(t, response.Data.Config.Catalog, CATALOG) + testutils.AssertEqual(t, response.Data.Config.FivetranRoleArn, FIVETRAN_ROLE_ARN) + testutils.AssertEqual(t, response.Data.Config.PrefixPath, PREFIX_PATH) + testutils.AssertEqual(t, response.Data.Config.Region, REGION) + testutils.AssertEqual(t, response.Data.Config.StorageAccountName, STORAGE_ACCOUNT_NAME) + testutils.AssertEqual(t, response.Data.Config.ContainerName, CONTAINER_NAME) + testutils.AssertEqual(t, response.Data.Config.TenantId, TENANT_ID) + testutils.AssertEqual(t, response.Data.Config.ClientId, CLIENT_ID) + testutils.AssertEqual(t, response.Data.Config.SecretValue, SECRET_VALUE) + testutils.AssertEqual(t, response.Data.Config.WorkspaceName, WORKSPACE_NAME) + testutils.AssertEqual(t, response.Data.Config.LakehouseName, LAKEHOUSE_NAME) } diff --git a/destinations/destination_details_test.go b/destinations/destination_details_test.go index c3d3bcfd..8eafcb9b 100644 --- a/destinations/destination_details_test.go +++ b/destinations/destination_details_test.go @@ -19,6 +19,9 @@ const DESTINATION_DETAILS_REGION = "GCP_US_EAST4" const DESTINATION_DETAILS_TIME_ZONE = "-5" const DESTINATION_DETAILS_SETUP_STATUS = "connected" const DESTINATION_DETAILS_DAYLIGHT = true +const DESTINATION_DETAILS_LOCALPROCESSINGAGENTID = "lpa_id" +const DESTINATION_DETAILS_PRIVATELINKID = "private_link_id" +const DESTINATION_DETAILS_NETWORKINGMETHOD = "Direct" const DESTINATION_DETAILS_HOST = "your-account.snowflakecomputing.com" const DESTINATION_DETAILS_PORT = "443" const DESTINATION_DETAILS_DATABASE = "fivetran" @@ -91,6 +94,9 @@ func prepareDestinationDetailsResponse() string { "service": "%s", "region": "%s", "daylight_saving_time_enabled": %v, + "local_processing_agent_id": "%v", + "private_link_id": "%v", + "networking_method": "%v", "time_zone_offset": "%s", "setup_status": "%s", "config": { @@ -108,6 +114,9 @@ func prepareDestinationDetailsResponse() string { DESTINATION_DETAILS_SERVICE, DESTINATION_DETAILS_REGION, DESTINATION_DETAILS_DAYLIGHT, + DESTINATION_DETAILS_LOCALPROCESSINGAGENTID, + DESTINATION_DETAILS_PRIVATELINKID, + DESTINATION_DETAILS_NETWORKINGMETHOD, DESTINATION_DETAILS_TIME_ZONE, DESTINATION_DETAILS_SETUP_STATUS, DESTINATION_DETAILS_HOST, @@ -125,6 +134,9 @@ func assertDestinationDetailsResponse(t *testing.T, response destinations.Destin testutils.AssertEqual(t, response.Data.Service, DESTINATION_DETAILS_SERVICE) testutils.AssertEqual(t, response.Data.Region, DESTINATION_DETAILS_REGION) testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DESTINATION_DETAILS_DAYLIGHT) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, DESTINATION_DETAILS_LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.PrivateLinkId, DESTINATION_DETAILS_PRIVATELINKID) + testutils.AssertEqual(t, response.Data.NetworkingMethod, DESTINATION_DETAILS_NETWORKINGMETHOD) testutils.AssertEqual(t, response.Data.TimeZoneOffset, DESTINATION_DETAILS_TIME_ZONE) testutils.AssertEqual(t, response.Data.SetupStatus, DESTINATION_DETAILS_SETUP_STATUS) testutils.AssertEqual(t, response.Data.Config.Host, DESTINATION_DETAILS_HOST) @@ -141,6 +153,9 @@ func assertDestinationDetailsCustomResponse(t *testing.T, response destinations. testutils.AssertEqual(t, response.Data.GroupID, DESTINATION_DETAILS_ID) testutils.AssertEqual(t, response.Data.Service, DESTINATION_DETAILS_SERVICE) testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DESTINATION_DETAILS_DAYLIGHT) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, DESTINATION_DETAILS_LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.PrivateLinkId, DESTINATION_DETAILS_PRIVATELINKID) + testutils.AssertEqual(t, response.Data.NetworkingMethod, DESTINATION_DETAILS_NETWORKINGMETHOD) testutils.AssertEqual(t, response.Data.Region, DESTINATION_DETAILS_REGION) testutils.AssertEqual(t, response.Data.TimeZoneOffset, DESTINATION_DETAILS_TIME_ZONE) testutils.AssertEqual(t, response.Data.SetupStatus, DESTINATION_DETAILS_SETUP_STATUS) diff --git a/destinations/destination_modify.go b/destinations/destination_modify.go index 4f71b0bf..38d5be48 100644 --- a/destinations/destination_modify.go +++ b/destinations/destination_modify.go @@ -1,122 +1,146 @@ package destinations import ( - "context" - "fmt" + "context" + "fmt" - httputils "github.com/fivetran/go-fivetran/http_utils" + httputils "github.com/fivetran/go-fivetran/http_utils" ) // DestinationModifyService implements the Destination Management, Modify a Destination API. // Ref. https://fivetran.com/docs/rest-api/destinations#modifyadestination type DestinationModifyService struct { - httputils.HttpService - destinationID *string - region *string - timeZoneOffset *string - config *DestinationConfig - configCustom *map[string]interface{} - trustCertificates *bool - trustFingerprints *bool - runSetupTests *bool - daylightSavingTimeEnabled *bool + httputils.HttpService + destinationID *string + region *string + timeZoneOffset *string + config *DestinationConfig + configCustom *map[string]interface{} + trustCertificates *bool + trustFingerprints *bool + runSetupTests *bool + daylightSavingTimeEnabled *bool + localProcessingAgentId *string + networkingMethod *string + privateLinkId *string } func (s *DestinationModifyService) request() *destinationModifyRequest { - var config interface{} - - if s.config != nil { - config = s.config.Request() - } - - return &destinationModifyRequest{ - Region: s.region, - TimeZoneOffset: s.timeZoneOffset, - Config: config, - TrustCertificates: s.trustCertificates, - TrustFingerprints: s.trustFingerprints, - RunSetupTests: s.runSetupTests, - DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, - } + var config interface{} + + if s.config != nil { + config = s.config.Request() + } + + return &destinationModifyRequest{ + Region: s.region, + TimeZoneOffset: s.timeZoneOffset, + Config: config, + TrustCertificates: s.trustCertificates, + TrustFingerprints: s.trustFingerprints, + RunSetupTests: s.runSetupTests, + DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, + PrivateLinkId: s.privateLinkId, + LocalProcessingAgentId: s.localProcessingAgentId, + NetworkingMethod: s.networkingMethod, + } } func (s *DestinationModifyService) requestCustom() *destinationModifyRequest { - return &destinationModifyRequest{ - Region: s.region, - TimeZoneOffset: s.timeZoneOffset, - Config: s.configCustom, - TrustCertificates: s.trustCertificates, - TrustFingerprints: s.trustFingerprints, - RunSetupTests: s.runSetupTests, - DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, - } + return &destinationModifyRequest{ + Region: s.region, + TimeZoneOffset: s.timeZoneOffset, + Config: s.configCustom, + TrustCertificates: s.trustCertificates, + TrustFingerprints: s.trustFingerprints, + RunSetupTests: s.runSetupTests, + DaylightSavingTimeEnabled: s.daylightSavingTimeEnabled, + PrivateLinkId: s.privateLinkId, + LocalProcessingAgentId: s.localProcessingAgentId, + NetworkingMethod: s.networkingMethod, + } } func (s *DestinationModifyService) DestinationID(value string) *DestinationModifyService { - s.destinationID = &value - return s + s.destinationID = &value + return s } func (s *DestinationModifyService) Region(value string) *DestinationModifyService { - s.region = &value - return s + s.region = &value + return s } func (s *DestinationModifyService) TimeZoneOffset(value string) *DestinationModifyService { - s.timeZoneOffset = &value - return s + s.timeZoneOffset = &value + return s } func (s *DestinationModifyService) Config(value *DestinationConfig) *DestinationModifyService { - s.config = value - return s + s.config = value + return s } func (s *DestinationModifyService) ConfigCustom(value *map[string]interface{}) *DestinationModifyService { - s.configCustom = value - return s + s.configCustom = value + return s } func (s *DestinationModifyService) TrustCertificates(value bool) *DestinationModifyService { - s.trustCertificates = &value - return s + s.trustCertificates = &value + return s } func (s *DestinationModifyService) TrustFingerprints(value bool) *DestinationModifyService { - s.trustFingerprints = &value - return s + s.trustFingerprints = &value + return s } func (s *DestinationModifyService) RunSetupTests(value bool) *DestinationModifyService { - s.runSetupTests = &value - return s + s.runSetupTests = &value + return s } func (s *DestinationModifyService) DaylightSavingTimeEnabled(value bool) *DestinationModifyService { - s.daylightSavingTimeEnabled = &value - return s + s.daylightSavingTimeEnabled = &value + return s +} + +func (s *DestinationModifyService) LocalProcessingAgentId(value string) *DestinationModifyService { + s.localProcessingAgentId = &value + return s +} + +func (s *DestinationModifyService) PrivateLinkId(value string) *DestinationModifyService { + s.privateLinkId = &value + return s +} + +func (s *DestinationModifyService) NetworkingMethod(value string) *DestinationModifyService { + s.networkingMethod = &value + return s } func (s *DestinationModifyService) Do(ctx context.Context) (DestinationDetailsWithSetupTestsResponse, error) { - var response DestinationDetailsWithSetupTestsResponse + var response DestinationDetailsWithSetupTestsResponse - if s.destinationID == nil { - return response, fmt.Errorf("missing required DestinationID") - } + if s.destinationID == nil { + return response, fmt.Errorf("missing required DestinationID") + } - url := fmt.Sprintf("/destinations/%v", *s.destinationID) - err := s.HttpService.Do(ctx, "PATCH", url, s.request(), nil, 200, &response) - return response, err + url := fmt.Sprintf("/destinations/%v", *s.destinationID) + err := s.HttpService.Do(ctx, "PATCH", url, s.request(), nil, 200, &response) + return response, err } func (s *DestinationModifyService) DoCustom(ctx context.Context) (DestinationDetailsWithSetupTestsCustomResponse, error) { - var response DestinationDetailsWithSetupTestsCustomResponse + var response DestinationDetailsWithSetupTestsCustomResponse - if s.destinationID == nil { - return response, fmt.Errorf("missing required DestinationID") - } + if s.destinationID == nil { + return response, fmt.Errorf("missing required DestinationID") + } - url := fmt.Sprintf("/destinations/%v", *s.destinationID) - err := s.HttpService.Do(ctx, "PATCH", url, s.requestCustom(), nil, 200, &response) - return response, err + url := fmt.Sprintf("/destinations/%v", *s.destinationID) + err := s.HttpService.Do(ctx, "PATCH", url, s.requestCustom(), nil, 200, &response) + return response, err } diff --git a/destinations/destination_modify_test.go b/destinations/destination_modify_test.go index 9f9c81fe..1108d139 100644 --- a/destinations/destination_modify_test.go +++ b/destinations/destination_modify_test.go @@ -15,23 +15,26 @@ import ( ) const ( - DESTINATION_MODIFY_SERVICE = "snowflake" - DESTINATION_MODIFY_ID = "decent_dropsy" - DESTINATION_MODIFY_REGION = "GCP_AUSTRALIA_SOUTHEAST1" - DESTINATION_MODIFY_TIME_ZONE_OFFSET = "+10" - DESTINATION_MODIFY_DAYLIGHT = true - DESTINATION_MODIFY_SETUP_STATUS = "connected" - DESTINATION_MODIFY_TEST_TITLE_HOST = "Host Connection" - DESTINATION_MODIFY_TEST_TITLE_DB = "Database Connection" - DESTINATION_MODIFY_TEST_TITLE_PERM = "Permission Test" - DESTINATION_MODIFY_TEST_STATUS_PASSED = "PASSED" - DESTINATION_MODIFY_HOST = "your-account.snowflakecomputing.com" - DESTINATION_MODIFY_PORT = "1433" - DESTINATION_MODIFY_DATABASE = "fivetran" - DESTINATION_MODIFY_AUTH = "PASSWORD" - DESTINATION_MODIFY_USER = "fivetran_user" - DESTINATION_MODIFY_PASSWORD = "******" - DESTINATION_MODIFY_MASKED = "******" + DESTINATION_MODIFY_SERVICE = "snowflake" + DESTINATION_MODIFY_ID = "decent_dropsy" + DESTINATION_MODIFY_REGION = "GCP_AUSTRALIA_SOUTHEAST1" + DESTINATION_MODIFY_TIME_ZONE_OFFSET = "+10" + DESTINATION_MODIFY_DAYLIGHT = true + DESTINATION_MODIFY_LOCALPROCESSINGAGENTID = "lpa_id" + DESTINATION_MODIFY_PRIVATELINKID = "private_link_id" + DESTINATION_MODIFY_NETWORKINGMETHOD = "Direct" + DESTINATION_MODIFY_SETUP_STATUS = "connected" + DESTINATION_MODIFY_TEST_TITLE_HOST = "Host Connection" + DESTINATION_MODIFY_TEST_TITLE_DB = "Database Connection" + DESTINATION_MODIFY_TEST_TITLE_PERM = "Permission Test" + DESTINATION_MODIFY_TEST_STATUS_PASSED = "PASSED" + DESTINATION_MODIFY_HOST = "your-account.snowflakecomputing.com" + DESTINATION_MODIFY_PORT = "1433" + DESTINATION_MODIFY_DATABASE = "fivetran" + DESTINATION_MODIFY_AUTH = "PASSWORD" + DESTINATION_MODIFY_USER = "fivetran_user" + DESTINATION_MODIFY_PASSWORD = "******" + DESTINATION_MODIFY_MASKED = "******" ) func TestDestinationModifyService(t *testing.T) { @@ -60,6 +63,9 @@ func TestDestinationModifyService(t *testing.T) { TimeZoneOffset(DESTINATION_MODIFY_TIME_ZONE_OFFSET). Config(destinationConfig). DaylightSavingTimeEnabled(DESTINATION_MODIFY_DAYLIGHT). + LocalProcessingAgentId(DESTINATION_MODIFY_LOCALPROCESSINGAGENTID). + PrivateLinkId(DESTINATION_MODIFY_PRIVATELINKID). + NetworkingMethod(DESTINATION_MODIFY_NETWORKINGMETHOD). TrustCertificates(TRUST_CERTIFICATES). TrustFingerprints(TRUST_FINGERPRINTS). RunSetupTests(RUN_SETUP_TESTS) @@ -96,6 +102,9 @@ func TestDestinationModifyCustomService(t *testing.T) { DestinationID(DESTINATION_MODIFY_ID). Region(DESTINATION_MODIFY_REGION). DaylightSavingTimeEnabled(DESTINATION_MODIFY_DAYLIGHT). + LocalProcessingAgentId(DESTINATION_MODIFY_LOCALPROCESSINGAGENTID). + PrivateLinkId(DESTINATION_MODIFY_PRIVATELINKID). + NetworkingMethod(DESTINATION_MODIFY_NETWORKINGMETHOD). TimeZoneOffset(DESTINATION_MODIFY_TIME_ZONE_OFFSET). ConfigCustom(&map[string]interface{}{ "host": DESTINATION_MODIFY_HOST, @@ -135,7 +144,10 @@ func prepareDestinationModifyResponse() string { "group_id": "%s", "service": "%s", "region": "%s", - "daylight_saving_time_enabled": %v, + "daylight_saving_time_enabled": %v, + "local_processing_agent_id": "%v", + "private_link_id": "%v", + "networking_method": "%v", "time_zone_offset": "%s", "setup_status": "%s", "setup_tests": [ @@ -170,6 +182,9 @@ func prepareDestinationModifyResponse() string { DESTINATION_MODIFY_SERVICE, DESTINATION_MODIFY_REGION, DESTINATION_MODIFY_DAYLIGHT, + DESTINATION_MODIFY_LOCALPROCESSINGAGENTID, + DESTINATION_MODIFY_PRIVATELINKID, + DESTINATION_MODIFY_NETWORKINGMETHOD, DESTINATION_MODIFY_TIME_ZONE_OFFSET, DESTINATION_MODIFY_SETUP_STATUS, DESTINATION_MODIFY_TEST_TITLE_HOST, @@ -193,6 +208,9 @@ func assertDestinationModifyResponse(t *testing.T, response destinations.Destina testutils.AssertEqual(t, response.Data.GroupID, DESTINATION_MODIFY_ID) testutils.AssertEqual(t, response.Data.Service, DESTINATION_MODIFY_SERVICE) testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DESTINATION_MODIFY_DAYLIGHT) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, DESTINATION_MODIFY_LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.PrivateLinkId, DESTINATION_MODIFY_PRIVATELINKID) + testutils.AssertEqual(t, response.Data.NetworkingMethod, DESTINATION_MODIFY_NETWORKINGMETHOD) testutils.AssertEqual(t, response.Data.Region, DESTINATION_MODIFY_REGION) testutils.AssertEqual(t, response.Data.TimeZoneOffset, DESTINATION_MODIFY_TIME_ZONE_OFFSET) testutils.AssertEqual(t, response.Data.SetupStatus, DESTINATION_MODIFY_SETUP_STATUS) @@ -222,6 +240,10 @@ func assertDestinationModifyCustomResponse(t *testing.T, response destinations.D testutils.AssertEqual(t, response.Data.GroupID, DESTINATION_MODIFY_ID) testutils.AssertEqual(t, response.Data.Service, DESTINATION_MODIFY_SERVICE) testutils.AssertEqual(t, response.Data.DaylightSavingTimeEnabled, DESTINATION_MODIFY_DAYLIGHT) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, DESTINATION_MODIFY_LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.LocalProcessingAgentId, DESTINATION_MODIFY_LOCALPROCESSINGAGENTID) + testutils.AssertEqual(t, response.Data.PrivateLinkId, DESTINATION_MODIFY_PRIVATELINKID) + testutils.AssertEqual(t, response.Data.NetworkingMethod, DESTINATION_MODIFY_NETWORKINGMETHOD) testutils.AssertEqual(t, response.Data.Region, DESTINATION_MODIFY_REGION) testutils.AssertEqual(t, response.Data.TimeZoneOffset, DESTINATION_MODIFY_TIME_ZONE_OFFSET) testutils.AssertEqual(t, response.Data.SetupStatus, DESTINATION_MODIFY_SETUP_STATUS) diff --git a/fivetran.go b/fivetran.go index 8f8ebdfd..38eaa4a9 100644 --- a/fivetran.go +++ b/fivetran.go @@ -6,7 +6,7 @@ import ( "github.com/fivetran/go-fivetran/destinations" "github.com/fivetran/go-fivetran/connect_card" externallogging "github.com/fivetran/go-fivetran/external_logging" - "github.com/fivetran/go-fivetran/private_links" + "github.com/fivetran/go-fivetran/private_link" httputils "github.com/fivetran/go-fivetran/http_utils" ) @@ -74,8 +74,8 @@ func NewConnectCardConfig() *connectcard.ConnectCardConfig { return &connectcard.ConnectCardConfig{} } -func NewPrivateLinksConfig() *privatelinks.PrivateLinksConfig { - return &privatelinks.PrivateLinksConfig{} +func NewPrivateLinkConfig() *privatelink.PrivateLinkConfig { + return &privatelink.PrivateLinkConfig{} } func Debug(value bool) { diff --git a/groups/common_types.go b/groups/common_types.go index 4168d5f0..83549736 100644 --- a/groups/common_types.go +++ b/groups/common_types.go @@ -6,7 +6,6 @@ import ( "github.com/fivetran/go-fivetran/common" "github.com/fivetran/go-fivetran/connectors" "github.com/fivetran/go-fivetran/users" - "github.com/fivetran/go-fivetran/private_links" ) type GroupItem struct { @@ -50,14 +49,6 @@ type GroupListUsersResponse struct { } `json:"data"` } -type GroupListPrivateLinksResponse struct { - common.CommonResponse - Data struct { - Items []privatelinks.PrivateLinksResponseBase `json:"items"` - NextCursor string `json:"next_cursor"` - } `json:"data"` -} - type GroupsListResponse struct { common.CommonResponse Data struct { diff --git a/groups/group_private_links_list.go b/groups/group_private_links_list.go deleted file mode 100644 index 1ad5780e..00000000 --- a/groups/group_private_links_list.go +++ /dev/null @@ -1,47 +0,0 @@ -package groups - -import ( - "context" - "fmt" - - httputils "github.com/fivetran/go-fivetran/http_utils" -) - -type GroupListPrivateLinksService struct { - httputils.HttpService - groupID *string - limit *int - cursor *string -} - -func (s *GroupListPrivateLinksService) GroupID(value string) *GroupListPrivateLinksService { - s.groupID = &value - return s -} - -func (s *GroupListPrivateLinksService) Limit(value int) *GroupListPrivateLinksService { - s.limit = &value - return s -} - -func (s *GroupListPrivateLinksService) Cursor(value string) *GroupListPrivateLinksService { - s.cursor = &value - return s -} - -func (s *GroupListPrivateLinksService) Do(ctx context.Context) (GroupListPrivateLinksResponse, error) { - var response GroupListPrivateLinksResponse - url := fmt.Sprintf("/groups/%v/private-links", *s.groupID) - var queries map[string]string = nil - if s.cursor != nil || s.limit != nil { - queries = make(map[string]string) - if s.cursor != nil { - queries["cursor"] = *s.cursor - } - if s.limit != nil { - queries["limit"] = fmt.Sprintf("%v", *s.limit) - } - } - err := s.HttpService.Do(ctx, "GET", url, nil, queries, 200, &response) - return response, err -} diff --git a/groups/group_private_links_list_test.go b/groups/group_private_links_list_test.go deleted file mode 100644 index 188dbd97..00000000 --- a/groups/group_private_links_list_test.go +++ /dev/null @@ -1,105 +0,0 @@ -package groups_test - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/fivetran/go-fivetran/groups" - "github.com/fivetran/go-fivetran/tests/mock" - - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -const ( - GROUP_LIST_PRIVATE_LINK_ID = "123456789123456789" - GROUP_LIST_PRIVATE_LINK_NAME = "name" - GROUP_LIST_PRIVATE_LINK_GROUP_ID = "group" - GROUP_LIST_PRIVATE_LINK_CLOUD = "cloud" - GROUP_LIST_PRIVATE_LINK_REGION = "region" - GROUP_LIST_PRIVATE_LINK_STATE = "state" - GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY = "state_summary" - GROUP_LIST_PRIVATE_LINK_CREATED_AT = "2018-01-15T11:00:27.329220Z" - GROUP_LIST_PRIVATE_LINK_CREATED_BY = "created_by" -) - -func TestGroupListPrivateLinksServiceDo(t *testing.T) { - // arrange - groupID := "projected_sickle" - limit := 10 - cursor := "eyJza2lwIjoxfQ" - - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodGet, fmt.Sprintf("/v1/groups/%s/private-links", groupID)). - ThenCall(func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, prepareGroupListPrivateLinksResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewGroupListPrivateLinks(). - GroupID(groupID). - Limit(limit). - Cursor(cursor). - Do(context.Background()) - - // assert - if err != nil { - t.Error(err) - } - - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - assertGroupListPrivateLinksResponse(t, response) -} - -func prepareGroupListPrivateLinksResponse() string { - value := fmt.Sprintf(`{ - "code": "Success", - "data": { - "items": [ - { - "id": "%v", - "name": "%v", - "group_id": "%v", - "cloud_provider": "%v", - "region": "%v", - "state": "%v", - "state_summary": "%v", - "created_at": "%v", - "created_by": "%v" - } - ], - "next_cursor": "eyJza2lwIjoyfQ" - } - }`, - GROUP_LIST_PRIVATE_LINK_ID, - GROUP_LIST_PRIVATE_LINK_NAME, - GROUP_LIST_PRIVATE_LINK_GROUP_ID, - GROUP_LIST_PRIVATE_LINK_CLOUD, - GROUP_LIST_PRIVATE_LINK_REGION, - GROUP_LIST_PRIVATE_LINK_STATE, - GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY, - GROUP_LIST_PRIVATE_LINK_CREATED_AT, - GROUP_LIST_PRIVATE_LINK_CREATED_BY) - return value -} - -func assertGroupListPrivateLinksResponse(t *testing.T, response groups.GroupListPrivateLinksResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, len(response.Data.Items), 1) - item := response.Data.Items[0] - testutils.AssertEqual(t, item.Id, GROUP_LIST_PRIVATE_LINK_ID) - testutils.AssertEqual(t, item.Name, GROUP_LIST_PRIVATE_LINK_NAME) - testutils.AssertEqual(t, item.GroupId, GROUP_LIST_PRIVATE_LINK_GROUP_ID) - testutils.AssertEqual(t, item.CloudProvider, GROUP_LIST_PRIVATE_LINK_CLOUD) - testutils.AssertEqual(t, item.Region, GROUP_LIST_PRIVATE_LINK_REGION) - testutils.AssertEqual(t, item.State, GROUP_LIST_PRIVATE_LINK_STATE) - testutils.AssertEqual(t, item.StateSummary, GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY) - testutils.AssertEqual(t, item.CreatedAt, GROUP_LIST_PRIVATE_LINK_CREATED_AT) - testutils.AssertEqual(t, item.CreatedBy, GROUP_LIST_PRIVATE_LINK_CREATED_BY) -} - diff --git a/local_processing_agent/common_types.go b/local_processing_agent/common_types.go new file mode 100644 index 00000000..e3dbbe7f --- /dev/null +++ b/local_processing_agent/common_types.go @@ -0,0 +1,60 @@ +package localprocessingagent + +type localProcessingAgentCreateRequest struct { + GroupId *string `json:"group_id,omitempty"` + DisplayName *string `json:"display_name,omitempty"` + EnvType *string `json:"env_type,omitempty"` + AcceptTerms *bool `json:"accept_terms,omitempty"` +} + +type LocalProcessingAgentDetails struct { + Id string `json:"id"` + DisplayName string `json:"display_name"` + GroupId string `json:"group_id"` + RegisteredAt string `json:"registered_at"` +} + +type LocalProcessingAgentUsageDetails struct { + ConnectionId string `json:"connection_id"` + Schema string `json:"schema"` + Service string `json:"service"` +} + +type LocalProcessingAgentData struct { + LocalProcessingAgentDetails + Usage []LocalProcessingAgentUsageDetails `json:"usage"` +} + +type LocalProcessingAgentCreateResponse struct { + Code string `json:"code"` + Message string `json:"message"` + Data struct { + LocalProcessingAgentDetails + Files struct { + ConfigJson string `json:"config_json"` + AuthJson string `json:"auth_json"` + DockerComposeYaml string `json:"docker_compose_yaml"` + } `json:"files"` + } `json:"data"` +} + +type LocalProcessingAgentDetailsResponse struct { + Code string `json:"code"` + Data LocalProcessingAgentData `json:"data"` +} + +type LocalProcessingAgentListResponse struct { + Code string `json:"code"` + Data struct { + Items []LocalProcessingAgentData `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` +} + + +type externalLoggingCreateRequestBase struct { + Id *string `json:"id,omitempty"` + GroupId *string `json:"group_id,omitempty"` + Service *string `json:"service,omitempty"` + Enabled *bool `json:"enabled,omitempty"` +} \ No newline at end of file diff --git a/local_processing_agent/local_processing_agents_create.go b/local_processing_agent/local_processing_agents_create.go new file mode 100644 index 00000000..5d250a2f --- /dev/null +++ b/local_processing_agent/local_processing_agents_create.go @@ -0,0 +1,52 @@ +package localprocessingagent + +import ( + "context" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// LocalProcessingAgentCreateService Creates a new local processing agent within your Fivetran account. +// Ref. https://fivetran.com/docs/rest-api/local-processing-agent-management#createalocalprocessingagent +type LocalProcessingAgentCreateService struct { + httputils.HttpService + groupId *string + displayName *string + envType *string + acceptTerms *bool +} + +func (s *LocalProcessingAgentCreateService) request() localProcessingAgentCreateRequest { + return localProcessingAgentCreateRequest{ + GroupId: s.groupId, + DisplayName: s.displayName, + EnvType: s.envType, + AcceptTerms: s.acceptTerms, + } +} + +func (s *LocalProcessingAgentCreateService) GroupId(value string) *LocalProcessingAgentCreateService { + s.groupId = &value + return s +} + +func (s *LocalProcessingAgentCreateService) DisplayName(value string) *LocalProcessingAgentCreateService { + s.displayName = &value + return s +} + +func (s *LocalProcessingAgentCreateService) EnvType(value string) *LocalProcessingAgentCreateService { + s.envType = &value + return s +} + +func (s *LocalProcessingAgentCreateService) AcceptTerms(value bool) *LocalProcessingAgentCreateService { + s.acceptTerms = &value + return s +} + +func (s *LocalProcessingAgentCreateService) Do(ctx context.Context) (LocalProcessingAgentCreateResponse, error) { + var response LocalProcessingAgentCreateResponse + err := s.HttpService.Do(ctx, "POST", "/local-processing-agents", s.request(), nil, 201, &response) + return response, err +} \ No newline at end of file diff --git a/local_processing_agent/local_processing_agents_create_test.go b/local_processing_agent/local_processing_agents_create_test.go new file mode 100644 index 00000000..9d601ee7 --- /dev/null +++ b/local_processing_agent/local_processing_agents_create_test.go @@ -0,0 +1,83 @@ +package localprocessingagent_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran/local_processing_agent" + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewLocalProcessingAgentCreateMappingMock(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/local-processing-agents").ThenCall( + + func(req *http.Request) (*http.Response, error) { + body := testutils.RequestBodyToJson(t, req) + assertLocalProcessingAgentCreateRequest(t, body) + response := mock.NewResponse(req, http.StatusCreated, prepareLocalProcessingAgentCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewLocalProcessingAgentCreate(). + GroupId("group_id"). + DisplayName("display_name"). + EnvType("DOCKER"). + AcceptTerms(true). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertLocalProcessingAgentCreateResponse(t, response) +} + +func prepareLocalProcessingAgentCreateResponse() string { + return `{ + "code": "Success", + "message": "Success", + "data": { + "id": "id", + "display_name": "display_name", + "group_id": "group_id", + "registered_at": "1970-01-01T00:00:00.000000Z", + "files": { + "config_json": "config_json", + "auth_json": "auth_json", + "docker_compose_yaml": "docker_compose_yaml" + } + } + }` +} + +func assertLocalProcessingAgentCreateRequest(t *testing.T, request map[string]interface{}) { + testutils.AssertKey(t, "group_id", request, "group_id") + testutils.AssertKey(t, "display_name", request, "display_name") + testutils.AssertKey(t, "env_type", request, "DOCKER") + testutils.AssertKey(t, "accept_terms", request, true) +} + +func assertLocalProcessingAgentCreateResponse(t *testing.T, response localprocessingagent.LocalProcessingAgentCreateResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertNotEmpty(t, response.Message) + + testutils.AssertEqual(t, response.Data.Id, "id") + testutils.AssertEqual(t, response.Data.DisplayName, "display_name") + testutils.AssertEqual(t, response.Data.GroupId, "group_id") + testutils.AssertEqual(t, response.Data.RegisteredAt, "1970-01-01T00:00:00.000000Z") + testutils.AssertEqual(t, response.Data.Files.ConfigJson, "config_json") + testutils.AssertEqual(t, response.Data.Files.AuthJson, "auth_json") + testutils.AssertEqual(t, response.Data.Files.DockerComposeYaml, "docker_compose_yaml") +} diff --git a/local_processing_agent/local_processing_agents_delete.go b/local_processing_agent/local_processing_agents_delete.go new file mode 100644 index 00000000..89f96acc --- /dev/null +++ b/local_processing_agent/local_processing_agents_delete.go @@ -0,0 +1,33 @@ +package localprocessingagent + +import ( + "context" + "fmt" + + "github.com/fivetran/go-fivetran/common" + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// LocalProcessingAgentDeleteService Deletes the specified local processing agent from your Fivetran account. +// Ref. https://fivetran.com/docs/rest-api/local-processing-agent-management#deletealocalprocessingagent +type LocalProcessingAgentDeleteService struct { + httputils.HttpService + agentId *string +} + +func (s *LocalProcessingAgentDeleteService) AgentId(value string) *LocalProcessingAgentDeleteService { + s.agentId = &value + return s +} + +func (s *LocalProcessingAgentDeleteService) Do(ctx context.Context) (common.CommonResponse, error) { + var response common.CommonResponse + + if s.agentId == nil { + return response, fmt.Errorf("missing required agentId") + } + + url := fmt.Sprintf("/local-processing-agents/%v", *s.agentId) + err := s.HttpService.Do(ctx, "DELETE", url, nil, nil, 200, &response) + return response, err +} diff --git a/proxy/proxy_connection_membership_delete_test.go b/local_processing_agent/local_processing_agents_delete_test.go similarity index 50% rename from proxy/proxy_connection_membership_delete_test.go rename to local_processing_agent/local_processing_agents_delete_test.go index b22045bb..b3a5b450 100644 --- a/proxy/proxy_connection_membership_delete_test.go +++ b/local_processing_agent/local_processing_agents_delete_test.go @@ -1,4 +1,4 @@ -package proxy_test +package localprocessingagent_test import ( "context" @@ -13,17 +13,17 @@ import ( testutils "github.com/fivetran/go-fivetran/test_utils" ) -func TestProxyConnectionDeleteServiceDo(t *testing.T) { +func TestLocalProcessingAgentDeleteServiceDo(t *testing.T) { // arrange ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodDelete, "/v1/proxy/proxy_id/connections/connection_id").ThenCall( + handler := mockClient.When(http.MethodDelete, "/v1/local-processing-agents/agent_id").ThenCall( func(req *http.Request) (*http.Response, error) { response := mock.NewResponse(req, http.StatusOK, `{"code": "Success"}`) return response, nil }, ) - service := ftClient.NewProxyConnectionMembershipDelete().ProxyId("proxy_id").ConnectionId("connection_id") + service := ftClient.NewLocalProcessingAgentDelete().AgentId("agent_id") // act response, err := service.Do(context.Background()) @@ -33,7 +33,7 @@ func TestProxyConnectionDeleteServiceDo(t *testing.T) { t.Error(err) } - assertProxyConnectionDeleteResponse(t, response, "Success") + assertLocalProcessingAgentDeleteResponse(t, response, "Success") // Check that the expected interactions with the mock client occurred interactions := mockClient.Interactions() @@ -42,30 +42,21 @@ func TestProxyConnectionDeleteServiceDo(t *testing.T) { testutils.AssertEqual(t, handler.Interactions, 1) } -func TestProxyConnectionDeleteServiceDoMissingId(t *testing.T) { +func TestLocalProcessingAgentsDeleteServiceDoMissingAgentID(t *testing.T) { + // Create a test client ftClient, _ := testutils.CreateTestClient() - service := ftClient.NewProxyConnectionMembershipDelete() - // Call the Do method to execute the request - _, err := service.Do(context.Background()) - - // Check for expected error - expectedError := fmt.Errorf("missing required proxyId") - testutils.AssertEqual(t, err, expectedError) -} - -func TestProxyConnectionDeleteServiceDoMissingConnectionId(t *testing.T) { - ftClient, _ := testutils.CreateTestClient() - service := ftClient.NewProxyConnectionMembershipDelete().ProxyId("proxy_id") + // Create the ExternalLoggingDeleteService without setting the Log ID + service := ftClient.NewLocalProcessingAgentDelete() // Call the Do method to execute the request _, err := service.Do(context.Background()) // Check for expected error - expectedError := fmt.Errorf("missing required connectionId") + expectedError := fmt.Errorf("missing required agentId") testutils.AssertEqual(t, err, expectedError) } -func assertProxyConnectionDeleteResponse(t *testing.T, response common.CommonResponse, code string) { +func assertLocalProcessingAgentDeleteResponse(t *testing.T, response common.CommonResponse, code string) { testutils.AssertEqual(t, response.Code, code) } diff --git a/local_processing_agent/local_processing_agents_details.go b/local_processing_agent/local_processing_agents_details.go new file mode 100644 index 00000000..de735857 --- /dev/null +++ b/local_processing_agent/local_processing_agents_details.go @@ -0,0 +1,32 @@ +package localprocessingagent + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// LocalProcessingAgentDetailsService Retrieves the details of the specified local processing agent. +// Ref. https://fivetran.com/docs/rest-api/local-processing-agent-management#retrievelocalprocessingagentdetails +type LocalProcessingAgentDetailsService struct { + httputils.HttpService + agentId *string +} + +func (s *LocalProcessingAgentDetailsService) AgentId(value string) *LocalProcessingAgentDetailsService { + s.agentId = &value + return s +} + +func (s *LocalProcessingAgentDetailsService) Do(ctx context.Context) (LocalProcessingAgentDetailsResponse, error) { + var response LocalProcessingAgentDetailsResponse + + if s.agentId == nil { + return response, fmt.Errorf("missing required agentId") + } + + url := fmt.Sprintf("/local-processing-agents/%v", *s.agentId) + err := s.HttpService.Do(ctx, "GET", url, nil, nil, 200, &response) + return response, err +} diff --git a/local_processing_agent/local_processing_agents_details_test.go b/local_processing_agent/local_processing_agents_details_test.go new file mode 100644 index 00000000..83ecdab6 --- /dev/null +++ b/local_processing_agent/local_processing_agents_details_test.go @@ -0,0 +1,67 @@ +package localprocessingagent_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran/local_processing_agent" + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestLocalProcessingAgentDetailsServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/local-processing-agents/agent_id"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareLocalProcessingAgentDetailsResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewLocalProcessingAgentDetails(). + AgentId("agent_id"). + Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertLocalProcessingAgentDetailsResponse(t, response) +} + +func prepareLocalProcessingAgentDetailsResponse() string { + return `{ + "code": "Success", + "data": { + "id": "id", + "display_name": "display_name", + "group_id": "group_id", + "registered_at": "1970-01-01T00:00:00.000000Z", + "usage": [ + { + "connection_id": "connection_id", + "schema": "schema", + "service": "service" + } + ] + } +}` +} + +func assertLocalProcessingAgentDetailsResponse(t *testing.T, response localprocessingagent.LocalProcessingAgentDetailsResponse) { + testutils.AssertEqual(t, response.Data.Id, "id") + testutils.AssertEqual(t, response.Data.DisplayName, "display_name") + testutils.AssertEqual(t, response.Data.GroupId, "group_id") + testutils.AssertEqual(t, response.Data.RegisteredAt, "1970-01-01T00:00:00.000000Z") + testutils.AssertEqual(t, response.Data.Usage[0].ConnectionId, "connection_id") + testutils.AssertEqual(t, response.Data.Usage[0].Schema, "schema") + testutils.AssertEqual(t, response.Data.Usage[0].Service, "service") +} \ No newline at end of file diff --git a/local_processing_agent/local_processing_agents_list.go b/local_processing_agent/local_processing_agents_list.go new file mode 100644 index 00000000..b1dac241 --- /dev/null +++ b/local_processing_agent/local_processing_agents_list.go @@ -0,0 +1,43 @@ +package localprocessingagent + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// LocalProcessingAgentListService Returns a list of local processing agents with usage within your Fivetran account. +// Ref. https://fivetran.com/docs/rest-api/local-processing-agent-management#listlocalprocessingagents +type LocalProcessingAgentListService struct { + httputils.HttpService + limit *int + cursor *string +} + +func (s *LocalProcessingAgentListService) Limit(value int) *LocalProcessingAgentListService { + s.limit = &value + return s +} + +func (s *LocalProcessingAgentListService) Cursor(value string) *LocalProcessingAgentListService { + s.cursor = &value + return s +} + +func (s *LocalProcessingAgentListService) Do(ctx context.Context) (LocalProcessingAgentListResponse, error) { + var response LocalProcessingAgentListResponse + + var queries map[string]string = nil + if s.cursor != nil || s.limit != nil { + queries = make(map[string]string) + if s.cursor != nil { + queries["cursor"] = *s.cursor + } + if s.limit != nil { + queries["limit"] = fmt.Sprintf("%v", *s.limit) + } + } + err := s.HttpService.Do(ctx, "GET", "/local-processing-agents", nil, queries, 200, &response) + return response, err +} \ No newline at end of file diff --git a/local_processing_agent/local_processing_agents_list_test.go b/local_processing_agent/local_processing_agents_list_test.go new file mode 100644 index 00000000..2bb2c686 --- /dev/null +++ b/local_processing_agent/local_processing_agents_list_test.go @@ -0,0 +1,72 @@ +package localprocessingagent_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran/local_processing_agent" + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestLocalProcessingAgentListServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/local-processing-agents"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareLocalProcessingAgentListResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewLocalProcessingAgentList(). + Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertLocalProcessingAgentListResponse(t, response) +} + +func prepareLocalProcessingAgentListResponse() string { + return `{ + "code": "Success", + "data": { + "items": [ + { + "id": "id", + "display_name": "display_name", + "group_id": "group_id", + "registered_at": "1970-01-01T00:00:00.000000Z", + "usage": [ + { + "connection_id": "connection_id", + "schema": "schema", + "service": "service" + } + ] + } + ], + "next_cursor": null + } + }` +} + +func assertLocalProcessingAgentListResponse(t *testing.T, response localprocessingagent.LocalProcessingAgentListResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Items[0].Id, "id") + testutils.AssertEqual(t, response.Data.Items[0].DisplayName, "display_name") + testutils.AssertEqual(t, response.Data.Items[0].GroupId, "group_id") + testutils.AssertEqual(t, response.Data.Items[0].RegisteredAt, "1970-01-01T00:00:00.000000Z") + testutils.AssertEqual(t, response.Data.Items[0].Usage[0].ConnectionId, "connection_id") + testutils.AssertEqual(t, response.Data.Items[0].Usage[0].Schema, "schema") + testutils.AssertEqual(t, response.Data.Items[0].Usage[0].Service, "service") +} \ No newline at end of file diff --git a/local_processing_agent/local_processing_agents_reauth.go b/local_processing_agent/local_processing_agents_reauth.go new file mode 100644 index 00000000..a86e47fa --- /dev/null +++ b/local_processing_agent/local_processing_agents_reauth.go @@ -0,0 +1,32 @@ +package localprocessingagent + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// LocalProcessingAgentReAuthService Regenerates authentication keys for the specified local processing agent. +// Ref. https://fivetran.com/docs/rest-api/local-processing-agent-management#regeneratekeys +type LocalProcessingAgentReAuthService struct { + httputils.HttpService + agentId *string +} + +func (s *LocalProcessingAgentReAuthService) AgentId(value string) *LocalProcessingAgentReAuthService { + s.agentId = &value + return s +} + +func (s *LocalProcessingAgentReAuthService) Do(ctx context.Context) (LocalProcessingAgentCreateResponse, error) { + var response LocalProcessingAgentCreateResponse + + if s.agentId == nil { + return response, fmt.Errorf("missing required agentId") + } + + url := fmt.Sprintf("/local-processing-agents/%v/re-auth", *s.agentId) + err := s.HttpService.Do(ctx, "POST", url, nil, nil, 200, &response) + return response, err +} \ No newline at end of file diff --git a/local_processing_agent/local_processing_agents_reauth_test.go b/local_processing_agent/local_processing_agents_reauth_test.go new file mode 100644 index 00000000..adbb2ad1 --- /dev/null +++ b/local_processing_agent/local_processing_agents_reauth_test.go @@ -0,0 +1,70 @@ +package localprocessingagent_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran/local_processing_agent" + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewLocalProcessingAgentReAuthMappingMock(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/local-processing-agents/agent_id/re-auth").ThenCall( + + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, prepareLocalProcessingAgentResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewLocalProcessingAgentReAuth(). + AgentId("agent_id"). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", response) + t.Error(err) + } + + // assert + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + + assertLocalProcessingAgentResponse(t, response) +} + +func prepareLocalProcessingAgentResponse() string { + return `{ + "code": "Success", + "message": "Success", + "data": { + "id": "id", + "display_name": "display_name", + "group_id": "group_id", + "registered_at": "1970-01-01T00:00:00.000000Z", + "files": { + "config_json": "config_json", + "auth_json": "auth_json", + "docker_compose_yaml": "docker_compose_yaml" + } + } + }` +} + +func assertLocalProcessingAgentResponse(t *testing.T, response localprocessingagent.LocalProcessingAgentCreateResponse) { + testutils.AssertEqual(t, response.Code, "Success") + + testutils.AssertEqual(t, response.Data.Id, "id") + testutils.AssertEqual(t, response.Data.DisplayName, "display_name") + testutils.AssertEqual(t, response.Data.GroupId, "group_id") + testutils.AssertEqual(t, response.Data.RegisteredAt, "1970-01-01T00:00:00.000000Z") + testutils.AssertEqual(t, response.Data.Files.ConfigJson, "config_json") + testutils.AssertEqual(t, response.Data.Files.AuthJson, "auth_json") + testutils.AssertEqual(t, response.Data.Files.DockerComposeYaml, "docker_compose_yaml") +} diff --git a/private_link/common_types.go b/private_link/common_types.go new file mode 100644 index 00000000..03ecc1fb --- /dev/null +++ b/private_link/common_types.go @@ -0,0 +1,42 @@ +package privatelink + +type PrivateLinkResponseBase struct { + Id string `json:"id"` + Name string `json:"name"` + Region string `json:"region"` + Service string `json:"service"` + AccountId string `json:"account_id"` + CloudProvider string `json:"cloud_provider"` + State string `json:"state"` + StateSummary string `json:"state_summary"` + CreatedAt string `json:"created_at"` + CreatedBy string `json:"created_by"` +} + +type PrivateLinkResponse struct { + Code string `json:"code"` + Message string `json:"message"` + Data struct { + PrivateLinkResponseBase + Config PrivateLinkConfigResponse `json:"config"` + } `json:"data"` +} + +type PrivateLinkListResponse struct { + Code string `json:"code"` + Data struct { + Items []PrivateLinkResponseBase `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` +} + +type privateLinkCreateRequest struct { + Name *string `json:"name,omitempty"` + Region *string `json:"region,omitempty"` + Service *string `json:"service,omitempty"` + Config any `json:"config,omitempty"` +} + +type privateLinkModifyRequest struct { + Config any `json:"config,omitempty"` +} \ No newline at end of file diff --git a/private_link/private_link_config.go b/private_link/private_link_config.go new file mode 100644 index 00000000..e6b96d04 --- /dev/null +++ b/private_link/private_link_config.go @@ -0,0 +1,118 @@ +package privatelink + +// PrivateLinkConfig builds Private Link Management, Private Link Config. +// Ref. https://fivetran.com/docs/rest-api/private-link-management#privatelinketupconfigurations +type PrivateLinkConfig struct { + connectionServiceName *string + connectionServiceId *string + workspaceUrl *string + accountName *string + accountUrl *string + vpceId *string + plsId *string + awsAccountId *string + clusterIdentifier *string + subResourceName *string + privateConnectionServiceId *string +} + +type privateLinkConfigRequest struct { + ConnectionServiceName *string `json:"connection_service_name,omitempty"` + ConnectionServiceId *string `json:"connection_service_id,omitempty"` + WorkspaceUrl *string `json:"workspace_url,omitempty"` + AccountName *string `json:"account_name,omitempty"` + AccountUrl *string `json:"account_url,omitempty"` + VpceId *string `json:"vpce_id,omitempty"` + PlsId *string `json:"pls_id,omitempty"` + AwsAccountId *string `json:"aws_account_id,omitempty"` + ClusterIdentifier *string `json:"cluster_identifier,omitempty"` + SubResourceName *string `json:"sub_resource_name,omitempty"` + PrivateConnectionServiceId *string `json:"private_connection_service_id,omitempty"` +} + +type PrivateLinkConfigResponse struct { + ConnectionServiceName string `json:"connection_service_name"` + ConnectionServiceId string `json:"connection_service_id"` + WorkspaceUrl string `json:"workspace_url"` + AccountName string `json:"account_name"` + AccountUrl string `json:"account_url"` + VpceId string `json:"vpce_id"` + PlsId string `json:"pls_id"` + AwsAccountId string `json:"aws_account_id"` + ClusterIdentifier string `json:"cluster_identifier"` + SubResourceName string `json:"sub_resource_name"` + PrivateConnectionServiceId string `json:"private_connection_service_id,omitempty"` + +} + +func (plc *PrivateLinkConfig) Request() *privateLinkConfigRequest { + return &privateLinkConfigRequest{ + ConnectionServiceName: plc.connectionServiceName, + ConnectionServiceId: plc.connectionServiceId, + WorkspaceUrl: plc.workspaceUrl, + AccountName: plc.accountName, + AccountUrl: plc.accountUrl, + VpceId: plc.vpceId, + PlsId: plc.plsId, + AwsAccountId: plc.awsAccountId, + ClusterIdentifier: plc.clusterIdentifier, + SubResourceName: plc.subResourceName, + PrivateConnectionServiceId: plc.privateConnectionServiceId, + } +} + +func (plc *PrivateLinkConfig) ConnectionServiceName(value string) *PrivateLinkConfig { + plc.connectionServiceName = &value + return plc +} + +func (plc *PrivateLinkConfig) ConnectionServiceId(value string) *PrivateLinkConfig { + plc.connectionServiceId = &value + return plc +} + +func (plc *PrivateLinkConfig) WorkspaceUrl(value string) *PrivateLinkConfig { + plc.workspaceUrl = &value + return plc +} + +func (plc *PrivateLinkConfig) AccountName(value string) *PrivateLinkConfig { + plc.accountName = &value + return plc +} + +func (plc *PrivateLinkConfig) AccountUrl(value string) *PrivateLinkConfig { + plc.accountUrl = &value + return plc +} + +func (plc *PrivateLinkConfig) VpceId(value string) *PrivateLinkConfig { + plc.vpceId = &value + return plc +} + +func (plc *PrivateLinkConfig) PlsId(value string) *PrivateLinkConfig { + plc.plsId = &value + return plc +} + +func (plc *PrivateLinkConfig) AwsAccountId(value string) *PrivateLinkConfig { + plc.awsAccountId = &value + return plc +} + +func (plc *PrivateLinkConfig) ClusterIdentifier(value string) *PrivateLinkConfig { + plc.clusterIdentifier = &value + return plc +} + +func (plc *PrivateLinkConfig) SubResourceName(value string) *PrivateLinkConfig { + plc.subResourceName = &value + return plc +} + +func (plc *PrivateLinkConfig) PrivateConnectionServiceId(value string) *PrivateLinkConfig { + plc.privateConnectionServiceId = &value + return plc +} + diff --git a/private_link/private_link_create.go b/private_link/private_link_create.go new file mode 100644 index 00000000..ab6cb273 --- /dev/null +++ b/private_link/private_link_create.go @@ -0,0 +1,58 @@ +package privatelink + +import ( + "context" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// PrivateLinkCreateService implements the Log Management, Create a Log Service API. +// Ref. https://fivetran.com/docs/rest-api/log-service-management#createalogservice +type PrivateLinkCreateService struct { + httputils.HttpService + name *string + region *string + service *string + config *PrivateLinkConfig +} + + +func (s *PrivateLinkCreateService) request() privateLinkCreateRequest { + var config interface{} + if s.config != nil { + config = s.config.Request() + } + + return privateLinkCreateRequest{ + Name: s.name, + Region: s.region, + Service: s.service, + Config: config, + } +} + +func (s *PrivateLinkCreateService) Region(value string) *PrivateLinkCreateService { + s.region = &value + return s +} + +func (s *PrivateLinkCreateService) Service(value string) *PrivateLinkCreateService { + s.service = &value + return s +} + +func (s *PrivateLinkCreateService) Name(value string) *PrivateLinkCreateService { + s.name = &value + return s +} + +func (s *PrivateLinkCreateService) Config(value *PrivateLinkConfig) *PrivateLinkCreateService { + s.config = value + return s +} + +func (s *PrivateLinkCreateService) Do(ctx context.Context) (PrivateLinkResponse, error) { + var response PrivateLinkResponse + err := s.HttpService.Do(ctx, "POST", "/private-links", s.request(), nil, 201, &response) + return response, err +} \ No newline at end of file diff --git a/private_link/private_link_create_test.go b/private_link/private_link_create_test.go new file mode 100644 index 00000000..eed14b5c --- /dev/null +++ b/private_link/private_link_create_test.go @@ -0,0 +1,84 @@ +package privatelink_test + +import ( + "context" + "net/http" + "testing" + + "github.com/fivetran/go-fivetran" + "github.com/fivetran/go-fivetran/private_link" + "github.com/fivetran/go-fivetran/tests/mock" + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestPrivateLinkCreateServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/private-links"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusCreated, preparePrivateLinkCreateResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewPrivateLinkCreate(). + Name("name"). + Region("region"). + Service("service"). + Config(preparePrivateLinkConfig()). + Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertPrivateLinkCreateResponse(t, response) +} + +func preparePrivateLinkConfig() *privatelink.PrivateLinkConfig { + config := fivetran.NewPrivateLinkConfig() + config.ConnectionServiceName("connection_service_name") + + return config +} + +func preparePrivateLinkCreateResponse() string { + return `{ + "code": "Success", + "data": { + "id": "id", + "name": "name", + "region": "region", + "service": "service", + "account_id": "account_id", + "cloud_provider": "cloud_provider", + "state": "state", + "state_summary": "state_summary", + "created_at": "2022-04-29T09:41:08.583Z", + "created_by": "created_by", + "config": { + "connection_service_name": "connection_service_name" + } + } +}` +} + +func assertPrivateLinkCreateResponse(t *testing.T, response privatelink.PrivateLinkResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Id, "id") + testutils.AssertEqual(t, response.Data.Name, "name") + testutils.AssertEqual(t, response.Data.Region, "region") + testutils.AssertEqual(t, response.Data.Service, "service") + testutils.AssertEqual(t, response.Data.CloudProvider, "cloud_provider") + testutils.AssertEqual(t, response.Data.State, "state") + testutils.AssertEqual(t, response.Data.StateSummary, "state_summary") + testutils.AssertEqual(t, response.Data.CreatedAt, "2022-04-29T09:41:08.583Z") + testutils.AssertEqual(t, response.Data.CreatedBy, "created_by") + testutils.AssertEqual(t, response.Data.Config.ConnectionServiceName, "connection_service_name") +} diff --git a/private_links/private_links_delete.go b/private_link/private_link_delete.go similarity index 54% rename from private_links/private_links_delete.go rename to private_link/private_link_delete.go index 2d1fe2eb..32f2c943 100644 --- a/private_links/private_links_delete.go +++ b/private_link/private_link_delete.go @@ -1,4 +1,4 @@ -package privatelinks +package privatelink import ( "context" @@ -8,19 +8,19 @@ import ( httputils "github.com/fivetran/go-fivetran/http_utils" ) -// PrivateLinksDeleteService implements the Private Links Management, Delete a Private Link -// Ref. https://fivetran.com/docs/rest-api/private-links-management#deleteaprivatelink -type PrivateLinksDeleteService struct { +// PrivateLinkDeleteService implements the Private Link Management, Delete a Private Link +// Ref. https://fivetran.com/docs/rest-api/private-link-management#deleteaprivatelink +type PrivateLinkDeleteService struct { httputils.HttpService privateLinkId *string } -func (s *PrivateLinksDeleteService) PrivateLinkId(value string) *PrivateLinksDeleteService { +func (s *PrivateLinkDeleteService) PrivateLinkId(value string) *PrivateLinkDeleteService { s.privateLinkId = &value return s } -func (s *PrivateLinksDeleteService) Do(ctx context.Context) (common.CommonResponse, error) { +func (s *PrivateLinkDeleteService) Do(ctx context.Context) (common.CommonResponse, error) { var response common.CommonResponse if s.privateLinkId == nil { return response, fmt.Errorf("missing required privateLinkId") diff --git a/private_links/private_links_delete_test.go b/private_link/private_link_delete_test.go similarity index 66% rename from private_links/private_links_delete_test.go rename to private_link/private_link_delete_test.go index 57a93f16..5a52dd81 100644 --- a/private_links/private_links_delete_test.go +++ b/private_link/private_link_delete_test.go @@ -1,4 +1,4 @@ -package privatelinks_test +package privatelink_test import ( "context" @@ -10,17 +10,17 @@ import ( testutils "github.com/fivetran/go-fivetran/test_utils" ) -func TestPrivateLinksDeleteServiceDo(t *testing.T) { +func TestPrivateLinkDeleteServiceDo(t *testing.T) { // arrange ftClient, mockClient := testutils.CreateTestClient() handler := mockClient.When(http.MethodDelete, "/v1/private-links/123456"). ThenCall(func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, preparePrivateLinksDeleteResponse()) + response := mock.NewResponse(req, http.StatusOK, preparePrivateLinkDeleteResponse()) return response, nil }) // act - response, err := ftClient.NewPrivateLinksDelete(). + response, err := ftClient.NewPrivateLinkDelete(). PrivateLinkId("123456"). Do(context.Background()) @@ -33,17 +33,17 @@ func TestPrivateLinksDeleteServiceDo(t *testing.T) { testutils.AssertEqual(t, len(interactions), 1) testutils.AssertEqual(t, interactions[0].Handler, handler) testutils.AssertEqual(t, handler.Interactions, 1) - assertPrivateLinksDeleteResponse(t, response) + assertPrivateLinkDeleteResponse(t, response) } -func preparePrivateLinksDeleteResponse() string { +func preparePrivateLinkDeleteResponse() string { return `{ "code": "Success", - "message": "Group has been deleted" + "message": "Private Link has been deleted" }` } -func assertPrivateLinksDeleteResponse(t *testing.T, response common.CommonResponse) { +func assertPrivateLinkDeleteResponse(t *testing.T, response common.CommonResponse) { testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, response.Message, "Group has been deleted") + testutils.AssertEqual(t, response.Message, "Private Link has been deleted") } diff --git a/private_link/private_link_details.go b/private_link/private_link_details.go new file mode 100644 index 00000000..b160f890 --- /dev/null +++ b/private_link/private_link_details.go @@ -0,0 +1,31 @@ +package privatelink + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// PrivateLinkDetailsService implements the Private Link Management, Retrieve Private Link details API. +// Ref. https://fivetran.com/docs/rest-api/private-link-management#retrieveprivatelinkdetails +type PrivateLinkDetailsService struct { + httputils.HttpService + privateLinkId *string +} + +func (s *PrivateLinkDetailsService) PrivateLinkId(value string) *PrivateLinkDetailsService { + s.privateLinkId = &value + return s +} + +func (s *PrivateLinkDetailsService) Do(ctx context.Context) (PrivateLinkResponse, error) { + var response PrivateLinkResponse + if s.privateLinkId == nil { + return response, fmt.Errorf("missing required privateLinkId") + } + + url := fmt.Sprintf("/private-links/%v", *s.privateLinkId) + err := s.HttpService.Do(ctx, "GET", url, nil, nil, 200, &response) + return response, err +} \ No newline at end of file diff --git a/private_link/private_link_details_test.go b/private_link/private_link_details_test.go new file mode 100644 index 00000000..b4b69f70 --- /dev/null +++ b/private_link/private_link_details_test.go @@ -0,0 +1,72 @@ +package privatelink_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran/private_link" + "github.com/fivetran/go-fivetran/tests/mock" + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestPrivateLinkDetailsServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/private-links/123456"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, preparePrivateLinkDetailsResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewPrivateLinkDetails(). + PrivateLinkId("123456"). + Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertPrivateLinkDetailsResponse(t, response) +} + +func preparePrivateLinkDetailsResponse() string { + return `{ + "code": "Success", + "data": { + "id": "123456", + "name": "name", + "region": "region", + "service": "service", + "account_id": "account_id", + "cloud_provider": "cloud_provider", + "state": "state", + "state_summary": "state_summary", + "created_at": "2022-04-29T09:41:08.583Z", + "created_by": "created_by", + "config": { + "connection_service_name": "connection_service_name" + } + } +}` +} + +func assertPrivateLinkDetailsResponse(t *testing.T, response privatelink.PrivateLinkResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Id, "123456") + testutils.AssertEqual(t, response.Data.Name, "name") + testutils.AssertEqual(t, response.Data.Region, "region") + testutils.AssertEqual(t, response.Data.Service, "service") + testutils.AssertEqual(t, response.Data.CloudProvider, "cloud_provider") + testutils.AssertEqual(t, response.Data.State, "state") + testutils.AssertEqual(t, response.Data.StateSummary, "state_summary") + testutils.AssertEqual(t, response.Data.CreatedAt, "2022-04-29T09:41:08.583Z") + testutils.AssertEqual(t, response.Data.CreatedBy, "created_by") + testutils.AssertEqual(t, response.Data.Config.ConnectionServiceName, "connection_service_name") +} diff --git a/private_link/private_link_list.go b/private_link/private_link_list.go new file mode 100644 index 00000000..57170370 --- /dev/null +++ b/private_link/private_link_list.go @@ -0,0 +1,43 @@ +package privatelink + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// PrivateLinkListService Returns a list of all private links within your Fivetran account. +// Ref. https://fivetran.com/docs/rest-api/private-links-management#listallprivatelinkswithinaccount +type PrivateLinkListService struct { + httputils.HttpService + limit *int + cursor *string +} + +func (s *PrivateLinkListService) Limit(value int) *PrivateLinkListService { + s.limit = &value + return s +} + +func (s *PrivateLinkListService) Cursor(value string) *PrivateLinkListService { + s.cursor = &value + return s +} + +func (s *PrivateLinkListService) Do(ctx context.Context) (PrivateLinkListResponse, error) { + var response PrivateLinkListResponse + + var queries map[string]string = nil + if s.cursor != nil || s.limit != nil { + queries = make(map[string]string) + if s.cursor != nil { + queries["cursor"] = *s.cursor + } + if s.limit != nil { + queries["limit"] = fmt.Sprintf("%v", *s.limit) + } + } + err := s.HttpService.Do(ctx, "GET", "/private-links", nil, queries, 200, &response) + return response, err +} \ No newline at end of file diff --git a/private_link/private_link_list_test.go b/private_link/private_link_list_test.go new file mode 100644 index 00000000..b9104b21 --- /dev/null +++ b/private_link/private_link_list_test.go @@ -0,0 +1,73 @@ +package privatelink_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran/private_link" + "github.com/fivetran/go-fivetran/tests/mock" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestPrivateLinkListServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodGet, "/v1/private-links"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, preparePrivateLinkListResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewPrivateLinkList(). + Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertPrivateLinkListResponse(t, response) +} + +func preparePrivateLinkListResponse() string { + return `{ + "code": "Success", + "data": { + "items": [ + { + "id": "123456", + "name": "name", + "region": "region", + "service": "service", + "account_id": "account_id", + "cloud_provider": "cloud_provider", + "state": "state", + "state_summary": "state_summary", + "created_at": "2022-04-29T09:41:08.583Z", + "created_by": "created_by" + } + ], + "next_cursor": null + } + }` +} + +func assertPrivateLinkListResponse(t *testing.T, response privatelink.PrivateLinkListResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Items[0].Id, "123456") + testutils.AssertEqual(t, response.Data.Items[0].Name, "name") + testutils.AssertEqual(t, response.Data.Items[0].Region, "region") + testutils.AssertEqual(t, response.Data.Items[0].Service, "service") + testutils.AssertEqual(t, response.Data.Items[0].CloudProvider, "cloud_provider") + testutils.AssertEqual(t, response.Data.Items[0].State, "state") + testutils.AssertEqual(t, response.Data.Items[0].StateSummary, "state_summary") + testutils.AssertEqual(t, response.Data.Items[0].CreatedAt, "2022-04-29T09:41:08.583Z") + testutils.AssertEqual(t, response.Data.Items[0].CreatedBy, "created_by") +} \ No newline at end of file diff --git a/private_link/private_link_modify.go b/private_link/private_link_modify.go new file mode 100644 index 00000000..f6592ea6 --- /dev/null +++ b/private_link/private_link_modify.go @@ -0,0 +1,49 @@ +package privatelink + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" +) + +// PrivateLinkModifyService implements the Private Link Management, Modify a Private Link Service API. +// Ref. https://fivetran.com/docs/rest-api/private-link-management#updateaprivatelink +type PrivateLinkModifyService struct { + httputils.HttpService + privateLinkId *string + config *PrivateLinkConfig +} + +func (s *PrivateLinkModifyService) request() *privateLinkModifyRequest { + var config interface{} + + if s.config != nil { + config = s.config.Request() + } + + return &privateLinkModifyRequest{ + Config: config, + } +} + +func (s *PrivateLinkModifyService) PrivateLinkId(value string) *PrivateLinkModifyService { + s.privateLinkId = &value + return s +} + +func (s *PrivateLinkModifyService) Config(value *PrivateLinkConfig) *PrivateLinkModifyService { + s.config = value + return s +} + +func (s *PrivateLinkModifyService) Do(ctx context.Context) (PrivateLinkResponse, error) { + var response PrivateLinkResponse + if s.privateLinkId == nil { + return response, fmt.Errorf("missing required privateLinkId") + } + + url := fmt.Sprintf("/private-links/%v", *s.privateLinkId) + err := s.HttpService.Do(ctx, "PATCH", url, s.request(), nil, 200, &response) + return response, err +} \ No newline at end of file diff --git a/private_link/private_link_modify_test.go b/private_link/private_link_modify_test.go new file mode 100644 index 00000000..f5c8bd4a --- /dev/null +++ b/private_link/private_link_modify_test.go @@ -0,0 +1,81 @@ +package privatelink_test + +import ( + "context" + "net/http" + "testing" + "github.com/fivetran/go-fivetran" + "github.com/fivetran/go-fivetran/private_link" + "github.com/fivetran/go-fivetran/tests/mock" + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestPrivateLinkModifyServiceDo(t *testing.T) { + // arrange + + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPatch, "/v1/private-links/123456"). + ThenCall(func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, preparePrivateLinkModifyResponse()) + return response, nil + }) + + // act + response, err := ftClient.NewPrivateLinkModify(). + PrivateLinkId("123456"). + Config(preparePrivateLinkModifyConfig()). + Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) + assertPrivateLinkModifyResponse(t, response) +} + +func preparePrivateLinkModifyResponse() string { + return `{ + "code": "Success", + "data": { + "id": "123456", + "name": "name", + "region": "region", + "service": "service", + "account_id": "account_id", + "cloud_provider": "cloud_provider", + "state": "state", + "state_summary": "state_summary", + "created_at": "2022-04-29T09:41:08.583Z", + "created_by": "created_by", + "config": { + "connection_service_name": "connection_service_name" + } + } +}` +} + +func preparePrivateLinkModifyConfig() *privatelink.PrivateLinkConfig { + config := fivetran.NewPrivateLinkConfig() + config.ConnectionServiceName("connection_service_name") + + return config +} + +func assertPrivateLinkModifyResponse(t *testing.T, response privatelink.PrivateLinkResponse) { + testutils.AssertEqual(t, response.Code, "Success") + testutils.AssertEqual(t, response.Data.Id, "123456") + testutils.AssertEqual(t, response.Data.Name, "name") + testutils.AssertEqual(t, response.Data.Region, "region") + testutils.AssertEqual(t, response.Data.Service, "service") + testutils.AssertEqual(t, response.Data.CloudProvider, "cloud_provider") + testutils.AssertEqual(t, response.Data.State, "state") + testutils.AssertEqual(t, response.Data.StateSummary, "state_summary") + testutils.AssertEqual(t, response.Data.CreatedAt, "2022-04-29T09:41:08.583Z") + testutils.AssertEqual(t, response.Data.CreatedBy, "created_by") + testutils.AssertEqual(t, response.Data.Config.ConnectionServiceName, "connection_service_name") +} \ No newline at end of file diff --git a/private_links/common_types.go b/private_links/common_types.go deleted file mode 100644 index 55dee4af..00000000 --- a/private_links/common_types.go +++ /dev/null @@ -1,32 +0,0 @@ -package privatelinks - -type PrivateLinksResponseBase struct { - Id string `json:"id"` - Name string `json:"name"` - GroupId string `json:"group_id"` - CloudProvider string `json:"cloud_provider"` - Region string `json:"region"` - State string `json:"state"` - StateSummary string `json:"state_summary"` - CreatedAt string `json:"created_at"` - CreatedBy string `json:"created_by"` -} - -type PrivateLinksResponse struct { - Code string `json:"code"` - Message string `json:"message"` - Data struct { - PrivateLinksResponseBase - Config PrivateLinksConfigResponse `json:"config"` - } `json:"data"` -} - -type privateLinksCreateRequest struct { - Name *string `json:"name,omitempty"` - GroupId *string `json:"group_id,omitempty"` - Config any `json:"config,omitempty"` -} - -type privateLinksModifyRequest struct { - Config any `json:"config,omitempty"` -} \ No newline at end of file diff --git a/private_links/private_links_config.go b/private_links/private_links_config.go deleted file mode 100644 index ea81b030..00000000 --- a/private_links/private_links_config.go +++ /dev/null @@ -1,107 +0,0 @@ -package privatelinks - -// PrivateLinksConfig builds Private Links Management, Private Link Config. -// Ref. https://fivetran.com/docs/rest-api/private-links-management#privatelinksetupconfigurations -type PrivateLinksConfig struct { - connectionServiceName *string - connectionServiceId *string - workspaceUrl *string - accountName *string - accountUrl *string - vpceId *string - plsId *string - awsAccountId *string - clusterIdentifier *string - subResourceName *string -} - -type privateLinksConfigRequest struct { - ConnectionServiceName *string `json:"connection_service_name,omitempty"` - ConnectionServiceId *string `json:"connection_service_id,omitempty"` - WorkspaceUrl *string `json:"workspace_url,omitempty"` - AccountName *string `json:"account_name,omitempty"` - AccountUrl *string `json:"account_url,omitempty"` - VpceId *string `json:"vpce_id,omitempty"` - PlsId *string `json:"pls_id,omitempty"` - AwsAccountId *string `json:"aws_account_id,omitempty"` - ClusterIdentifier *string `json:"cluster_identifier,omitempty"` - SubResourceName *string `json:"sub_resource_name,omitempty"` -} - -type PrivateLinksConfigResponse struct { - ConnectionServiceName string `json:"connection_service_name"` - ConnectionServiceId string `json:"connection_service_id"` - WorkspaceUrl string `json:"workspace_url"` - AccountName string `json:"account_name"` - AccountUrl string `json:"account_url"` - VpceId string `json:"vpce_id"` - PlsId string `json:"pls_id"` - AwsAccountId string `json:"aws_account_id"` - ClusterIdentifier string `json:"cluster_identifier"` - SubResourceName string `json:"sub_resource_name"` -} - -func (plc *PrivateLinksConfig) Request() *privateLinksConfigRequest { - return &privateLinksConfigRequest{ - ConnectionServiceName: plc.connectionServiceName, - ConnectionServiceId: plc.connectionServiceId, - WorkspaceUrl: plc.workspaceUrl, - AccountName: plc.accountName, - AccountUrl: plc.accountUrl, - VpceId: plc.vpceId, - PlsId: plc.plsId, - AwsAccountId: plc.awsAccountId, - ClusterIdentifier: plc.clusterIdentifier, - SubResourceName: plc.subResourceName, - } -} - -func (plc *PrivateLinksConfig) ConnectionServiceName(value string) *PrivateLinksConfig { - plc.connectionServiceName = &value - return plc -} - -func (plc *PrivateLinksConfig) ConnectionServiceId(value string) *PrivateLinksConfig { - plc.connectionServiceId = &value - return plc -} - -func (plc *PrivateLinksConfig) WorkspaceUrl(value string) *PrivateLinksConfig { - plc.workspaceUrl = &value - return plc -} - -func (plc *PrivateLinksConfig) AccountName(value string) *PrivateLinksConfig { - plc.accountName = &value - return plc -} - -func (plc *PrivateLinksConfig) AccountUrl(value string) *PrivateLinksConfig { - plc.accountUrl = &value - return plc -} - -func (plc *PrivateLinksConfig) VpceId(value string) *PrivateLinksConfig { - plc.vpceId = &value - return plc -} - -func (plc *PrivateLinksConfig) PlsId(value string) *PrivateLinksConfig { - plc.plsId = &value - return plc -} - -func (plc *PrivateLinksConfig) AwsAccountId(value string) *PrivateLinksConfig { - plc.awsAccountId = &value - return plc -} - -func (plc *PrivateLinksConfig) ClusterIdentifier(value string) *PrivateLinksConfig { - plc.clusterIdentifier = &value - return plc -} - -func (plc *PrivateLinksConfig) SubResourceName(value string) *PrivateLinksConfig { - plc.subResourceName = &value - return plc -} diff --git a/private_links/private_links_create.go b/private_links/private_links_create.go deleted file mode 100644 index 96206b77..00000000 --- a/private_links/private_links_create.go +++ /dev/null @@ -1,51 +0,0 @@ -package privatelinks - -import ( - "context" - - httputils "github.com/fivetran/go-fivetran/http_utils" -) - -// PrivateLinksCreateService implements the Log Management, Create a Log Service API. -// Ref. https://fivetran.com/docs/rest-api/log-service-management#createalogservice -type PrivateLinksCreateService struct { - httputils.HttpService - name *string - groupId *string - config *PrivateLinksConfig -} - - -func (s *PrivateLinksCreateService) request() privateLinksCreateRequest { - var config interface{} - if s.config != nil { - config = s.config.Request() - } - - return privateLinksCreateRequest{ - Name: s.name, - GroupId: s.groupId, - Config: config, - } -} - -func (s *PrivateLinksCreateService) GroupId(value string) *PrivateLinksCreateService { - s.groupId = &value - return s -} - -func (s *PrivateLinksCreateService) Name(value string) *PrivateLinksCreateService { - s.name = &value - return s -} - -func (s *PrivateLinksCreateService) Config(value *PrivateLinksConfig) *PrivateLinksCreateService { - s.config = value - return s -} - -func (s *PrivateLinksCreateService) Do(ctx context.Context) (PrivateLinksResponse, error) { - var response PrivateLinksResponse - err := s.HttpService.Do(ctx, "POST", "/private-links", s.request(), nil, 201, &response) - return response, err -} \ No newline at end of file diff --git a/private_links/private_links_create_test.go b/private_links/private_links_create_test.go deleted file mode 100644 index 06c458df..00000000 --- a/private_links/private_links_create_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package privatelinks_test - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/fivetran/go-fivetran/private_links" - "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestPrivateLinksCreateServiceDo(t *testing.T) { - // arrange - - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/private-links"). - ThenCall(func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusCreated, preparePrivateLinksCreateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewPrivateLinksCreate(). - Name(GROUP_LIST_PRIVATE_LINK_NAME). - Do(context.Background()) - - // assert - if err != nil { - t.Error(err) - } - - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - assertPrivateLinksCreateResponse(t, response) -} - -func preparePrivateLinksCreateResponse() string { - return fmt.Sprintf(`{ - "code": "Success", - "data": { - "id": "%v", - "name": "%v", - "group_id": "%v", - "cloud_provider": "%v", - "region": "%v", - "state": "%v", - "state_summary": "%v", - "created_at": "%v", - "created_by": "%v", - "config" : { - "workspace_url": "%v" - } - } - }`, - GROUP_LIST_PRIVATE_LINK_ID, - GROUP_LIST_PRIVATE_LINK_NAME, - GROUP_LIST_PRIVATE_LINK_GROUP_ID, - GROUP_LIST_PRIVATE_LINK_CLOUD, - GROUP_LIST_PRIVATE_LINK_REGION, - GROUP_LIST_PRIVATE_LINK_STATE, - GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY, - GROUP_LIST_PRIVATE_LINK_CREATED_AT, - GROUP_LIST_PRIVATE_LINK_CREATED_BY, - GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID) -} - -func assertPrivateLinksCreateResponse(t *testing.T, response privatelinks.PrivateLinksResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, response.Data.Id, GROUP_LIST_PRIVATE_LINK_ID) - testutils.AssertEqual(t, response.Data.Name, GROUP_LIST_PRIVATE_LINK_NAME) - testutils.AssertEqual(t, response.Data.GroupId, GROUP_LIST_PRIVATE_LINK_GROUP_ID) - testutils.AssertEqual(t, response.Data.CloudProvider, GROUP_LIST_PRIVATE_LINK_CLOUD) - testutils.AssertEqual(t, response.Data.Region, GROUP_LIST_PRIVATE_LINK_REGION) - testutils.AssertEqual(t, response.Data.State, GROUP_LIST_PRIVATE_LINK_STATE) - testutils.AssertEqual(t, response.Data.StateSummary, GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY) - testutils.AssertEqual(t, response.Data.CreatedAt, GROUP_LIST_PRIVATE_LINK_CREATED_AT) - testutils.AssertEqual(t, response.Data.CreatedBy, GROUP_LIST_PRIVATE_LINK_CREATED_BY) - testutils.AssertEqual(t, response.Data.Config.WorkspaceUrl, GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID) -} diff --git a/private_links/private_links_details.go b/private_links/private_links_details.go deleted file mode 100644 index 401116f2..00000000 --- a/private_links/private_links_details.go +++ /dev/null @@ -1,31 +0,0 @@ -package privatelinks - -import ( - "context" - "fmt" - - httputils "github.com/fivetran/go-fivetran/http_utils" -) - -// PrivateLinksDetailsService implements the Private Links Management, Retrieve Private Link details API. -// Ref. https://fivetran.com/docs/rest-api/private-links-management#retrieveprivatelinkdetails -type PrivateLinksDetailsService struct { - httputils.HttpService - privateLinkId *string -} - -func (s *PrivateLinksDetailsService) PrivateLinkId(value string) *PrivateLinksDetailsService { - s.privateLinkId = &value - return s -} - -func (s *PrivateLinksDetailsService) Do(ctx context.Context) (PrivateLinksResponse, error) { - var response PrivateLinksResponse - if s.privateLinkId == nil { - return response, fmt.Errorf("missing required privateLinkId") - } - - url := fmt.Sprintf("/private-links/%v", *s.privateLinkId) - err := s.HttpService.Do(ctx, "GET", url, nil, nil, 200, &response) - return response, err -} \ No newline at end of file diff --git a/private_links/private_links_details_test.go b/private_links/private_links_details_test.go deleted file mode 100644 index 38d12304..00000000 --- a/private_links/private_links_details_test.go +++ /dev/null @@ -1,96 +0,0 @@ -package privatelinks_test - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/fivetran/go-fivetran/private_links" - "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -const ( - GROUP_LIST_PRIVATE_LINK_ID = "123456" - GROUP_LIST_PRIVATE_LINK_NAME = "name" - GROUP_LIST_PRIVATE_LINK_GROUP_ID = "group" - GROUP_LIST_PRIVATE_LINK_CLOUD = "cloud" - GROUP_LIST_PRIVATE_LINK_REGION = "region" - GROUP_LIST_PRIVATE_LINK_STATE = "state" - GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY = "state_summary" - GROUP_LIST_PRIVATE_LINK_CREATED_AT = "2018-01-15T11:00:27.329220Z" - GROUP_LIST_PRIVATE_LINK_CREATED_BY = "created_by" - GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID = "workspaceUrl" -) - -func TestPrivateLinksDetailsServiceDo(t *testing.T) { - // arrange - - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodGet, "/v1/private-links/" + GROUP_LIST_PRIVATE_LINK_ID). - ThenCall(func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, preparePrivateLinksDetailsResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewPrivateLinksDetails(). - PrivateLinkId(GROUP_LIST_PRIVATE_LINK_ID). - Do(context.Background()) - - // assert - if err != nil { - t.Error(err) - } - - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - assertPrivateLinksDetailsResponse(t, response) -} - -func preparePrivateLinksDetailsResponse() string { - return fmt.Sprintf(`{ - "code": "Success", - "data": { - "id": "%v", - "name": "%v", - "group_id": "%v", - "cloud_provider": "%v", - "region": "%v", - "state": "%v", - "state_summary": "%v", - "created_at": "%v", - "created_by": "%v", - "config" : { - "workspace_url": "%v" - } - } - }`, - GROUP_LIST_PRIVATE_LINK_ID, - GROUP_LIST_PRIVATE_LINK_NAME, - GROUP_LIST_PRIVATE_LINK_GROUP_ID, - GROUP_LIST_PRIVATE_LINK_CLOUD, - GROUP_LIST_PRIVATE_LINK_REGION, - GROUP_LIST_PRIVATE_LINK_STATE, - GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY, - GROUP_LIST_PRIVATE_LINK_CREATED_AT, - GROUP_LIST_PRIVATE_LINK_CREATED_BY, - GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID) -} - -func assertPrivateLinksDetailsResponse(t *testing.T, response privatelinks.PrivateLinksResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, response.Data.Id, GROUP_LIST_PRIVATE_LINK_ID) - testutils.AssertEqual(t, response.Data.Name, GROUP_LIST_PRIVATE_LINK_NAME) - testutils.AssertEqual(t, response.Data.GroupId, GROUP_LIST_PRIVATE_LINK_GROUP_ID) - testutils.AssertEqual(t, response.Data.CloudProvider, GROUP_LIST_PRIVATE_LINK_CLOUD) - testutils.AssertEqual(t, response.Data.Region, GROUP_LIST_PRIVATE_LINK_REGION) - testutils.AssertEqual(t, response.Data.State, GROUP_LIST_PRIVATE_LINK_STATE) - testutils.AssertEqual(t, response.Data.StateSummary, GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY) - testutils.AssertEqual(t, response.Data.CreatedAt, GROUP_LIST_PRIVATE_LINK_CREATED_AT) - testutils.AssertEqual(t, response.Data.CreatedBy, GROUP_LIST_PRIVATE_LINK_CREATED_BY) - testutils.AssertEqual(t, response.Data.Config.WorkspaceUrl, GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID) -} diff --git a/private_links/private_links_modify.go b/private_links/private_links_modify.go deleted file mode 100644 index e357acd4..00000000 --- a/private_links/private_links_modify.go +++ /dev/null @@ -1,49 +0,0 @@ -package privatelinks - -import ( - "context" - "fmt" - - httputils "github.com/fivetran/go-fivetran/http_utils" -) - -// PrivateLinksModifyService implements the Private Links Management, Modify a Private Link Service API. -// Ref. https://fivetran.com/docs/rest-api/private-links-management#updateaprivatelink -type PrivateLinksModifyService struct { - httputils.HttpService - privateLinkId *string - config *PrivateLinksConfig -} - -func (s *PrivateLinksModifyService) request() *privateLinksModifyRequest { - var config interface{} - - if s.config != nil { - config = s.config.Request() - } - - return &privateLinksModifyRequest{ - Config: config, - } -} - -func (s *PrivateLinksModifyService) PrivateLinkId(value string) *PrivateLinksModifyService { - s.privateLinkId = &value - return s -} - -func (s *PrivateLinksModifyService) Config(value *PrivateLinksConfig) *PrivateLinksModifyService { - s.config = value - return s -} - -func (s *PrivateLinksModifyService) Do(ctx context.Context) (PrivateLinksResponse, error) { - var response PrivateLinksResponse - if s.privateLinkId == nil { - return response, fmt.Errorf("missing required privateLinkId") - } - - url := fmt.Sprintf("/private-links/%v", *s.privateLinkId) - err := s.HttpService.Do(ctx, "PATCH", url, s.request(), nil, 200, &response) - return response, err -} \ No newline at end of file diff --git a/private_links/private_links_modify_test.go b/private_links/private_links_modify_test.go deleted file mode 100644 index 582b8850..00000000 --- a/private_links/private_links_modify_test.go +++ /dev/null @@ -1,84 +0,0 @@ -package privatelinks_test - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/fivetran/go-fivetran" - "github.com/fivetran/go-fivetran/private_links" - "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestPrivateLinksModifyServiceDo(t *testing.T) { - // arrange - - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPatch, "/v1/private-links/" + GROUP_LIST_PRIVATE_LINK_ID). - ThenCall(func(req *http.Request) (*http.Response, error) { - response := mock.NewResponse(req, http.StatusOK, fmt.Sprintf(`{ - "code": "Success", - "data": { - "id": "%v", - "name": "%v", - "group_id": "%v", - "cloud_provider": "%v", - "region": "%v", - "state": "%v", - "state_summary": "%v", - "created_at": "%v", - "created_by": "%v", - "config" : { - "workspace_url": "%v" - } - } - }`, - GROUP_LIST_PRIVATE_LINK_ID, - GROUP_LIST_PRIVATE_LINK_NAME, - GROUP_LIST_PRIVATE_LINK_GROUP_ID, - GROUP_LIST_PRIVATE_LINK_CLOUD, - GROUP_LIST_PRIVATE_LINK_REGION, - GROUP_LIST_PRIVATE_LINK_STATE, - GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY, - GROUP_LIST_PRIVATE_LINK_CREATED_AT, - GROUP_LIST_PRIVATE_LINK_CREATED_BY, - GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID)) - return response, nil - }) - - // act - response, err := ftClient.NewPrivateLinksModify(). - PrivateLinkId(GROUP_LIST_PRIVATE_LINK_ID). - Config(preparePrivateLinksModifyConfig()). - Do(context.Background()) - - // assert - if err != nil { - t.Error(err) - } - - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertEqual(t, response.Data.Id, GROUP_LIST_PRIVATE_LINK_ID) - testutils.AssertEqual(t, response.Data.Name, GROUP_LIST_PRIVATE_LINK_NAME) - testutils.AssertEqual(t, response.Data.GroupId, GROUP_LIST_PRIVATE_LINK_GROUP_ID) - testutils.AssertEqual(t, response.Data.CloudProvider, GROUP_LIST_PRIVATE_LINK_CLOUD) - testutils.AssertEqual(t, response.Data.Region, GROUP_LIST_PRIVATE_LINK_REGION) - testutils.AssertEqual(t, response.Data.State, GROUP_LIST_PRIVATE_LINK_STATE) - testutils.AssertEqual(t, response.Data.StateSummary, GROUP_LIST_PRIVATE_LINK_STATE_SUMMARY) - testutils.AssertEqual(t, response.Data.CreatedAt, GROUP_LIST_PRIVATE_LINK_CREATED_AT) - testutils.AssertEqual(t, response.Data.CreatedBy, GROUP_LIST_PRIVATE_LINK_CREATED_BY) - testutils.AssertEqual(t, response.Data.Config.WorkspaceUrl, GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID) -} - -func preparePrivateLinksModifyConfig() *privatelinks.PrivateLinksConfig { - config := fivetran.NewPrivateLinksConfig() - config.WorkspaceUrl(GROUP_LIST_PRIVATE_LINK_WORKSPACE_ID) - - return config -} \ No newline at end of file diff --git a/proxy/common_types.go b/proxy/common_types.go index a99e5ef4..9855d146 100644 --- a/proxy/common_types.go +++ b/proxy/common_types.go @@ -1,61 +1,61 @@ package proxy import ( - "github.com/fivetran/go-fivetran/common" + "github.com/fivetran/go-fivetran/common" ) type ProxyCreateData struct { - AgentId string `json:"agent_id"` - AuthToken string `json:"auth_token"` - ProxyServerUri string `json:"proxy_server_uri"` + AgentId string `json:"agent_id"` + AuthToken string `json:"auth_token"` + ProxyServerUri string `json:"proxy_server_uri"` } type ProxyData struct { - Id string `json:"id"` - AccountId string `json:"account_id"` - RegistredAt string `json:"registred_at"` - Region string `json:"region"` - Token string `json:"token"` - Salt string `json:"salt"` - CreatedBy string `json:"created_by"` - DisplayName string `json:"display_name"` + Id string `json:"id"` + AccountId string `json:"account_id"` + RegistredAt string `json:"registred_at"` + Region string `json:"region"` + Token string `json:"token"` + Salt string `json:"salt"` + CreatedBy string `json:"created_by"` + DisplayName string `json:"display_name"` } type proxyCreateRequest struct { - DisplayName *string `json:"display_name,omitempty"` - GroupId *string `json:"group_id,omitempty"` + DisplayName *string `json:"display_name,omitempty"` + GroupRegion *string `json:"group_region,omitempty"` } type ProxyCreateResponse struct { - common.CommonResponse - Data ProxyCreateData `json:"data"` + common.CommonResponse + Data ProxyCreateData `json:"data"` } type ProxyListResponse struct { - Code string `json:"code"` - Data struct { - Items []ProxyData `json:"items"` - NextCursor string `json:"next_cursor"` - } `json:"data"` + Code string `json:"code"` + Data struct { + Items []ProxyData `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` } type ProxyDetailsResponse struct { - Code string `json:"code"` - Data ProxyData `json:"data"` + Code string `json:"code"` + Data ProxyData `json:"data"` } type ProxyConnectionMembershipsListResponse struct { - Code string `json:"code"` - Data struct { - Items []ProxyConnectionMembership `json:"items"` - NextCursor string `json:"next_cursor"` - } `json:"data"` + Code string `json:"code"` + Data struct { + Items []ProxyConnectionMembership `json:"items"` + NextCursor string `json:"next_cursor"` + } `json:"data"` } type ProxyConnectionMembership struct { - ConnectionId string `json:"connection_id"` + ConnectionId string `json:"connection_id"` } type proxyConnectionMembershipCreateRequest struct { - ConnectionId *string `json:"connection_id,omitempty"` + ConnectionId *string `json:"connection_id,omitempty"` } \ No newline at end of file diff --git a/proxy/proxy_connection_membership_create.go b/proxy/proxy_connection_membership_create.go deleted file mode 100644 index c70744bb..00000000 --- a/proxy/proxy_connection_membership_create.go +++ /dev/null @@ -1,45 +0,0 @@ -package proxy - -import ( - "context" - "fmt" - "github.com/fivetran/go-fivetran/common" - httputils "github.com/fivetran/go-fivetran/http_utils" -) - -// ProxyConnectionMembershipCreateService implements the Proxy Agent Management, Attach connection to the proxy agent -// Ref. https://fivetran.com/docs/rest-api/proxy-management#attachconnectiontotheproxyagent -type ProxyConnectionMembershipCreateService struct { - httputils.HttpService - proxyId *string - connectionId *string -} - -func (s *ProxyConnectionMembershipCreateService) request() *proxyConnectionMembershipCreateRequest { - return &proxyConnectionMembershipCreateRequest{ - ConnectionId: s.connectionId, - } -} - -func (s *ProxyConnectionMembershipCreateService) ProxyId(value string) *ProxyConnectionMembershipCreateService { - s.proxyId = &value - return s -} - -func (s *ProxyConnectionMembershipCreateService) ConnectionId(value string) *ProxyConnectionMembershipCreateService { - s.connectionId = &value - return s -} - -func (s *ProxyConnectionMembershipCreateService) Do(ctx context.Context) (common.CommonResponse, error) { - var response common.CommonResponse - if s.proxyId == nil { - return response, fmt.Errorf("missing required proxyId") - } - if s.connectionId == nil { - return response, fmt.Errorf("missing required connectionId") - } - url := fmt.Sprintf("/proxy/%v/connections", *s.proxyId) - err := s.HttpService.Do(ctx, "POST", url, s.request(), nil, 200, &response) - return response, err -} diff --git a/proxy/proxy_connection_membership_create_test.go b/proxy/proxy_connection_membership_create_test.go deleted file mode 100644 index 302e101e..00000000 --- a/proxy/proxy_connection_membership_create_test.go +++ /dev/null @@ -1,61 +0,0 @@ -package proxy_test - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/fivetran/go-fivetran/common" - "github.com/fivetran/go-fivetran/tests/mock" - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestNewProxyConnectionCreate(t *testing.T) { - // arrange - ftClient, mockClient := testutils.CreateTestClient() - handler := mockClient.When(http.MethodPost, "/v1/proxy/proxy_id/connections").ThenCall( - - func(req *http.Request) (*http.Response, error) { - body := testutils.RequestBodyToJson(t, req) - assertProxyConnectionCreateRequest(t, body) - response := mock.NewResponse(req, http.StatusOK, prepareProxyConnectionCreateResponse()) - return response, nil - }) - - // act - response, err := ftClient.NewProxyConnectionMembershipCreate(). - ProxyId("proxy_id"). - ConnectionId("connection_id"). - Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", response) - t.Error(err) - } - - // assert - interactions := mockClient.Interactions() - testutils.AssertEqual(t, len(interactions), 1) - testutils.AssertEqual(t, interactions[0].Handler, handler) - testutils.AssertEqual(t, handler.Interactions, 1) - - assertProxyConnectionCreateResponse(t, response) -} - -func prepareProxyConnectionCreateResponse() string { - return fmt.Sprintf( - `{ - "code": "Success", - "message": "string" - }`) -} - -func assertProxyConnectionCreateRequest(t *testing.T, request map[string]interface{}) { - testutils.AssertKey(t, "connection_id", request, "connection_id") -} - -func assertProxyConnectionCreateResponse(t *testing.T, response common.CommonResponse) { - testutils.AssertEqual(t, response.Code, "Success") - testutils.AssertNotEmpty(t, response.Message) -} diff --git a/proxy/proxy_connection_membership_delete.go b/proxy/proxy_connection_membership_delete.go deleted file mode 100644 index 6f3b9544..00000000 --- a/proxy/proxy_connection_membership_delete.go +++ /dev/null @@ -1,43 +0,0 @@ -package proxy - -import ( - "context" - "fmt" - - "github.com/fivetran/go-fivetran/common" - httputils "github.com/fivetran/go-fivetran/http_utils" -) - -// ProxyConnectionMembershipDeleteService implements the Proxy Agent Management, Detach connection from the proxy agent -// Ref. https://fivetran.com/docs/rest-api/proxy-management#detachconnectionfromtheproxyagent -type ProxyConnectionMembershipDeleteService struct { - httputils.HttpService - proxyId *string - connectionId *string -} - -func (s *ProxyConnectionMembershipDeleteService) ProxyId(value string) *ProxyConnectionMembershipDeleteService { - s.proxyId = &value - return s -} - -func (s *ProxyConnectionMembershipDeleteService) ConnectionId(value string) *ProxyConnectionMembershipDeleteService { - s.connectionId = &value - return s -} - -func (s *ProxyConnectionMembershipDeleteService) Do(ctx context.Context) (common.CommonResponse, error) { - var response common.CommonResponse - - if s.proxyId == nil { - return response, fmt.Errorf("missing required proxyId") - } - - if s.connectionId == nil { - return response, fmt.Errorf("missing required connectionId") - } - - url := fmt.Sprintf("/proxy/%v/connections/%v", *s.proxyId, *s.connectionId) - err := s.HttpService.Do(ctx, "DELETE", url, nil, nil, 200, &response) - return response, err -} \ No newline at end of file diff --git a/proxy/proxy_create.go b/proxy/proxy_create.go index dfa0be20..25220bdb 100644 --- a/proxy/proxy_create.go +++ b/proxy/proxy_create.go @@ -1,38 +1,38 @@ package proxy import ( - "context" + "context" - httputils "github.com/fivetran/go-fivetran/http_utils" + httputils "github.com/fivetran/go-fivetran/http_utils" ) // ProxyCreateService implements the Proxy Agent Management, Create a Proxy Agent. // Ref. https://fivetran.com/docs/rest-api/proxy-management#createaproxyagent type ProxyCreateService struct { - httputils.HttpService - display_name *string - group_id *string + httputils.HttpService + display_name *string + group_region *string } func (s *ProxyCreateService) request() *proxyCreateRequest { - return &proxyCreateRequest{ - DisplayName: s.display_name, - GroupId: s.group_id, - } + return &proxyCreateRequest{ + DisplayName: s.display_name, + GroupRegion: s.group_region, + } } func (s *ProxyCreateService) DisplayName(value string) *ProxyCreateService { - s.display_name = &value - return s + s.display_name = &value + return s } -func (s *ProxyCreateService) GroupId(value string) *ProxyCreateService { - s.group_id = &value - return s +func (s *ProxyCreateService) GroupRegion(value string) *ProxyCreateService { + s.group_region = &value + return s } func (s *ProxyCreateService) Do(ctx context.Context) (ProxyCreateResponse, error) { - var response ProxyCreateResponse - err := s.HttpService.Do(ctx, "POST", "/proxy", s.request(), nil, 201, &response) - return response, err + var response ProxyCreateResponse + err := s.HttpService.Do(ctx, "POST", "/proxy", s.request(), nil, 201, &response) + return response, err } \ No newline at end of file diff --git a/proxy/proxy_create_test.go b/proxy/proxy_create_test.go index 5e916cb3..44bef279 100644 --- a/proxy/proxy_create_test.go +++ b/proxy/proxy_create_test.go @@ -12,7 +12,7 @@ import ( const ( PROXY_NAME = "Test Proxy" - PROXY_GROUP = "group_id" + PROXY_GROUP = "group_region" ) func TestNewProxyCreate(t *testing.T) { @@ -30,7 +30,7 @@ func TestNewProxyCreate(t *testing.T) { // act response, err := ftClient.NewProxyCreate(). DisplayName(PROXY_NAME). - GroupId(PROXY_GROUP). + GroupRegion(PROXY_GROUP). Do(context.Background()) if err != nil { @@ -60,7 +60,7 @@ func prepareProxyCreateResponse() string { func assertProxyCreateRequest(t *testing.T, request map[string]interface{}) { testutils.AssertKey(t, "display_name", request, PROXY_NAME) - testutils.AssertKey(t, "group_id", request, PROXY_GROUP) + testutils.AssertKey(t, "group_region", request, PROXY_GROUP) } func assertProxyCreateResponse(t *testing.T, response proxy.ProxyCreateResponse) { diff --git a/test_utils/test_utils.go b/test_utils/test_utils.go index 8d3ed635..2bb56ebe 100644 --- a/test_utils/test_utils.go +++ b/test_utils/test_utils.go @@ -513,6 +513,7 @@ func CleanupAccount() { CleanupWebhooks() CleanupTeams() CleanupProxy() + CleanupLocalProcessingAgents() } func IsPredefinedUserExist() bool { @@ -602,21 +603,15 @@ func CleanupExternalLogging() { } func CleanupPrivateLinks() { - groups, err := Client.NewGroupsList().Do(context.Background()) + links, err := Client.NewPrivateLinkList().Do(context.Background()) if err != nil { log.Fatal(err) } - for _, group := range groups.Data.Items { - privateLinks, err := Client.NewGroupListPrivateLinks().GroupID(group.ID).Do(context.Background()) - if err != nil { + for _, link := range links.Data.Items { + _, err := Client.NewPrivateLinkDelete().PrivateLinkId(link.Id).Do(context.Background()) + if err != nil && err.Error() != "status code: 404; expected: 200" { log.Fatal(err) } - for _, privateLinks := range privateLinks.Data.Items { - _, err := Client.NewPrivateLinksDelete().PrivateLinkId(privateLinks.Id).Do(context.Background()) - if err != nil && err.Error() != "status code: 404; expected: 200" { - log.Fatal(err) - } - } } } @@ -669,6 +664,24 @@ func CleanupProxy() { } } +func CleanupLocalProcessingAgents() { + list, err := Client.NewLocalProcessingAgentList().Do(context.Background()) + if err != nil { + log.Fatal(err) + } + + for _, lpa := range list.Data.Items { + _, err := Client.NewLocalProcessingAgentDelete().AgentId(lpa.Id).Do(context.Background()) + if err != nil && err.Error() != "status code: 404; expected: 200" { + log.Fatal(err) + } + } + + if list.Data.NextCursor != "" { + CleanupLocalProcessingAgents() + } +} + func CreateTempExternalLogging(t *testing.T) string { t.Helper() externalLoggingId := CreateExternalLogging(t) @@ -705,66 +718,26 @@ func CreateExternalLogging(t *testing.T) string { } /* Private Links */ -func CreatePrivateLinkGroup(t *testing.T) string { +func CreatePrivateLink(t *testing.T) (string) { t.Helper() - created, err := Client.NewGroupCreate().Name("private_link_test").Do(context.Background()) - if err != nil { - t.Logf("%+v\n", created) - t.Error(err) - } - return created.Data.ID -} - -func CreatePrivateLinkDestination(t *testing.T, id string) string { - t.Helper() - destination, err := Client.NewDestinationCreate(). - GroupID(id). - Service("adls"). - Region("AZURE_EASTUS2"). - RunSetupTests(false). - TimeZoneOffset("-5"). - Config( - fivetran.NewDestinationConfig(). - StorageAccountName("adls_storage_account_name"). - ContainerName("adls_container_name"). - TenantId("service_principal_tenant_id"). - ClientId("service_principal_client_id"). - SecretValue("service_principal_secret_value"). - PrefixPath("adls_container_path_prefix"). - ConnectionType("Directly")). - Do(context.Background()) - if err != nil { - t.Logf("%+v\n", destination) - t.Error(err) - } - return destination.Data.ID -} - -func CreatePrivateLink(t *testing.T) (string, string, string) { - t.Helper() - plGroupId := CreatePrivateLinkGroup(t) - t.Logf("groupId %+v\n", plGroupId) - plDestinationId := CreatePrivateLinkDestination(t,plGroupId) - t.Logf("plDestinationId %+v\n", plDestinationId) - - created, err := Client.NewPrivateLinksCreate(). - Name("test"). - GroupId(plGroupId). - Config(fivetran.NewPrivateLinksConfig(). - ConnectionServiceId("1"). - SubResourceName("blob")). + created, err := Client.NewPrivateLinkCreate(). + Name("go_sdk_private_link_internal"). + Service("SOURCE"). + Region("GCP_US_EAST4"). + Config(fivetran.NewPrivateLinkConfig(). + ConnectionServiceName("test")). Do(context.Background()) if err != nil { t.Logf("%+v\n", created) t.Error(err) } - return created.Data.Id, plDestinationId, plGroupId + return created.Data.Id } func DeletePrivateLink(t *testing.T, id string) { t.Helper() - deleted, err := Client.NewPrivateLinksDelete().PrivateLinkId(id).Do(context.Background()) + deleted, err := Client.NewPrivateLinkDelete().PrivateLinkId(id).Do(context.Background()) if err != nil { t.Logf("%+v\n", deleted) @@ -772,16 +745,14 @@ func DeletePrivateLink(t *testing.T, id string) { } } -func CreateTempPrivateLink(t *testing.T) (string, string) { +func CreateTempPrivateLink(t *testing.T) (string) { t.Helper() - privateLinkId, plDestinationId, plGroupId := CreatePrivateLink(t) + privateLinkId := CreatePrivateLink(t) t.Cleanup(func() { - //DeletePrivateLink(t, privateLinkId) - DeleteDestination(t, plDestinationId) - DeleteGroup(t, plGroupId) + DeletePrivateLink(t, privateLinkId) }) - return privateLinkId, plGroupId + return privateLinkId } /* Private Links */ @@ -981,7 +952,7 @@ func CreateProxy(t *testing.T) string { t.Helper() created, err := Client.NewProxyCreate(). DisplayName("go_sdk_proxy_internal"). - GroupId(PredefinedGroupId). + GroupRegion("GCP_US_EAST4"). Do(context.Background()) if err != nil { @@ -1001,25 +972,28 @@ func DeleteProxy(t *testing.T, id string) { } } -func DeleteProxyConnection(t *testing.T, proxyId string, connectionId string) { +func CreateLocalProcessingAgent(t *testing.T) string { t.Helper() - deleted, err := Client.NewProxyConnectionMembershipDelete().ProxyId(proxyId).ConnectionId(connectionId).Do(context.Background()) + created, err := Client.NewLocalProcessingAgentCreate(). + DisplayName("go_sdk_lpa_internal"). + GroupId(PredefinedGroupId). + EnvType("DOCKER"). + AcceptTerms(true). + Do(context.Background()) if err != nil { - t.Logf("%+v\n", deleted) + t.Logf("%+v\n", created) t.Error(err) } + return created.Data.Id } -func CreateProxyConnection(t *testing.T, proxyId string, connectionId string) { +func DeleteLocalProcessingAgent(t *testing.T, id string) { t.Helper() - created, err := Client.NewProxyConnectionMembershipCreate(). - ProxyId(proxyId). - ConnectionId(connectionId). - Do(context.Background()) + deleted, err := Client.NewLocalProcessingAgentDelete().AgentId(id).Do(context.Background()) if err != nil { - t.Logf("%+v\n", created) + t.Logf("%+v\n", deleted) t.Error(err) } } \ No newline at end of file diff --git a/tests/e2e/connector_create_test.go b/tests/e2e/connector_create_test.go index 22f3bf4f..25f15a9c 100644 --- a/tests/e2e/connector_create_test.go +++ b/tests/e2e/connector_create_test.go @@ -13,6 +13,7 @@ func TestNewConnectorCreateE2E(t *testing.T) { GroupID(testutils.PredefinedGroupId). Service("itunes_connect"). RunSetupTests(false). + NetworkingMethod("Directly"). Config(fivetran.NewConnectorConfig(). Schema("itunes_e2e_connect"). Username("fivetran"). @@ -39,6 +40,10 @@ func TestNewConnectorCreateE2E(t *testing.T) { testutils.AssertEqual(t, *created.Data.PauseAfterTrial, false) testutils.AssertEqual(t, *created.Data.SyncFrequency, 360) testutils.AssertEqual(t, created.Data.ScheduleType, "auto") + testutils.AssertEmpty(t, created.Data.PrivateLinkId) + testutils.AssertEmpty(t, created.Data.LocalProcessingAgentId) + testutils.AssertEmpty(t, created.Data.ProxyAgentId) + testutils.AssertEqual(t, created.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, created.Data.Status.SetupState, "incomplete") testutils.AssertEqual(t, created.Data.Status.SyncState, "scheduled") diff --git a/tests/e2e/connector_modify_test.go b/tests/e2e/connector_modify_test.go index 57cd8496..d70d099b 100644 --- a/tests/e2e/connector_modify_test.go +++ b/tests/e2e/connector_modify_test.go @@ -42,7 +42,11 @@ func TestNewConnectorModifyE2E(t *testing.T) { testutils.AssertEqual(t, *updated.Data.PauseAfterTrial, true) testutils.AssertEqual(t, *updated.Data.SyncFrequency, 1440) testutils.AssertEqual(t, updated.Data.ScheduleType, "auto") - + testutils.AssertEmpty(t, updated.Data.PrivateLinkId) + testutils.AssertEmpty(t, updated.Data.LocalProcessingAgentId) + testutils.AssertEmpty(t, updated.Data.ProxyAgentId) + testutils.AssertEqual(t, updated.Data.NetworkingMethod, "Directly") + testutils.AssertNotEmpty(t, updated.Data.Status.SetupState) testutils.AssertEqual(t, updated.Data.Status.SyncState, "paused") testutils.AssertEqual(t, updated.Data.Status.UpdateState, "on_schedule") diff --git a/tests/e2e/destination_create_test.go b/tests/e2e/destination_create_test.go index 7eb92b94..ff6205c6 100644 --- a/tests/e2e/destination_create_test.go +++ b/tests/e2e/destination_create_test.go @@ -15,6 +15,7 @@ func TestNewDestinationCreateE2E(t *testing.T) { TimeZoneOffset("+10"). RunSetupTests(false). DaylightSavingTimeEnabled(true). + NetworkingMethod("Directly"). Config(fivetran.NewDestinationConfig(). Host("your-account.snowflakecomputing.com"). Port(443). @@ -37,6 +38,9 @@ func TestNewDestinationCreateE2E(t *testing.T) { testutils.AssertEqual(t, created.Data.TimeZoneOffset, "+10") testutils.AssertEqual(t, created.Data.DaylightSavingTimeEnabled, true) testutils.AssertEqual(t, created.Data.SetupStatus, "incomplete") + testutils.AssertEmpty(t, created.Data.PrivateLinkId) + testutils.AssertEmpty(t, created.Data.LocalProcessingAgentId) + testutils.AssertEqual(t, created.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, created.Data.Config.Host, "your-account.snowflakecomputing.com") testutils.AssertEqual(t, created.Data.Config.Port, "443") testutils.AssertEqual(t, created.Data.Config.Database, "fivetran") @@ -76,6 +80,9 @@ func TestNewDestinationCreateCustomE2E(t *testing.T) { testutils.AssertEqual(t, created.Data.Region, "GCP_US_EAST4") testutils.AssertEqual(t, created.Data.TimeZoneOffset, "+10") testutils.AssertEqual(t, created.Data.DaylightSavingTimeEnabled, false) + testutils.AssertEmpty(t, created.Data.PrivateLinkId) + testutils.AssertEmpty(t, created.Data.LocalProcessingAgentId) + testutils.AssertEqual(t, created.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, created.Data.SetupStatus, "incomplete") testutils.AssertEqual(t, created.Data.Config["host"], "your-account.snowflakecomputing.com") testutils.AssertEqual(t, created.Data.Config["port"], "443") diff --git a/tests/e2e/destination_details_test.go b/tests/e2e/destination_details_test.go index 632574b3..1dc520d3 100644 --- a/tests/e2e/destination_details_test.go +++ b/tests/e2e/destination_details_test.go @@ -24,6 +24,9 @@ func TestNewDestinationDetailsE2E(t *testing.T) { testutils.AssertEqual(t, details.Data.Region, "GCP_US_EAST4") testutils.AssertEqual(t, details.Data.TimeZoneOffset, "+10") testutils.AssertEqual(t, details.Data.DaylightSavingTimeEnabled, true) + testutils.AssertEmpty(t, details.Data.PrivateLinkId) + testutils.AssertEmpty(t, details.Data.LocalProcessingAgentId) + testutils.AssertEqual(t, details.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, details.Data.SetupStatus, "incomplete") testutils.AssertEqual(t, details.Data.Config.Database, "fivetran") testutils.AssertEqual(t, details.Data.Config.Password, "******") @@ -50,6 +53,9 @@ func TestNewDestinationDetailsCustomE2E(t *testing.T) { testutils.AssertEqual(t, details.Data.TimeZoneOffset, "+10") testutils.AssertEqual(t, details.Data.DaylightSavingTimeEnabled, true) testutils.AssertEqual(t, details.Data.SetupStatus, "incomplete") + testutils.AssertEmpty(t, details.Data.PrivateLinkId) + testutils.AssertEmpty(t, details.Data.LocalProcessingAgentId) + testutils.AssertEqual(t, details.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, details.Data.Config["database"], "fivetran") testutils.AssertEqual(t, details.Data.Config["password"], "******") testutils.AssertEqual(t, details.Data.Config["port"], "443") diff --git a/tests/e2e/destination_modify_test.go b/tests/e2e/destination_modify_test.go index 969b9d18..7f16f33e 100644 --- a/tests/e2e/destination_modify_test.go +++ b/tests/e2e/destination_modify_test.go @@ -37,6 +37,9 @@ func TestNewDestinationModifyE2E(t *testing.T) { testutils.AssertEqual(t, details.Data.Region, "GCP_AUSTRALIA_SOUTHEAST1") testutils.AssertEqual(t, details.Data.TimeZoneOffset, "+10") testutils.AssertEqual(t, details.Data.DaylightSavingTimeEnabled, true) + testutils.AssertEmpty(t, details.Data.PrivateLinkId) + testutils.AssertEmpty(t, details.Data.LocalProcessingAgentId) + testutils.AssertEqual(t, details.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, details.Data.Config.Host, "updated_host.snowflakecomputing.com") testutils.AssertEqual(t, details.Data.Config.Port, "444") testutils.AssertEqual(t, details.Data.Config.Database, "fivetran_updated") @@ -74,6 +77,9 @@ func TestNewDestinationModifyCustomE2E(t *testing.T) { testutils.AssertEqual(t, details.Data.Region, "GCP_AUSTRALIA_SOUTHEAST1") testutils.AssertEqual(t, details.Data.TimeZoneOffset, "+10") testutils.AssertEqual(t, details.Data.DaylightSavingTimeEnabled, false) + testutils.AssertEmpty(t, details.Data.PrivateLinkId) + testutils.AssertEmpty(t, details.Data.LocalProcessingAgentId) + testutils.AssertEqual(t, details.Data.NetworkingMethod, "Directly") testutils.AssertEqual(t, details.Data.Config["host"], "updated_host.snowflakecomputing.com") testutils.AssertEqual(t, details.Data.Config["port"], "444") testutils.AssertEqual(t, details.Data.Config["database"], "fivetran_updated") diff --git a/tests/e2e/group_private_links_list_test.go b/tests/e2e/group_private_links_list_test.go deleted file mode 100644 index 1317a82f..00000000 --- a/tests/e2e/group_private_links_list_test.go +++ /dev/null @@ -1,27 +0,0 @@ -package fivetran_test - -import ( - "context" - "testing" - - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestNewGroupListPrivateLinksE2E(t *testing.T) { - t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed") - - privateLinkId, groupId := testutils.CreateTempPrivateLink(t) - privateLinks, err := testutils.Client.NewGroupListPrivateLinks().GroupID(groupId).Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", privateLinks) - t.Error(err) - } - - testutils.AssertEqual(t, privateLinks.Code, "Success") - testutils.AssertHasLength(t, privateLinks.Data.Items, 1) - - testutils.AssertEqual(t, privateLinks.Data.Items[0].Name, "test") - testutils.AssertEqual(t, privateLinks.Data.Items[0].Id, privateLinkId) - testutils.AssertEqual(t, privateLinks.Data.Items[0].GroupId, groupId) -} \ No newline at end of file diff --git a/tests/e2e/local_processing_agent_create_test.go b/tests/e2e/local_processing_agent_create_test.go new file mode 100644 index 00000000..3fa86398 --- /dev/null +++ b/tests/e2e/local_processing_agent_create_test.go @@ -0,0 +1,34 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewLocalProcessingAgentCreateE2E(t *testing.T) { + groupId := testutils.CreateGroup(t) + created, err := testutils.Client.NewLocalProcessingAgentCreate(). + DisplayName("go_sdk_test_lpa"). + GroupId(groupId). + EnvType("DOCKER"). + AcceptTerms(true). + Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", created) + t.Error(err) + } + + testutils.AssertEqual(t, created.Code, "Success") + testutils.AssertNotEmpty(t, created.Message) + testutils.AssertNotEmpty(t, created.Data.Id) + testutils.AssertEqual(t, created.Data.DisplayName, "go_sdk_test_lpa") + testutils.AssertEqual(t, created.Data.GroupId, groupId) + + t.Cleanup(func() { + testutils.DeleteLocalProcessingAgent(t, created.Data.Id) + testutils.DeleteGroup(t, groupId) + }) +} diff --git a/tests/e2e/local_processing_agent_delete_test.go b/tests/e2e/local_processing_agent_delete_test.go new file mode 100644 index 00000000..1034c6d5 --- /dev/null +++ b/tests/e2e/local_processing_agent_delete_test.go @@ -0,0 +1,21 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestNewLocalProcessingAgentDeleteE2E(t *testing.T) { + agentId := testutils.CreateLocalProcessingAgent(t) + + deleted, err := testutils.Client.NewLocalProcessingAgentDelete().AgentId(agentId).Do(context.Background()) + + if err != nil { + t.Logf("%+v\n", deleted) + t.Error(err) + } + + testutils.AssertEqual(t, deleted.Code, "Success") +} diff --git a/tests/e2e/local_processing_agent_details_test.go b/tests/e2e/local_processing_agent_details_test.go new file mode 100644 index 00000000..6ce064ff --- /dev/null +++ b/tests/e2e/local_processing_agent_details_test.go @@ -0,0 +1,25 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestLocalProcessingAgentDetailsE2E(t *testing.T) { + agentId := testutils.CreateLocalProcessingAgent(t) + + result, err := testutils.Client.NewLocalProcessingAgentDetails().AgentId(agentId).Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Id, agentId) + testutils.AssertNotEmpty(t, result.Data.DisplayName) + testutils.AssertNotEmpty(t, result.Data.GroupId) + + t.Cleanup(func() { testutils.DeleteLocalProcessingAgent(t, agentId) }) +} diff --git a/tests/e2e/local_processing_agent_list_test.go b/tests/e2e/local_processing_agent_list_test.go new file mode 100644 index 00000000..b4c3d5e3 --- /dev/null +++ b/tests/e2e/local_processing_agent_list_test.go @@ -0,0 +1,25 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestLocalProcessingAgentListE2E(t *testing.T) { + agentId := testutils.CreateLocalProcessingAgent(t) + + result, err := testutils.Client.NewLocalProcessingAgentList().Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Items[0].Id, agentId) + testutils.AssertNotEmpty(t, result.Data.Items[0].DisplayName) + testutils.AssertNotEmpty(t, result.Data.Items[0].GroupId) + + t.Cleanup(func() { testutils.DeleteLocalProcessingAgent(t, agentId) }) +} diff --git a/tests/e2e/private_links_create_test.go b/tests/e2e/private_link_create_test.go similarity index 51% rename from tests/e2e/private_links_create_test.go rename to tests/e2e/private_link_create_test.go index f2b3a202..2b5cb1cc 100644 --- a/tests/e2e/private_links_create_test.go +++ b/tests/e2e/private_link_create_test.go @@ -11,14 +11,12 @@ import ( func TestNewPrivateLinkCreateE2E(t *testing.T) { t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed") - plGroupId := testutils.CreatePrivateLinkGroup(t) - plDestinationId := testutils.CreatePrivateLinkDestination(t, plGroupId) - - created, err := testutils.Client.NewPrivateLinksCreate(). - Name("test"). - GroupId(plGroupId). - Config(fivetran.NewPrivateLinksConfig(). - ConnectionServiceId("1")). + created, err := testutils.Client.NewPrivateLinkCreate(). + Name("go_sdk_private_link_test"). + Service("SOURCE"). + Region("GCP_US_EAST4"). + Config(fivetran.NewPrivateLinkConfig(). + ConnectionServiceName("test")). Do(context.Background()) if err != nil { @@ -28,13 +26,13 @@ func TestNewPrivateLinkCreateE2E(t *testing.T) { testutils.AssertEqual(t, created.Code, "Success") testutils.AssertNotEmpty(t, created.Message) - testutils.AssertEqual(t, created.Data.Name, "test") - testutils.AssertEqual(t, created.Data.GroupId, plGroupId) - testutils.AssertEqual(t, created.Data.Config.ConnectionServiceId, "1") + testutils.AssertEqual(t, created.Data.Name, "go_sdk_private_link_test") + testutils.AssertNotEmpty(t, created.Data.Service) + testutils.AssertNotEmpty(t, created.Data.Region) + testutils.AssertNotEmpty(t, created.Data.CloudProvider) + testutils.AssertEqual(t, created.Data.Config.ConnectionServiceName, "test") t.Cleanup(func() { testutils.DeletePrivateLink(t, created.Data.Id) - testutils.DeleteDestination(t, plDestinationId) - testutils.DeleteGroup(t, plGroupId) }) } diff --git a/tests/e2e/private_links_delete_test.go b/tests/e2e/private_link_delete_test.go similarity index 60% rename from tests/e2e/private_links_delete_test.go rename to tests/e2e/private_link_delete_test.go index b0418013..3cf2047b 100644 --- a/tests/e2e/private_links_delete_test.go +++ b/tests/e2e/private_link_delete_test.go @@ -10,9 +10,9 @@ import ( func TestNewPrivateLinkDeleteE2E(t *testing.T) { t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed") - privateLinkId, plDestinationId, plGroupId := testutils.CreatePrivateLink(t) + privateLinkId := testutils.CreatePrivateLink(t) - deleted, err := testutils.Client.NewPrivateLinksDelete().PrivateLinkId(privateLinkId).Do(context.Background()) + deleted, err := testutils.Client.NewPrivateLinkDelete().PrivateLinkId(privateLinkId).Do(context.Background()) if err != nil { t.Logf("%+v\n", deleted) @@ -21,9 +21,4 @@ func TestNewPrivateLinkDeleteE2E(t *testing.T) { testutils.AssertEqual(t, deleted.Code, "Success") testutils.AssertNotEmpty(t, deleted.Message) - - t.Cleanup(func() { - testutils.DeleteDestination(t, plDestinationId) - testutils.DeleteGroup(t, plGroupId) - }) } diff --git a/tests/e2e/private_link_details_test.go b/tests/e2e/private_link_details_test.go new file mode 100644 index 00000000..92662359 --- /dev/null +++ b/tests/e2e/private_link_details_test.go @@ -0,0 +1,31 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestPrivateLinkDetailsE2E(t *testing.T) { + t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed") + + linkId := testutils.CreatePrivateLink(t) + + result, err := testutils.Client.NewPrivateLinkDetails().PrivateLinkId(linkId).Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Id, linkId) + testutils.AssertNotEmpty(t, result.Data.Name) + testutils.AssertNotEmpty(t, result.Data.AccountId) + testutils.AssertNotEmpty(t, result.Data.Region) + testutils.AssertNotEmpty(t, result.Data.Service) + testutils.AssertNotEmpty(t, result.Data.CreatedAt) + testutils.AssertNotEmpty(t, result.Data.CreatedBy) + + t.Cleanup(func() { testutils.DeletePrivateLink(t, linkId) }) +} diff --git a/tests/e2e/private_link_list_test.go b/tests/e2e/private_link_list_test.go new file mode 100644 index 00000000..d2eb536d --- /dev/null +++ b/tests/e2e/private_link_list_test.go @@ -0,0 +1,31 @@ +package fivetran_test + +import ( + "context" + "testing" + + testutils "github.com/fivetran/go-fivetran/test_utils" +) + +func TestPrivateLinkListE2E(t *testing.T) { + t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed") + + linkId := testutils.CreatePrivateLink(t) + + result, err := testutils.Client.NewPrivateLinkList().Do(context.Background()) + if err != nil { + t.Logf("%+v\n", result) + t.Error(err) + } + + testutils.AssertEqual(t, result.Code, "Success") + testutils.AssertEqual(t, result.Data.Items[0].Id, linkId) + testutils.AssertNotEmpty(t, result.Data.Items[0].AccountId) + testutils.AssertNotEmpty(t, result.Data.Items[0].Region) + testutils.AssertNotEmpty(t, result.Data.Items[0].Service) + testutils.AssertNotEmpty(t, result.Data.Items[0].CreatedAt) + testutils.AssertNotEmpty(t, result.Data.Items[0].CreatedBy) + testutils.AssertNotEmpty(t, result.Data.Items[0].Name) + + t.Cleanup(func() { testutils.DeletePrivateLink(t, linkId) }) +} diff --git a/tests/e2e/private_links_modify_test.go b/tests/e2e/private_link_modify_test.go similarity index 59% rename from tests/e2e/private_links_modify_test.go rename to tests/e2e/private_link_modify_test.go index c74fca57..2b426173 100644 --- a/tests/e2e/private_links_modify_test.go +++ b/tests/e2e/private_link_modify_test.go @@ -11,10 +11,11 @@ import ( func TestNewPrivateLinkModifyE2E(t *testing.T) { t.Skip("Private links have a strict limit on the number of requests per hour; to test changes in these modules, this Skip must be removed") - privateLinkId, plGroupId := testutils.CreateTempPrivateLink(t) - details, err := testutils.Client.NewPrivateLinksModify().PrivateLinkId(privateLinkId). - Config(fivetran.NewPrivateLinksConfig(). - ConnectionServiceId("2")). + privateLinkId := testutils.CreateTempPrivateLink(t) + + details, err := testutils.Client.NewPrivateLinkModify().PrivateLinkId(privateLinkId). + Config(fivetran.NewPrivateLinkConfig(). + ConnectionServiceName("test2")). Do(context.Background()) if err != nil { @@ -24,7 +25,5 @@ func TestNewPrivateLinkModifyE2E(t *testing.T) { testutils.AssertEqual(t, details.Code, "Success") testutils.AssertNotEmpty(t, details.Message) - - testutils.AssertEqual(t, details.Data.GroupId, plGroupId) - testutils.AssertEqual(t, details.Data.Config.ConnectionServiceId, "2") + testutils.AssertEqual(t, details.Data.Config.ConnectionServiceName, "test2") } \ No newline at end of file diff --git a/tests/e2e/proxy_connection_membership_create_test.go b/tests/e2e/proxy_connection_membership_create_test.go deleted file mode 100644 index 6942c33e..00000000 --- a/tests/e2e/proxy_connection_membership_create_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package fivetran_test - -import ( - "context" - "testing" - - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestNewProxyConnectionMembershipCreateE2E(t *testing.T) { - proxyId := testutils.CreateProxy(t) - connectionId := testutils.CreateConnector(t) - - created, err := testutils.Client.NewProxyConnectionMembershipCreate(). - ProxyId(proxyId). - ConnectionId(connectionId). - Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", created) - t.Error(err) - } - - testutils.AssertEqual(t, created.Code, "Success") - testutils.AssertNotEmpty(t, created.Message) - - t.Cleanup(func() { - testutils.DeleteProxyConnection(t, proxyId, connectionId) - testutils.DeleteConnector(t, connectionId) - testutils.DeleteProxy(t, proxyId) - }) -} diff --git a/tests/e2e/proxy_connection_membership_delete_test.go b/tests/e2e/proxy_connection_membership_delete_test.go deleted file mode 100644 index fde9ace5..00000000 --- a/tests/e2e/proxy_connection_membership_delete_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package fivetran_test - -import ( - "context" - "testing" - - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestProxyConnectionMembershipDeleteE2E(t *testing.T) { - proxyId := testutils.CreateProxy(t) - connectionId := testutils.CreateConnector(t) - testutils.CreateProxyConnection(t, proxyId, connectionId) - - deleted, err := testutils.Client.NewProxyConnectionMembershipDelete(). - ProxyId(proxyId). - ConnectionId(connectionId). - Do(context.Background()) - - if err != nil { - t.Logf("%+v\n", deleted) - t.Error(err) - } - - testutils.AssertEqual(t, deleted.Code, "Success") - testutils.AssertNotEmpty(t, deleted.Message) - - t.Cleanup(func() { - testutils.DeleteConnector(t, connectionId) - testutils.DeleteProxy(t, proxyId) - }) -} diff --git a/tests/e2e/proxy_connection_memberships_list_test.go b/tests/e2e/proxy_connection_memberships_list_test.go deleted file mode 100644 index 45b3bfca..00000000 --- a/tests/e2e/proxy_connection_memberships_list_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package fivetran_test - -import ( - "context" - "testing" - - testutils "github.com/fivetran/go-fivetran/test_utils" -) - -func TestProxyConnectionMembershipsListE2E(t *testing.T) { - proxyId := testutils.CreateProxy(t) - connectionId := testutils.CreateConnector(t) - testutils.CreateProxyConnection(t, proxyId, connectionId) - - result, err := testutils.Client.NewProxyConnectionMembershipsList().ProxyId(proxyId).Do(context.Background()) - if err != nil { - t.Logf("%+v\n", result) - t.Error(err) - } - - testutils.AssertEqual(t, result.Code, "Success") - testutils.AssertEqual(t, result.Data.Items[0].ConnectionId, connectionId) - - t.Cleanup(func() { - testutils.DeleteProxyConnection(t, proxyId, connectionId) - testutils.DeleteConnector(t, connectionId) - testutils.DeleteProxy(t, proxyId) - }) -} diff --git a/tests/e2e/proxy_create_test.go b/tests/e2e/proxy_create_test.go index aa572d28..641054a9 100644 --- a/tests/e2e/proxy_create_test.go +++ b/tests/e2e/proxy_create_test.go @@ -8,10 +8,9 @@ import ( ) func TestNewProxyCreateE2E(t *testing.T) { - groupId := testutils.CreateGroup(t) created, err := testutils.Client.NewProxyCreate(). DisplayName("go_sdk_test_proxy"). - GroupId(groupId). + GroupRegion("GCP_US_EAST4"). Do(context.Background()) if err != nil { @@ -27,6 +26,5 @@ func TestNewProxyCreateE2E(t *testing.T) { t.Cleanup(func() { testutils.DeleteProxy(t, created.Data.AgentId) - testutils.DeleteGroup(t, groupId) }) }