Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update HDA to actual version #118

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
}
6 changes: 6 additions & 0 deletions hybrid_deployment_agent/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
}

Expand Down
7 changes: 7 additions & 0 deletions hybrid_deployment_agent/hybrid_deployment_agents_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type HybridDeploymentAgentCreateService struct {
groupId *string
displayName *string
envType *string
authType *string
acceptTerms *bool
}

Expand All @@ -21,6 +22,7 @@ func (s *HybridDeploymentAgentCreateService) request() hybridDeploymentAgentCrea
GroupId: s.groupId,
DisplayName: s.displayName,
EnvType: s.envType,
AuthType: s.authType,
AcceptTerms: s.acceptTerms,
}
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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",
Expand All @@ -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)
}

Expand All @@ -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")
Expand Down
16 changes: 14 additions & 2 deletions hybrid_deployment_agent/hybrid_deployment_agents_reauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ 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 {
s.agentId = &value
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

Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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)
}
Loading