From e625abc5e7dbfc8170d44b7bcd0cee18cc80d272 Mon Sep 17 00:00:00 2001 From: Aleksandr Boldyrev <125960514+fivetran-aleksandrboldyrev@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:30:59 +0100 Subject: [PATCH] Update HDA to actual version (#118) --- CHANGELOG.md | 10 ++- client.go | 4 ++ hybrid_deployment_agent/common_types.go | 6 ++ .../hybrid_deployment_agents_create.go | 7 +++ .../hybrid_deployment_agents_create_test.go | 4 ++ .../hybrid_deployment_agents_reauth.go | 16 ++++- .../hybrid_deployment_agents_reauth_test.go | 3 + ...rid_deployment_agents_reset_credentials.go | 33 ++++++++++ ...eployment_agents_reset_credentials_test.go | 62 +++++++++++++++++++ 9 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials.go create mode 100644 hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 930945b..b966d44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v1.0.2...HEAD) +## [Unreleased](https://github.com/fivetran/go-fivetran/compare/v1.0.3...HEAD) + +## [1.0.3](https://github.com/fivetran/go-fivetran/compare/v1.0.2...v1.0.3) + +## Added +- Field `HybridDeploymentAgentCreateService.authType` +- Field `HybridDeploymentAgentReAuthService.authType` +- Field `HybridDeploymentAgentCreateResponse.Token` +- Service `HybridDeploymentAgentResetCredentialsService` ## [1.0.2](https://github.com/fivetran/go-fivetran/compare/v1.0.1...v1.0.2) diff --git a/client.go b/client.go index dfe1322..f437bf6 100644 --- a/client.go +++ b/client.go @@ -653,3 +653,7 @@ func (c *Client) NewHybridDeploymentAgentList() *hybriddeploymentagent.HybridDep func (c *Client) NewHybridDeploymentAgentReAuth() *hybriddeploymentagent.HybridDeploymentAgentReAuthService { return &hybriddeploymentagent.HybridDeploymentAgentReAuthService{HttpService: c.NewHttpService()} } + +func (c *Client) NewHybridDeploymentAgentResetCredentials() *hybriddeploymentagent.HybridDeploymentAgentResetCredentialsService { + return &hybriddeploymentagent.HybridDeploymentAgentResetCredentialsService{HttpService: c.NewHttpService()} +} \ No newline at end of file diff --git a/hybrid_deployment_agent/common_types.go b/hybrid_deployment_agent/common_types.go index 4eba58f..cb7b413 100644 --- a/hybrid_deployment_agent/common_types.go +++ b/hybrid_deployment_agent/common_types.go @@ -3,10 +3,15 @@ package hybriddeploymentagent type hybridDeploymentAgentCreateRequest struct { GroupId *string `json:"group_id,omitempty"` DisplayName *string `json:"display_name,omitempty"` + AuthType *string `json:"auth_type,omitempty"` EnvType *string `json:"env_type,omitempty"` AcceptTerms *bool `json:"accept_terms,omitempty"` } +type hybridDeploymentAgentReAuthRequest struct { + AuthType *string `json:"auth_type,omitempty"` +} + type HybridDeploymentAgentDetails struct { Id string `json:"id"` DisplayName string `json:"display_name"` @@ -35,6 +40,7 @@ type HybridDeploymentAgentCreateResponse struct { AuthJson string `json:"auth_json"` DockerComposeYaml string `json:"docker_compose_yaml"` } `json:"files"` + Token string `json:"token"` } `json:"data"` } diff --git a/hybrid_deployment_agent/hybrid_deployment_agents_create.go b/hybrid_deployment_agent/hybrid_deployment_agents_create.go index 09dddff..e609db1 100644 --- a/hybrid_deployment_agent/hybrid_deployment_agents_create.go +++ b/hybrid_deployment_agent/hybrid_deployment_agents_create.go @@ -13,6 +13,7 @@ type HybridDeploymentAgentCreateService struct { groupId *string displayName *string envType *string + authType *string acceptTerms *bool } @@ -21,6 +22,7 @@ func (s *HybridDeploymentAgentCreateService) request() hybridDeploymentAgentCrea GroupId: s.groupId, DisplayName: s.displayName, EnvType: s.envType, + AuthType: s.authType, AcceptTerms: s.acceptTerms, } } @@ -40,6 +42,11 @@ func (s *HybridDeploymentAgentCreateService) EnvType(value string) *HybridDeploy return s } +func (s *HybridDeploymentAgentCreateService) AuthType(value string) *HybridDeploymentAgentCreateService { + s.authType = &value + return s +} + func (s *HybridDeploymentAgentCreateService) AcceptTerms(value bool) *HybridDeploymentAgentCreateService { s.acceptTerms = &value return s diff --git a/hybrid_deployment_agent/hybrid_deployment_agents_create_test.go b/hybrid_deployment_agent/hybrid_deployment_agents_create_test.go index 1e8e56c..7d29e06 100644 --- a/hybrid_deployment_agent/hybrid_deployment_agents_create_test.go +++ b/hybrid_deployment_agent/hybrid_deployment_agents_create_test.go @@ -26,6 +26,7 @@ func TestNewHybridDeploymentAgentCreateMappingMock(t *testing.T) { response, err := ftClient.NewHybridDeploymentAgentCreate(). GroupId("group_id"). DisplayName("display_name"). + AuthType("AUTO"). EnvType("DOCKER"). AcceptTerms(true). Do(context.Background()) @@ -53,6 +54,7 @@ func prepareHybridDeploymentAgentCreateResponse() string { "display_name": "display_name", "group_id": "group_id", "registered_at": "1970-01-01T00:00:00.000000Z", + "token": "token", "files": { "config_json": "config_json", "auth_json": "auth_json", @@ -66,6 +68,7 @@ func assertHybridDeploymentAgentCreateRequest(t *testing.T, request map[string]i 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, "auth_type", request, "AUTO") testutils.AssertKey(t, "accept_terms", request, true) } @@ -77,6 +80,7 @@ func assertHybridDeploymentAgentCreateResponse(t *testing.T, response hybriddepl 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.Token, "token") 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/hybrid_deployment_agent/hybrid_deployment_agents_reauth.go b/hybrid_deployment_agent/hybrid_deployment_agents_reauth.go index a8d603e..817faf9 100644 --- a/hybrid_deployment_agent/hybrid_deployment_agents_reauth.go +++ b/hybrid_deployment_agent/hybrid_deployment_agents_reauth.go @@ -11,7 +11,14 @@ import ( // Ref. https://fivetran.com/docs/rest-api/hybrid-deployment-agent-management#regeneratekeys type HybridDeploymentAgentReAuthService struct { httputils.HttpService - agentId *string + agentId *string + authType *string +} + +func (s *HybridDeploymentAgentReAuthService) request() hybridDeploymentAgentReAuthRequest { + return hybridDeploymentAgentReAuthRequest{ + AuthType: s.authType, + } } func (s *HybridDeploymentAgentReAuthService) AgentId(value string) *HybridDeploymentAgentReAuthService { @@ -19,6 +26,11 @@ func (s *HybridDeploymentAgentReAuthService) AgentId(value string) *HybridDeploy return s } +func (s *HybridDeploymentAgentReAuthService) AuthType(value string) *HybridDeploymentAgentReAuthService { + s.authType = &value + return s +} + func (s *HybridDeploymentAgentReAuthService) Do(ctx context.Context) (HybridDeploymentAgentCreateResponse, error) { var response HybridDeploymentAgentCreateResponse @@ -27,6 +39,6 @@ func (s *HybridDeploymentAgentReAuthService) Do(ctx context.Context) (HybridDepl } url := fmt.Sprintf("/hybrid-deployment-agents/%v/re-auth", *s.agentId) - err := s.HttpService.Do(ctx, "POST", url, nil, nil, 200, &response) + err := s.HttpService.Do(ctx, "POST", url, s.request(), nil, 200, &response) return response, err } \ No newline at end of file diff --git a/hybrid_deployment_agent/hybrid_deployment_agents_reauth_test.go b/hybrid_deployment_agent/hybrid_deployment_agents_reauth_test.go index b55c391..85fdb7e 100644 --- a/hybrid_deployment_agent/hybrid_deployment_agents_reauth_test.go +++ b/hybrid_deployment_agent/hybrid_deployment_agents_reauth_test.go @@ -23,6 +23,7 @@ func TestNewHybridDeploymentAgentReAuthMappingMock(t *testing.T) { // act response, err := ftClient.NewHybridDeploymentAgentReAuth(). AgentId("agent_id"). + AuthType("AUTO"). Do(context.Background()) if err != nil { @@ -48,6 +49,7 @@ func prepareHybridDeploymentAgentResponse() string { "display_name": "display_name", "group_id": "group_id", "registered_at": "1970-01-01T00:00:00.000000Z", + "token": "token_value", "files": { "config_json": "config_json", "auth_json": "auth_json", @@ -64,6 +66,7 @@ func assertHybridDeploymentAgentResponse(t *testing.T, response hybriddeployment 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.Token, "token_value") 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/hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials.go b/hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials.go new file mode 100644 index 0000000..a7e0883 --- /dev/null +++ b/hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials.go @@ -0,0 +1,33 @@ +package hybriddeploymentagent + +import ( + "context" + "fmt" + + httputils "github.com/fivetran/go-fivetran/http_utils" + "github.com/fivetran/go-fivetran/common" +) + +// HybridDeploymentAgentResetCredentialsService Regenerates authentication keys for the specified hybrid deployment agent. +// Ref. https://fivetran.com/docs/rest-api/api-reference/hybrid-deployment-agent-management/reset-local-processing-agent-credentials +type HybridDeploymentAgentResetCredentialsService struct { + httputils.HttpService + agentId *string +} + +func (s *HybridDeploymentAgentResetCredentialsService) AgentId(value string) *HybridDeploymentAgentResetCredentialsService { + s.agentId = &value + return s +} + +func (s *HybridDeploymentAgentResetCredentialsService) 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("/hybrid-deployment-agents/%v/reset-credentials", *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/hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials_test.go b/hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials_test.go new file mode 100644 index 0000000..e73a484 --- /dev/null +++ b/hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials_test.go @@ -0,0 +1,62 @@ +package hybriddeploymentagent_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 TestHybridDeploymentAgentResetCredentialsServiceDo(t *testing.T) { + // arrange + ftClient, mockClient := testutils.CreateTestClient() + handler := mockClient.When(http.MethodPost, "/v1/hybrid-deployment-agents/agent_id/reset-credentials").ThenCall( + func(req *http.Request) (*http.Response, error) { + response := mock.NewResponse(req, http.StatusOK, `{"code": "Success"}`) + return response, nil + }, + ) + + service := ftClient.NewHybridDeploymentAgentResetCredentials().AgentId("agent_id") + + // act + response, err := service.Do(context.Background()) + + // assert + if err != nil { + t.Error(err) + } + + assertHybridDeploymentAgentResetCredentialsResponse(t, response, "Success") + + // Check that the expected interactions with the mock client occurred + interactions := mockClient.Interactions() + testutils.AssertEqual(t, len(interactions), 1) + testutils.AssertEqual(t, interactions[0].Handler, handler) + testutils.AssertEqual(t, handler.Interactions, 1) +} + +func TestHybridDeploymentAgentsResetCredentialsServiceDoMissingAgentID(t *testing.T) { + // Create a test client + ftClient, _ := testutils.CreateTestClient() + + // Create the ExternalLoggingResetCredentialsService without setting the Log ID + service := ftClient.NewHybridDeploymentAgentResetCredentials() + + // Call the Do method to execute the request + _, err := service.Do(context.Background()) + + // Check for expected error + expectedError := fmt.Errorf("missing required agentId") + testutils.AssertEqual(t, err, expectedError) +} + +func assertHybridDeploymentAgentResetCredentialsResponse(t *testing.T, response common.CommonResponse, code string) { + testutils.AssertEqual(t, response.Code, code) +}