-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89b0f3b
commit eaa7d66
Showing
27 changed files
with
1,168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.