Skip to content

Commit

Permalink
feat: updated based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilmhdh committed Dec 10, 2024
1 parent fe0d5e8 commit 6a316e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
8 changes: 4 additions & 4 deletions internal/client/integrations_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (client Client) CreateIntegrationAuth(request CreateIntegrationAuthRequest)
return body, nil
}

func (client Client) UpdateIntegrationAuth(request UpdateIntegrationAuthRequest) (CreateIntegrationAuthResponse, error) {
var body CreateIntegrationAuthResponse
func (client Client) UpdateIntegrationAuth(request UpdateIntegrationAuthRequest) (UpdateIntegrationAuthResponse, error) {
var body UpdateIntegrationAuthResponse
response, err := client.Config.HttpClient.
R().
SetResult(&body).
Expand All @@ -45,11 +45,11 @@ func (client Client) UpdateIntegrationAuth(request UpdateIntegrationAuthRequest)
Patch("api/v1/integration-auth/" + request.IntegrationAuthId)

if err != nil {
return CreateIntegrationAuthResponse{}, fmt.Errorf("UpdateIntegrationAuth: Unable to complete api request [err=%s]", err)
return UpdateIntegrationAuthResponse{}, fmt.Errorf("UpdateIntegrationAuth: Unable to complete api request [err=%s]", err)
}

if response.IsError() {
return CreateIntegrationAuthResponse{}, fmt.Errorf("UpdateIntegrationAuth: Unsuccessful response. [response=%s]", string(response.Body()))
return UpdateIntegrationAuthResponse{}, fmt.Errorf("UpdateIntegrationAuth: Unsuccessful response. [response=%s]", string(response.Body()))
}

return body, nil
Expand Down
6 changes: 6 additions & 0 deletions internal/client/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,12 @@ type CreateIntegrationAuthResponse struct {
} `json:"integrationAuth"`
}

type UpdateIntegrationAuthResponse struct {
IntegrationAuth struct {
ID string `json:"id"`
} `json:"integrationAuth"`
}

type DeleteIntegrationAuthRequest struct {
ID string `json:"id"`
}
Expand Down
32 changes: 16 additions & 16 deletions internal/provider/resource/integration_aws_secrets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,22 @@ func (r *IntegrationAWSSecretsManagerResource) Update(ctx context.Context, req r
}
}

if plan.MappingBehavior.ValueString() == MAPPING_BEHAVIOR_MANY_TO_ONE && (plan.AWSPath.IsNull() || plan.AWSPath.ValueString() == "") {
resp.Diagnostics.AddError(
"Invalid plan",
"secrets_manager_path is required when mapping_behavior is 'many-to-one'",
)
return
}

if plan.MappingBehavior.ValueString() == MAPPING_BEHAVIOR_ONE_TO_ONE && (!plan.AWSPath.IsNull() && plan.AWSPath.ValueString() != "") {
resp.Diagnostics.AddError(
"Invalid plan",
"secrets_manager_path should not be used when mapping_behavior is 'one-to-one'",
)
return
}

updateIntegrationAuthRequest := infisical.UpdateIntegrationAuthRequest{
Integration: infisical.IntegrationAuthTypeAwsSecretsManager,
IntegrationAuthId: plan.IntegrationAuthID.String(),
Expand Down Expand Up @@ -474,22 +490,6 @@ func (r *IntegrationAWSSecretsManagerResource) Update(ctx context.Context, req r
return
}

if plan.MappingBehavior.ValueString() == MAPPING_BEHAVIOR_MANY_TO_ONE && (plan.AWSPath.IsNull() || plan.AWSPath.ValueString() == "") {
resp.Diagnostics.AddError(
"Invalid plan",
"secrets_manager_path is required when mapping_behavior is 'many-to-one'",
)
return
}

if plan.MappingBehavior.ValueString() == MAPPING_BEHAVIOR_ONE_TO_ONE && (!plan.AWSPath.IsNull() && plan.AWSPath.ValueString() != "") {
resp.Diagnostics.AddError(
"Invalid plan",
"secrets_manager_path should not be used when mapping_behavior is 'one-to-one'",
)
return
}

// Convert metadata to map[string]interface{} if needed
metadataMap := map[string]interface{}{}

Expand Down

0 comments on commit 6a316e7

Please sign in to comment.