-
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
5307228
commit 868a423
Showing
23 changed files
with
1,129 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package connectors | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
httputils "github.com/fivetran/go-fivetran/http_utils" | ||
) | ||
|
||
// ConnectorsSourceMetadataService implements the Connector Management, Retrieve source metadata API. | ||
// Ref. https://fivetran.com/docs/rest-api/connectors#retrievesourcemetadata | ||
type ConnectorsSourceMetadataService struct { | ||
httputils.HttpService | ||
limit *int | ||
cursor *string | ||
} | ||
|
||
func (s *ConnectorsSourceMetadataService) Limit(value int) *ConnectorsSourceMetadataService { | ||
s.limit = &value | ||
return s | ||
} | ||
|
||
func (s *ConnectorsSourceMetadataService) Cursor(value string) *ConnectorsSourceMetadataService { | ||
s.cursor = &value | ||
return s | ||
} | ||
|
||
func (s *ConnectorsSourceMetadataService) Do(ctx context.Context) (ConnectorsSourceMetadataResponse, error) { | ||
var response ConnectorsSourceMetadataResponse | ||
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", "/metadata/connectors", nil, queries, 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
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,47 @@ | ||
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 | ||
} |
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,109 @@ | ||
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_SERVICE = "service" | ||
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", | ||
"service": "%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_SERVICE, | ||
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.Service, GROUP_LIST_PRIVATE_LINK_SERVICE) | ||
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) | ||
} | ||
|
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,34 @@ | ||
package privatelinks | ||
|
||
type PrivateLinksResponseBase struct { | ||
Id string `json:"id"` | ||
Name string `json:"name"` | ||
GroupId string `json:"group_id"` | ||
CloudProvider string `json:"cloud_provider"` | ||
Service string `json:"service"` | ||
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"` | ||
Service *string `json:"service,omitempty"` | ||
GroupId *string `json:"group_id,omitempty"` | ||
Config any `json:"config,omitempty"` | ||
} | ||
|
||
type privateLinksModifyRequest struct { | ||
Config any `json:"config,omitempty"` | ||
} |
Oops, something went wrong.