Skip to content

Commit

Permalink
chore: use service module from the gen client
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Sep 16, 2024
1 parent 1e1ae6a commit aff1c57
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23

require (
github.com/aiven/aiven-go-client/v2 v2.27.0
github.com/aiven/go-client-codegen v0.30.0
github.com/aiven/go-client-codegen v0.31.0
github.com/avast/retry-go v3.0.0+incompatible
github.com/dave/jennifer v1.7.1
github.com/docker/go-units v0.5.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ github.com/aiven/go-api-schemas v1.85.0 h1:wpTCQWjTLKQvVQq184u6Ji0ZksDZkNPqS6f6z
github.com/aiven/go-api-schemas v1.85.0/go.mod h1:/F7Rr8UVErsRxhgGN7CSo+Ac/uAg/OiAVCEKCfm3VAo=
github.com/aiven/go-client-codegen v0.30.0 h1:K+FZW4MvA68xMy5B2p85npeZ3qOwhAcDw/GAhmrJyWY=
github.com/aiven/go-client-codegen v0.30.0/go.mod h1:FfbH32Xb+Hx5zeKTIug1Y8SfMeB+AKNRzxgrzkts2oA=
github.com/aiven/go-client-codegen v0.30.1-0.20240913123648-ebf410109925 h1:oN5ZXpSALpf+jQIn4OSbHFgF0dzIxb1gNb08htspyts=
github.com/aiven/go-client-codegen v0.30.1-0.20240913123648-ebf410109925/go.mod h1:FfbH32Xb+Hx5zeKTIug1Y8SfMeB+AKNRzxgrzkts2oA=
github.com/aiven/go-client-codegen v0.31.0 h1:kFJnrdgVTmGoLfTnWV6Qxlzjg6APZ/321ApiOHLwIpM=
github.com/aiven/go-client-codegen v0.31.0/go.mod h1:FfbH32Xb+Hx5zeKTIug1Y8SfMeB+AKNRzxgrzkts2oA=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/aiven/aiven-go-client/v2"
avngen "github.com/aiven/go-client-codegen"
codegenintegrations "github.com/aiven/go-client-codegen/handler/serviceintegration"
"github.com/aiven/go-client-codegen/handler/service"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -45,11 +45,11 @@ func aivenServiceIntegrationSchema() map[string]*schema.Schema {
Type: schema.TypeString,
},
"integration_type": {
Description: "Type of the service integration. Possible values: " + schemautil.JoinQuoted(codegenintegrations.IntegrationTypeChoices(), ", ", "`"),
Description: "Type of the service integration. Possible values: " + schemautil.JoinQuoted(service.IntegrationTypeChoices(), ", ", "`"),
ForceNew: true,
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(codegenintegrations.IntegrationTypeChoices(), false),
ValidateFunc: validation.StringInSlice(service.IntegrationTypeChoices(), false),
},
"project": {
Description: "Project the integration belongs to.",
Expand Down Expand Up @@ -126,10 +126,10 @@ func resourceServiceIntegrationCreate(ctx context.Context, d *schema.ResourceDat
}
}

req := &codegenintegrations.ServiceIntegrationCreateIn{
req := &service.ServiceIntegrationCreateIn{
DestEndpointId: plainEndpointID(schemautil.OptionalStringPointer(d, "destination_endpoint_id")),
DestService: schemautil.OptionalStringPointer(d, "destination_service_name"),
IntegrationType: codegenintegrations.IntegrationType(integrationType),
IntegrationType: service.IntegrationType(integrationType),
SourceEndpointId: plainEndpointID(schemautil.OptionalStringPointer(d, "source_endpoint_id")),
SourceService: schemautil.OptionalStringPointer(d, "source_service_name"),
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func resourceServiceIntegrationUpdate(ctx context.Context, d *schema.ResourceDat
ctx,
projectName,
integrationID,
&codegenintegrations.ServiceIntegrationUpdateIn{
&service.ServiceIntegrationUpdateIn{
UserConfig: userConfig,
},
)
Expand Down Expand Up @@ -226,7 +226,7 @@ func resourceServiceIntegrationDelete(ctx context.Context, d *schema.ResourceDat
return nil
}

func resourceServiceIntegrationCheckForPreexistingResource(ctx context.Context, d *schema.ResourceData, client avngen.Client) (*codegenintegrations.ServiceIntegrationOut, error) {
func resourceServiceIntegrationCheckForPreexistingResource(ctx context.Context, d *schema.ResourceData, client avngen.Client) (*service.ServiceIntegrationOut, error) {
projectName := d.Get("project").(string)
integrationType := d.Get("integration_type").(string)
sourceServiceName := d.Get("source_service_name").(string)
Expand Down Expand Up @@ -303,7 +303,7 @@ func resourceServiceIntegrationWaitUntilActive(ctx context.Context, d *schema.Re

func resourceServiceIntegrationCopyAPIResponseToTerraform(
d *schema.ResourceData,
res *codegenintegrations.ServiceIntegrationGetOut,
res *service.ServiceIntegrationGetOut,
project string,
) error {
if err := d.Set("project", project); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"slices"

avngen "github.com/aiven/go-client-codegen"
codegenintegrations "github.com/aiven/go-client-codegen/handler/serviceintegration"
"github.com/aiven/go-client-codegen/handler/service"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

Expand All @@ -17,7 +17,7 @@ import (
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/serviceintegrationendpoint"
)

func hasEndpointConfig[T string | codegenintegrations.EndpointType](kind T) bool {
func hasEndpointConfig[T string | service.EndpointType](kind T) bool {
return slices.Contains(serviceintegrationendpoint.UserConfigTypes(), string(kind))
}

Expand All @@ -37,11 +37,11 @@ func aivenServiceIntegrationEndpointSchema() map[string]*schema.Schema {
},
"endpoint_type": {
Description: "Type of the service integration endpoint. Possible values: " +
schemautil.JoinQuoted(codegenintegrations.EndpointTypeChoices(), ", ", "`"),
schemautil.JoinQuoted(service.EndpointTypeChoices(), ", ", "`"),
ForceNew: true,
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice(codegenintegrations.EndpointTypeChoices(), false),
ValidateFunc: validation.StringInSlice(service.EndpointTypeChoices(), false),
},
"endpoint_config": {
Description: "Integration endpoint specific backend configuration",
Expand Down Expand Up @@ -80,9 +80,9 @@ func resourceServiceIntegrationEndpointCreate(ctx context.Context, d *schema.Res
projectName := d.Get("project").(string)
endpointType := d.Get("endpoint_type").(string)

req := &codegenintegrations.ServiceIntegrationEndpointCreateIn{
req := &service.ServiceIntegrationEndpointCreateIn{
EndpointName: d.Get("endpoint_name").(string),
EndpointType: codegenintegrations.EndpointType(endpointType),
EndpointType: service.EndpointType(endpointType),
UserConfig: make(map[string]interface{}),
}

Expand Down Expand Up @@ -111,7 +111,7 @@ func resourceServiceIntegrationEndpointRead(ctx context.Context, d *schema.Resou
return err
}

endpoint, err := client.ServiceIntegrationEndpointGet(ctx, projectName, endpointID, codegenintegrations.ServiceIntegrationEndpointGetIncludeSecrets(true))
endpoint, err := client.ServiceIntegrationEndpointGet(ctx, projectName, endpointID, service.ServiceIntegrationEndpointGetIncludeSecrets(true))
if err != nil {
return schemautil.ResourceReadHandleNotFound(err, d)
}
Expand All @@ -137,7 +137,7 @@ func resourceServiceIntegrationEndpointUpdate(ctx context.Context, d *schema.Res
}

endpointType := d.Get("endpoint_type").(string)
req := &codegenintegrations.ServiceIntegrationEndpointUpdateIn{
req := &service.ServiceIntegrationEndpointUpdateIn{
UserConfig: make(map[string]interface{}),
}

Expand Down Expand Up @@ -175,7 +175,7 @@ func resourceServiceIntegrationEndpointDelete(ctx context.Context, d *schema.Res

func copyServiceIntegrationEndpointPropertiesFromAPIResponseToTerraform(
d *schema.ResourceData,
endpoint *codegenintegrations.ServiceIntegrationEndpointGetOut,
endpoint *service.ServiceIntegrationEndpointGetOut,
project string,
) error {
if err := d.Set("project", project); err != nil {
Expand Down

0 comments on commit aff1c57

Please sign in to comment.