Skip to content

Commit

Permalink
Add Proxy Management
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetran-aleksandrboldyrev authored Apr 2, 2024
1 parent 89b0f3b commit eaa7d66
Show file tree
Hide file tree
Showing 27 changed files with 1,168 additions and 4 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ 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.3...HEAD)
## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v0.8.4...HEAD)

## [0.8.4](https://github.com/fivetran/go-fivetran/compare/v0.8.3...v0.8.4)

## 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)

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

Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ REST API Endpoint | REST API Version | SDK Service
[Invite a user](https://fivetran.com/docs/rest-api/users#inviteauser) | v1 | [UserInviteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserInviteService)
[Modify a user](https://fivetran.com/docs/rest-api/users#modifyauser) | v1 | [UserModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserModifyService)
[Delete a user](https://fivetran.com/docs/rest-api/users#deleteauser) | v1 | [UserDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserDeleteService)
[List all connector memberships](https://fivetran.com/docs/rest-api/users#listallconnectormemberships) | v1 | [UserConnectorMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipsListService)
[Retrieve connector membership](https://fivetran.com/docs/rest-api/users#retrieveconnectormembership) | v1 | [UserConnectorMembershipDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipDetailsService)
[Add connector membership](https://fivetran.com/docs/rest-api/users#addconnectormembership) | v1 | [UserConnectorMembershipCreateService](https://pkg.go.dev/github.com/fivetran/go-UserConnectorMembershipCreateService#UserDeleteService)
[Update connector membership](https://fivetran.com/docs/rest-api/users#updateconnectormembership) | v1 | [UserConnectorMembershipModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipModifyService)
[Delete connector membership](https://fivetran.com/docs/rest-api/users#deleteconnectormembership) | v1 | [UserConnectorMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserConnectorMembershipDeleteService)
[List all group memberships](https://fivetran.com/docs/rest-api/users#listallgroupmemberships) | v1 | [UserGroupMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipsListService)
[Retrieve group membership](https://fivetran.com/docs/rest-api/users#retrievegroupmembership) | v1 | [UserGroupMembershipDetailsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipDetailsService)
[Add group membership](https://fivetran.com/docs/rest-api/users#addgroupmembership) | v1 | [UserGroupMembershipCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipCreateService)
[Update group membership](https://fivetran.com/docs/rest-api/users#updategroupmembership) | v1 | [UserGroupMembershipModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipModifyService)
[Delete group membership](https://fivetran.com/docs/rest-api/users#deletegroupmembership) | v1 | [UserGroupMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#UserGroupMembershipDeleteService)

### [Group Management API](https://fivetran.com/docs/rest-api/groups)

Expand Down Expand Up @@ -214,6 +224,7 @@ REST API Endpoint | REST API Version | SDK Service/Config
[Delete a team](https://fivetran.com/docs/rest-api/teams#deleteateam) | v1 | [TeamsDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamsDeleteService)

### [Team Management User memberships](https://fivetran.com/docs/rest-api/teams#usermemberships)

REST API Endpoint | REST API Version | SDK Service/Config
--- | --- | ---
[List all user memberships](https://fivetran.com/docs/rest-api/teams#listallusermemberships) | v1 | [TeamUserMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamUserMembershipsListService)
Expand All @@ -223,6 +234,7 @@ REST API Endpoint | REST API Version | SDK Service/Config
[Delete a user from a team](https://fivetran.com/docs/rest-api/teams#deleteauserfromateam) | v1 | [TeamUserMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamUserMembershipDeleteService)

### [Team Management Connector memberships](https://fivetran.com/docs/rest-api/teams#connectormemberships)

REST API Endpoint | REST API Version | SDK Service/Config
--- | --- | ---
[List all connector memberships](https://fivetran.com/docs/rest-api/teams#listallconnectormemberships) | v1 | [TeamConnectorMembershipsListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamConnectorMembershipsListService)
Expand All @@ -232,6 +244,7 @@ REST API Endpoint | REST API Version | SDK Service/Config
[Delete connector membership](https://fivetran.com/docs/rest-api/teams#deleteconnectormembership) | v1 | [TeamConnectorMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamConnectorMembershipDeleteService)

### [Team Management Group memberships](https://fivetran.com/docs/rest-api/teams#groupmemberships)

REST API Endpoint | REST API Version | SDK Service/Config
--- | --- | ---
[List all group memberships](https://fivetran.com/docs/rest-api/teams#listallgroupmemberships) | v1 | [TeamGroupMembershipsService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamGroupMembershipsService)
Expand All @@ -240,6 +253,28 @@ REST API Endpoint | REST API Version | SDK Service/Config
[Update group membership](https://fivetran.com/docs/rest-api/teams#updategroupmembership) | v1 | [TeamGroupMembershipModifyService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamGroupMembershipModifyService)
[Delete group membership](https://fivetran.com/docs/rest-api/teams#deletegroupmembership) | v1 | [TeamGroupMembershipDeleteService](https://pkg.go.dev/github.com/fivetran/go-fivetran#TeamGroupMembershipDeleteService)

### [Private Links Management](https://fivetran.com/docs/rest-api/private-links-management)

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)
[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)

### [Proxy Agents Management](https://fivetran.com/docs/rest-api/proxy-management)

REST API Endpoint | REST API Version | SDK Service/Config
--- | --- | ---
[Create a Proxy Agent](/docs/rest-api/proxy-management#createaproxyagent) | v1 | [ProxyCreateService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyCreateService)
[List all Proxy Agents](/docs/rest-api/proxy-management#listallproxyagents) | v1 | [ProxyListService](https://pkg.go.dev/github.com/fivetran/go-fivetran#ProxyListService)
[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)

## Support

Please get in touch with us through our [Support Portal](https://support.fivetran.com/) if you
Expand Down
32 changes: 31 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/fivetran/go-fivetran/teams"
"github.com/fivetran/go-fivetran/users"
"github.com/fivetran/go-fivetran/webhooks"
"github.com/fivetran/go-fivetran/proxy"
)

// Client holds client configuration
Expand All @@ -35,7 +36,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.2"
const defaultUserAgent = "Go-Fivetran/0.8.4"

// New receives API Key and API Secret, and returns a new Client with the
// default HTTP client
Expand Down Expand Up @@ -601,3 +602,32 @@ func (c *Client) NewPrivateLinksDetails() *privatelinks.PrivateLinksDetailsServi
func (c *Client) NewPrivateLinksModify() *privatelinks.PrivateLinksModifyService {
return &privatelinks.PrivateLinksModifyService{HttpService: c.NewHttpService()}
}

/* Proxy */
func (c *Client) NewProxyCreate() *proxy.ProxyCreateService {
return &proxy.ProxyCreateService{HttpService: c.NewHttpService()}
}

func (c *Client) NewProxyList() *proxy.ProxyListService {
return &proxy.ProxyListService{HttpService: c.NewHttpService()}
}

func (c *Client) NewProxyDetails() *proxy.ProxyDetailsService {
return &proxy.ProxyDetailsService{HttpService: c.NewHttpService()}
}

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()}
}
2 changes: 0 additions & 2 deletions private_links/private_links_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package privatelinks

import (
"context"
"fmt"

httputils "github.com/fivetran/go-fivetran/http_utils"
)
Expand Down Expand Up @@ -47,7 +46,6 @@ func (s *PrivateLinksCreateService) Config(value *PrivateLinksConfig) *PrivateLi

func (s *PrivateLinksCreateService) Do(ctx context.Context) (PrivateLinksResponse, error) {
var response PrivateLinksResponse
fmt.Printf("request %v", s.request())
err := s.HttpService.Do(ctx, "POST", "/private-links", s.request(), nil, 201, &response)
return response, err
}
61 changes: 61 additions & 0 deletions proxy/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package proxy

import (
"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"`
}

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"`
}

type proxyCreateRequest struct {
DisplayName *string `json:"display_name,omitempty"`
GroupId *string `json:"group_id,omitempty"`
}

type ProxyCreateResponse struct {
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"`
}

type ProxyDetailsResponse struct {
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"`
}

type ProxyConnectionMembership struct {
ConnectionId string `json:"connection_id"`
}

type proxyConnectionMembershipCreateRequest struct {
ConnectionId *string `json:"connection_id,omitempty"`
}
45 changes: 45 additions & 0 deletions proxy/proxy_connection_membership_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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
}
61 changes: 61 additions & 0 deletions proxy/proxy_connection_membership_create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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)
}
43 changes: 43 additions & 0 deletions proxy/proxy_connection_membership_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
}
Loading

0 comments on commit eaa7d66

Please sign in to comment.