diff --git a/go.mod b/go.mod index 6686bf2cf82..c967c62d803 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/chimesdkvoice v1.12.6 github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.8.6 github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.15.7 + github.com/aws/aws-sdk-go-v2/service/cloudfront v1.32.6 github.com/aws/aws-sdk-go-v2/service/cloudsearch v1.20.6 github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.36.0 github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.32.2 diff --git a/go.sum b/go.sum index 40bb47148a2..707613cd85e 100644 --- a/go.sum +++ b/go.sum @@ -76,6 +76,8 @@ github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.8.6 h1:ype6mmLnDjOX8d4pkbj7SX github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.8.6/go.mod h1:ibuCTolZ5/w65nBDKpsXhzZUeQluX/m0hnXAiwFPvP8= github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.15.7 h1:8sBfx7QkDZ6dgfUNXWHWRc6Eax7WOI3Slgj6OKDHKTI= github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.15.7/go.mod h1:P1EMD13hrBE2KUw030w482Eyk2NmOFIvGqmgNi4XRDc= +github.com/aws/aws-sdk-go-v2/service/cloudfront v1.32.6 h1:xKbFXea2CIF/Wskauz1TMr//wZ6FyzEafMdSBIQqn80= +github.com/aws/aws-sdk-go-v2/service/cloudfront v1.32.6/go.mod h1:iB6PQSb3ULRrrlEiuFfVE318JiBOdk4k46BbuzrrgXc= github.com/aws/aws-sdk-go-v2/service/cloudsearch v1.20.6 h1:JnPMJhFeFICqHCS5eRMB3ZwdD53ytQ1CzJIXaiJ7rW0= github.com/aws/aws-sdk-go-v2/service/cloudsearch v1.20.6/go.mod h1:AxaZoqWLbXOy30l+IpFv5ryhIGDjhhap9+MQg5Xqndo= github.com/aws/aws-sdk-go-v2/service/cloudtrail v1.36.0 h1:tRzTDe5E/dgGwJRR1cltjV9NPG9J5L7HK01+p2B4gCM= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index c13dc8918c8..3634d2d988d 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -21,6 +21,7 @@ import ( chimesdkvoice_sdkv2 "github.com/aws/aws-sdk-go-v2/service/chimesdkvoice" cleanrooms_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cleanrooms" cloudcontrol_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" + cloudfront_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudfront" cloudsearch_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudsearch" cloudtrail_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudtrail" cloudwatch_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudwatch" @@ -397,6 +398,10 @@ func (c *AWSClient) CloudFrontConn(ctx context.Context) *cloudfront_sdkv1.CloudF return errs.Must(conn[*cloudfront_sdkv1.CloudFront](ctx, c, names.CloudFront, make(map[string]any))) } +func (c *AWSClient) CloudFrontClient(ctx context.Context) *cloudfront_sdkv2.Client { + return errs.Must(client[*cloudfront_sdkv2.Client](ctx, c, names.CloudFront, make(map[string]any))) +} + func (c *AWSClient) CloudHSMV2Conn(ctx context.Context) *cloudhsmv2_sdkv1.CloudHSMV2 { return errs.Must(conn[*cloudhsmv2_sdkv1.CloudHSMV2](ctx, c, names.CloudHSMV2, make(map[string]any))) } diff --git a/internal/service/cloudfront/service_endpoints_gen_test.go b/internal/service/cloudfront/service_endpoints_gen_test.go index ed9588ac7d8..d6a328f4ce9 100644 --- a/internal/service/cloudfront/service_endpoints_gen_test.go +++ b/internal/service/cloudfront/service_endpoints_gen_test.go @@ -4,15 +4,16 @@ package cloudfront_test import ( "context" + "errors" "fmt" - "net/url" "os" "path/filepath" "reflect" "strings" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + cloudfront_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudfront" cloudfront_sdkv1 "github.com/aws/aws-sdk-go/service/cloudfront" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" @@ -202,33 +203,69 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S }, } - for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv - testcase := testcase + t.Run("v1", func(t *testing.T) { + for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv + testcase := testcase - t.Run(name, func(t *testing.T) { - testEndpointCase(t, region, testcase, callService) - }) - } + t.Run(name, func(t *testing.T) { + testEndpointCase(t, region, testcase, callServiceV1) + }) + } + }) + + t.Run("v2", func(t *testing.T) { + for name, testcase := range testcases { //nolint:paralleltest // uses t.Setenv + testcase := testcase + + t.Run(name, func(t *testing.T) { + testEndpointCase(t, region, testcase, callServiceV2) + }) + } + }) } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := cloudfront_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(cloudfront_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), cloudfront_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) + if ep.URI.Path == "" { + ep.URI.Path = "/" + } + + return ep.URI.String() +} + +func callServiceV2(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { + t.Helper() + + var endpoint string - if url.Path == "" { - url.Path = "/" + client := meta.CloudFrontClient(ctx) + + _, err := client.ListDistributions(ctx, &cloudfront_sdkv2.ListDistributionsInput{}, + func(opts *cloudfront_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &endpoint), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) } - return url.String() + return endpoint } -func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { +func callServiceV1(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { t.Helper() client := meta.CloudFrontConn(ctx) diff --git a/internal/service/cloudfront/service_package_gen.go b/internal/service/cloudfront/service_package_gen.go index 1581087c214..90c1fcf8d93 100644 --- a/internal/service/cloudfront/service_package_gen.go +++ b/internal/service/cloudfront/service_package_gen.go @@ -5,6 +5,8 @@ package cloudfront import ( "context" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + cloudfront_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudfront" aws_sdkv1 "github.com/aws/aws-sdk-go/aws" session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" cloudfront_sdkv1 "github.com/aws/aws-sdk-go/service/cloudfront" @@ -141,6 +143,17 @@ func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*c return cloudfront_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil } +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*cloudfront_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) + + return cloudfront_sdkv2.NewFromConfig(cfg, func(o *cloudfront_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil +} + func ServicePackage(ctx context.Context) conns.ServicePackage { return &servicePackage{} } diff --git a/names/data/names_data.csv b/names/data/names_data.csv index d3faf7d286e..3a04e09b3f3 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -61,7 +61,7 @@ clouddirectory,clouddirectory,clouddirectory,clouddirectory,,clouddirectory,,,Cl servicediscovery,servicediscovery,servicediscovery,servicediscovery,,servicediscovery,,,ServiceDiscovery,ServiceDiscovery,,1,,aws_service_discovery_,aws_servicediscovery_,,service_discovery_,Cloud Map,AWS,,,,,,,ServiceDiscovery,ListNamespaces,, cloud9,cloud9,cloud9,cloud9,,cloud9,,,Cloud9,Cloud9,,1,,,aws_cloud9_,,cloud9_,Cloud9,AWS,,,,,,,Cloud9,ListEnvironments,, cloudformation,cloudformation,cloudformation,cloudformation,,cloudformation,,,CloudFormation,CloudFormation,,1,,,aws_cloudformation_,,cloudformation_,CloudFormation,AWS,,,,,,,CloudFormation,ListStackInstances,, -cloudfront,cloudfront,cloudfront,cloudfront,,cloudfront,,,CloudFront,CloudFront,,1,,,aws_cloudfront_,,cloudfront_,CloudFront,Amazon,,,,,,,CloudFront,ListDistributions,, +cloudfront,cloudfront,cloudfront,cloudfront,,cloudfront,,,CloudFront,CloudFront,,1,2,,aws_cloudfront_,,cloudfront_,CloudFront,Amazon,,,,,,,CloudFront,ListDistributions,, cloudhsm,cloudhsm,cloudhsm,cloudhsm,,,,,,,,,,,,,,CloudHSM,AWS,x,,,,,,,,,Legacy cloudhsmv2,cloudhsmv2,cloudhsmv2,cloudhsmv2,,cloudhsmv2,,cloudhsm,CloudHSMV2,CloudHSMV2,,1,,aws_cloudhsm_v2_,aws_cloudhsmv2_,,cloudhsm,CloudHSM,AWS,,,,,,,CloudHSM V2,DescribeClusters,, cloudsearch,cloudsearch,cloudsearch,cloudsearch,,cloudsearch,,,CloudSearch,CloudSearch,,,2,,aws_cloudsearch_,,cloudsearch_,CloudSearch,Amazon,,,,,,,CloudSearch,ListDomainNames,,