-
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
46f5b22
commit e625abc
Showing
9 changed files
with
142 additions
and
3 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
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
33 changes: 33 additions & 0 deletions
33
hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials.go
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,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 | ||
} |
62 changes: 62 additions & 0 deletions
62
hybrid_deployment_agent/hybrid_deployment_agents_reset_credentials_test.go
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,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) | ||
} |