diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 192867c3aae..b5f4b6e76cb 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -1,7 +1,9 @@ Breaking Change --- +* `aws/endpoints`: Several functions and types have been removed + * Removes `DecodeModel` and `DecodeModelOptions` from the package ([#509](https://github.com/aws/aws-sdk-go-v2/pull/509)) + * Remove Region Constants, Partition Constants, and types use for exploring the endpoint data model ([#512](https://github.com/aws/aws-sdk-go-v2/pull/512)) * `service/s3/s3crypto`: Package and associated encryption/decryption clients have been removed from the SDK ([#511](https://github.com/aws/aws-sdk-go-v2/pull/511)) -* `aws/endpoints`: Removes `DecodeModel` and `DecodeModelOptions` from the package ([#509](https://github.com/aws/aws-sdk-go-v2/pull/509)) * `aws/external`: Removes several export constants and types ([#508](https://github.com/aws/aws-sdk-go-v2/pull/508)) * No longer exports AWS environment constants used by the external environment configuration loader * `DefaultSharedConfigProfile` is now defined an exported constant diff --git a/Makefile b/Makefile index b72b2257b71..1b9c5ae1dca 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ all: generate unit ################### # Code Generation # ################### -generate: cleanup-models gen-test gen-endpoints gen-services gen-external-asserts gen-tools +generate: cleanup-models gen-test gen-endpoints gen-services gen-external-asserts gen-test: gen-protocol-test gen-codegen-test @@ -55,9 +55,6 @@ gen-external-asserts: @echo "Generating SDK external package implementor assertions" go generate ./aws/external -gen-tools: - go generate -tags sdktool ./internal/awstesting/cmd/op_crawler/ - cleanup-models: @echo "Cleaning up stale model versions" @./cleanup_models.sh diff --git a/aws/endpoints/defaults.go b/aws/endpoints/defaults.go index 2c475917e85..5eff793c25c 100644 --- a/aws/endpoints/defaults.go +++ b/aws/endpoints/defaults.go @@ -6,80 +6,14 @@ import ( "regexp" ) -// Partition identifiers -const ( - AwsPartitionID = "aws" // AWS Standard partition. - AwsCnPartitionID = "aws-cn" // AWS China partition. - AwsUsGovPartitionID = "aws-us-gov" // AWS GovCloud (US) partition. - AwsIsoPartitionID = "aws-iso" // AWS ISO (US) partition. - AwsIsoBPartitionID = "aws-iso-b" // AWS ISOB (US) partition. -) - -// AWS Standard partition's regions. -const ( - ApEast1RegionID = "ap-east-1" // Asia Pacific (Hong Kong). - ApNortheast1RegionID = "ap-northeast-1" // Asia Pacific (Tokyo). - ApNortheast2RegionID = "ap-northeast-2" // Asia Pacific (Seoul). - ApSouth1RegionID = "ap-south-1" // Asia Pacific (Mumbai). - ApSoutheast1RegionID = "ap-southeast-1" // Asia Pacific (Singapore). - ApSoutheast2RegionID = "ap-southeast-2" // Asia Pacific (Sydney). - CaCentral1RegionID = "ca-central-1" // Canada (Central). - EuCentral1RegionID = "eu-central-1" // EU (Frankfurt). - EuNorth1RegionID = "eu-north-1" // EU (Stockholm). - EuWest1RegionID = "eu-west-1" // EU (Ireland). - EuWest2RegionID = "eu-west-2" // EU (London). - EuWest3RegionID = "eu-west-3" // EU (Paris). - MeSouth1RegionID = "me-south-1" // Middle East (Bahrain). - SaEast1RegionID = "sa-east-1" // South America (Sao Paulo). - UsEast1RegionID = "us-east-1" // US East (N. Virginia). - UsEast2RegionID = "us-east-2" // US East (Ohio). - UsWest1RegionID = "us-west-1" // US West (N. California). - UsWest2RegionID = "us-west-2" // US West (Oregon). -) - -// AWS China partition's regions. -const ( - CnNorth1RegionID = "cn-north-1" // China (Beijing). - CnNorthwest1RegionID = "cn-northwest-1" // China (Ningxia). -) - -// AWS GovCloud (US) partition's regions. -const ( - UsGovEast1RegionID = "us-gov-east-1" // AWS GovCloud (US-East). - UsGovWest1RegionID = "us-gov-west-1" // AWS GovCloud (US). -) - -// AWS ISO (US) partition's regions. -const ( - UsIsoEast1RegionID = "us-iso-east-1" // US ISO East. -) - -// AWS ISOB (US) partition's regions. -const ( - UsIsobEast1RegionID = "us-isob-east-1" // US ISOB East (Ohio). -) - // NewDefaultResolver returns an Endpoint resolver that will be able // to resolve endpoints for: AWS Standard, AWS China, AWS GovCloud (US), AWS ISO (US), and AWS ISOB (US). -// -// Use DefaultPartitions() to get the list of the default partitions. func NewDefaultResolver() *Resolver { return &Resolver{ partitions: defaultPartitions, } } -// DefaultPartitions returns a list of the partitions the SDK is bundled -// with. The available partitions are: AWS Standard, AWS China, AWS GovCloud (US), AWS ISO (US), and AWS ISOB (US). -// -// partitions := endpoints.DefaultPartitions -// for _, p := range partitions { -// // ... inspect partitions -// } -func DefaultPartitions() Partitions { - return defaultPartitions.Partitions() -} - var defaultPartitions = partitions{ awsPartition, awscnPartition, @@ -88,11 +22,6 @@ var defaultPartitions = partitions{ awsisobPartition, } -// AwsPartition returns the Resolver for AWS Standard. -func AwsPartition() Partition { - return awsPartition.Partition() -} - var awsPartition = partition{ ID: "aws", Name: "AWS Standard", @@ -4568,12 +4497,6 @@ var awsPartition = partition{ }, }, } - -// AwsCnPartition returns the Resolver for AWS China. -func AwsCnPartition() Partition { - return awscnPartition.Partition() -} - var awscnPartition = partition{ ID: "aws-cn", Name: "AWS China", @@ -5192,12 +5115,6 @@ var awscnPartition = partition{ }, }, } - -// AwsUsGovPartition returns the Resolver for AWS GovCloud (US). -func AwsUsGovPartition() Partition { - return awsusgovPartition.Partition() -} - var awsusgovPartition = partition{ ID: "aws-us-gov", Name: "AWS GovCloud (US)", @@ -6127,12 +6044,6 @@ var awsusgovPartition = partition{ }, }, } - -// AwsIsoPartition returns the Resolver for AWS ISO (US). -func AwsIsoPartition() Partition { - return awsisoPartition.Partition() -} - var awsisoPartition = partition{ ID: "aws-iso", Name: "AWS ISO (US)", @@ -6488,12 +6399,6 @@ var awsisoPartition = partition{ }, }, } - -// AwsIsoBPartition returns the Resolver for AWS ISOB (US). -func AwsIsoBPartition() Partition { - return awsisobPartition.Partition() -} - var awsisobPartition = partition{ ID: "aws-iso-b", Name: "AWS ISOB (US)", diff --git a/aws/endpoints/endpoints.go b/aws/endpoints/endpoints.go deleted file mode 100644 index b0d29295611..00000000000 --- a/aws/endpoints/endpoints.go +++ /dev/null @@ -1,325 +0,0 @@ -package endpoints - -import ( - "fmt" - - "github.com/aws/aws-sdk-go-v2/aws" -) - -// ResolveOptions provide the configuration needed to direct how the -// endpoints will be resolved. -type ResolveOptions struct { - // DisableSSL forces the endpoint to be resolved as HTTP. - // instead of HTTPS if the service supports it. - DisableSSL bool - - // Sets the resolver to resolve the endpoint as a dualstack endpoint - // for the service. If dualstack support for a service is not known and - // StrictMatching is not enabled a dualstack endpoint for the service will - // be returned. This endpoint may not be valid. If StrictMatching is - // enabled only services that are known to support dualstack will return - // dualstack endpoints. - UseDualStack bool - - // Enables strict matching of services and regions resolved endpoints. - // If the partition doesn't enumerate the exact service and region an - // error will be returned. This option will prevent returning endpoints - // that look valid, but may not resolve to any real endpoint. - StrictMatching bool -} - -// A Resolver provides endpoint resolution based on modeled endpoint data. -type Resolver struct { - ResolveOptions - - partitions partitions -} - -// ResolveEndpoint attempts to resolve an endpoint againsted the modeled endpoint -// data. If an endpoint is found it will be returned. An error will be returned -// otherwise. -// -// Searches through the partitions in the order they are defined. -func (r *Resolver) ResolveEndpoint(service, region string) (aws.Endpoint, error) { - return r.partitions.EndpointFor(service, region, r.ResolveOptions) -} - -// Partitions returns the partitions that make up the resolver. -func (r *Resolver) Partitions() Partitions { - return r.partitions.Partitions() -} - -// Partitions is a slice of paritions describing regions and endpoints -type Partitions []Partition - -// ForRegion returns the first partition which includes the region -// passed in. This includes both known regions and regions which match -// a pattern supported by the partition which may include regions that are -// not explicitly known by the partition. Use the Regions method of the -// returned Partition if explicit support is needed. -func (ps Partitions) ForRegion(id string) (Partition, bool) { - for _, p := range ps { - if _, ok := p.p.Regions[id]; ok || p.p.RegionRegex.MatchString(id) { - return p, true - } - } - - return Partition{}, false -} - -// ForPartition returns the parition with the matching ID passed in. -func (ps Partitions) ForPartition(id string) (Partition, bool) { - for _, p := range ps { - if p.ID() == id { - return p, true - } - } - - return Partition{}, false -} - -// A Partition provides the ability to enumerate the partition's regions -// and services. -type Partition struct { - id, dnsSuffix string - p *partition -} - -// DNSSuffix returns the base domain name of the partition. -func (p Partition) DNSSuffix() string { return p.dnsSuffix } - -// ID returns the identifier of the partition. -func (p Partition) ID() string { return p.id } - -// Endpoint attempts to resolve the endpoint based on service and region. -// See Options for information on configuring how the endpoint is resolved. -// -// If the service cannot be found in the metadata the endpoint will be resolved -// based on the parition's endpoint pattern, and service endpoint prefix. -// -// When resolving endpoints you can choose to enable StrictMatching. This will -// require the provided service and region to be known by the partition. -// If the endpoint cannot be strictly resolved an error will be returned. This -// mode is useful to ensure the endpoint resolved is valid. Without -// StrictMatching enabled the endpoint returned my look valid but may not work. -// StrictMatching requires the SDK to be updated if you want to take advantage -// of new regions and services expansions. -// -// Errors that can be returned. -// * UnknownServiceError -// * UnknownEndpointError -func (p Partition) Endpoint(service, region string, opts ResolveOptions) (aws.Endpoint, error) { - return p.p.EndpointFor(service, region, opts) -} - -// Regions returns a map of Regions indexed by their ID. This is useful for -// enumerating over the regions in a partition. -func (p Partition) Regions() map[string]Region { - rs := map[string]Region{} - for id := range p.p.Regions { - rs[id] = Region{ - id: id, - p: p.p, - } - } - - return rs -} - -// RegionsForService returns the map of regions for the service id specified. -// false is returned if the service is not found in the partition. -func (p Partition) RegionsForService(id string) (map[string]Region, bool) { - if _, ok := p.p.Services[id]; !ok { - return nil, false - } - - s := Service{ - id: id, - p: p.p, - } - return s.Regions(), true -} - -// Services returns a map of Service indexed by their ID. This is useful for -// enumerating over the services in a partition. -func (p Partition) Services() map[string]Service { - ss := map[string]Service{} - for id := range p.p.Services { - ss[id] = Service{ - id: id, - p: p.p, - } - } - - return ss -} - -// Resolver returns an endpoint resolver for the partitions. Use this to satisfy -// the SDK's EndpointResolver. -func (p Partition) Resolver() *Resolver { - return &Resolver{ - partitions: partitions{*p.p}, - } -} - -// A Region provides information about a region, and ability to resolve an -// endpoint from the context of a region, given a service. -type Region struct { - id, desc string - p *partition -} - -// ID returns the region's identifier. -func (r Region) ID() string { return r.id } - -// Endpoint resolves an endpoint from the context of the region given -// a service. See Partition.EndpointFor for usage and errors that can be returned. -func (r Region) Endpoint(service string, opts ResolveOptions) (aws.Endpoint, error) { - return r.p.EndpointFor(service, r.id, opts) -} - -// Services returns a list of all services that are known to be in this region. -func (r Region) Services() map[string]Service { - ss := map[string]Service{} - for id, s := range r.p.Services { - if _, ok := s.Endpoints[r.id]; ok { - ss[id] = Service{ - id: id, - p: r.p, - } - } - } - - return ss -} - -// A Service provides information about a service, and ability to resolve an -// endpoint from the context of a service, given a region. -type Service struct { - id string - p *partition -} - -// ID returns the identifier for the service. -func (s Service) ID() string { return s.id } - -// Endpoint resolves an endpoint from the context of a service given -// a region. See Partition.EndpointFor for usage and errors that can be returned. -func (s Service) Endpoint(region string, opts ResolveOptions) (aws.Endpoint, error) { - return s.p.EndpointFor(s.id, region, opts) -} - -// Regions returns a map of Regions that the service is present in. -// -// A region is the AWS region the service exists in. Whereas a Endpoint is -// an URL that can be resolved to a instance of a service. -func (s Service) Regions() map[string]Region { - rs := map[string]Region{} - for id := range s.p.Services[s.id].Endpoints { - if _, ok := s.p.Regions[id]; ok { - rs[id] = Region{ - id: id, - p: s.p, - } - } - } - - return rs -} - -// Endpoints returns a map of Endpoints indexed by their ID for all known -// endpoints for a service. -// -// A region is the AWS region the service exists in. Whereas a Endpoint is -// an URL that can be resolved to a instance of a service. -func (s Service) Endpoints() map[string]Endpoint { - es := map[string]Endpoint{} - for id := range s.p.Services[s.id].Endpoints { - es[id] = Endpoint{ - id: id, - serviceID: s.id, - p: s.p, - } - } - - return es -} - -// A Endpoint provides information about endpoints, and provides the ability -// to resolve that endpoint for the service, and the region the endpoint -// represents. -type Endpoint struct { - id string - serviceID string - p *partition -} - -// ID returns the identifier for an endpoint. -func (e Endpoint) ID() string { return e.id } - -// ServiceID returns the identifier the endpoint belongs to. -func (e Endpoint) ServiceID() string { return e.serviceID } - -// Resolve resolves an endpoint from the context of a service and -// region the endpoint represents. See Partition.EndpointFor for usage and -// errors that can be returned. -func (e Endpoint) Resolve(opts ResolveOptions) (aws.Endpoint, error) { - return e.p.EndpointFor(e.serviceID, e.id, opts) -} - -// A UnknownServiceError is returned when the service does not resolve to an -// endpoint. Includes a list of all known services for the partition. Returned -// when a partition does not support the service. -type UnknownServiceError struct { - Partition string - Service string - Known []string -} - -// NewUnknownServiceError builds and returns UnknownServiceError. -func NewUnknownServiceError(p, s string, known []string) UnknownServiceError { - return UnknownServiceError{ - Partition: p, - Service: s, - Known: known, - } -} - -// String returns the string representation of the error. -func (e UnknownServiceError) Error() string { - extra := fmt.Sprintf("partition: %q, service: %q", e.Partition, e.Service) - if len(e.Known) > 0 { - extra += fmt.Sprintf(", known: %v", e.Known) - } - return "unknown service, could not resolve endpoint, " + extra -} - -// A UnknownEndpointError is returned when in StrictMatching mode and the -// service is valid, but the region does not resolve to an endpoint. Includes -// a list of all known endpoints for the service. -type UnknownEndpointError struct { - Partition string - Service string - Region string - Known []string -} - -// NewUnknownEndpointError builds and returns UnknownEndpointError. -func NewUnknownEndpointError(p, s, r string, known []string) UnknownEndpointError { - return UnknownEndpointError{ - Partition: p, - Service: s, - Region: r, - Known: known, - } -} - -// String returns the string representation of the error. -func (e UnknownEndpointError) Error() string { - extra := fmt.Sprintf("partition: %q, service: %q, region: %q", - e.Partition, e.Service, e.Region) - if len(e.Known) > 0 { - extra += fmt.Sprintf(", known: %v", e.Known) - } - return "unknown endpoint, could not resolve endpoint, " + extra -} diff --git a/aws/endpoints/endpoints_test.go b/aws/endpoints/endpoints_test.go deleted file mode 100644 index 3333a3459c3..00000000000 --- a/aws/endpoints/endpoints_test.go +++ /dev/null @@ -1,258 +0,0 @@ -package endpoints - -import "testing" - -func TestDefaultResolver_Partitions(t *testing.T) { - resolver := NewDefaultResolver() - ps := resolver.Partitions() - - if a, e := len(ps), len(defaultPartitions); a != e { - t.Errorf("expected %d partitions, got %d", e, a) - } -} - -func TestEnumDefaultRegions(t *testing.T) { - expectPart := defaultPartitions[0] - partEnum := defaultPartitions[0].Partition() - - regEnum := partEnum.Regions() - - if a, e := len(regEnum), len(expectPart.Regions); a != e { - t.Errorf("expected %d regions, got %d", e, a) - } -} - -func TestEnumPartitionServices(t *testing.T) { - expectPart := testPartitions[0] - partEnum := testPartitions[0].Partition() - - if a, e := partEnum.ID(), "part-id"; a != e { - t.Errorf("expect %q partition ID, got %q", e, a) - } - - svcEnum := partEnum.Services() - - if a, e := len(svcEnum), len(expectPart.Services); a != e { - t.Errorf("expected %d regions, got %d", e, a) - } -} - -func TestEnumRegionServices(t *testing.T) { - p := testPartitions[0].Partition() - - rs := p.Regions() - - if a, e := len(rs), 2; a != e { - t.Errorf("expect %d regions got %d", e, a) - } - - if _, ok := rs["us-east-1"]; !ok { - t.Errorf("expect us-east-1 region to be found, was not") - } - if _, ok := rs["us-west-2"]; !ok { - t.Errorf("expect us-west-2 region to be found, was not") - } - - r := rs["us-east-1"] - - if a, e := r.ID(), "us-east-1"; a != e { - t.Errorf("expect %q region ID, got %q", e, a) - } - - ss := r.Services() - if a, e := len(ss), 1; a != e { - t.Errorf("expect %d services for us-east-1, got %d", e, a) - } - - if _, ok := ss["service1"]; !ok { - t.Errorf("expect service1 service to be found, was not") - } - - resolved, err := r.Endpoint("service1", ResolveOptions{}) - if err != nil { - t.Fatalf("expect no error, got %v", err) - } - - if a, e := resolved.URL, "https://service1.us-east-1.amazonaws.com"; a != e { - t.Errorf("expect %q resolved URL, got %q", e, a) - } -} - -func TestEnumServiceRegions(t *testing.T) { - p := testPartitions[0].Partition() - - rs := p.Services()["service1"].Regions() - if e, a := 2, len(rs); e != a { - t.Errorf("expect %d regions, got %d", e, a) - } - - if _, ok := rs["us-east-1"]; !ok { - t.Errorf("expect region to be found") - } - if _, ok := rs["us-west-2"]; !ok { - t.Errorf("expect region to be found") - } -} - -func TestEnumServicesEndpoints(t *testing.T) { - p := testPartitions[0].Partition() - - ss := p.Services() - - if a, e := len(ss), 5; a != e { - t.Errorf("expect %d regions got %d", e, a) - } - - if _, ok := ss["service1"]; !ok { - t.Errorf("expect service1 region to be found, was not") - } - if _, ok := ss["service2"]; !ok { - t.Errorf("expect service2 region to be found, was not") - } - - s := ss["service1"] - if a, e := s.ID(), "service1"; a != e { - t.Errorf("expect %q service ID, got %q", e, a) - } - - resolved, err := s.Endpoint("us-west-2", ResolveOptions{}) - if err != nil { - t.Fatalf("expect no error, got %v", err) - } - - if a, e := resolved.URL, "https://service1.us-west-2.amazonaws.com"; a != e { - t.Errorf("expect %q resolved URL, got %q", e, a) - } -} - -func TestEnumEndpoints(t *testing.T) { - p := testPartitions[0].Partition() - s := p.Services()["service1"] - - es := s.Endpoints() - if a, e := len(es), 2; a != e { - t.Errorf("expect %d endpoints for service2, got %d", e, a) - } - if _, ok := es["us-east-1"]; !ok { - t.Errorf("expect us-east-1 to be found, was not") - } - - e := es["us-east-1"] - if a, e := e.ID(), "us-east-1"; a != e { - t.Errorf("expect %q endpoint ID, got %q", e, a) - } - if a, e := e.ServiceID(), "service1"; a != e { - t.Errorf("expect %q service ID, got %q", e, a) - } - - resolved, err := e.Resolve(ResolveOptions{}) - if err != nil { - t.Fatalf("expect no error, got %v", err) - } - - if a, e := resolved.URL, "https://service1.us-east-1.amazonaws.com"; a != e { - t.Errorf("expect %q resolved URL, got %q", e, a) - } -} - -func TestResolveEndpointForPartition(t *testing.T) { - p := testPartitions.Partitions()[0] - - expected, err := testPartitions.EndpointFor("service1", "us-east-1", ResolveOptions{}) - - actual, err := p.Endpoint("service1", "us-east-1", ResolveOptions{}) - if err != nil { - t.Fatalf("unexpected error, %v", err) - } - - if expected != actual { - t.Errorf("expect resolved endpoint to be %v, but got %v", expected, actual) - } -} - -func TestPartition_RegionsForService(t *testing.T) { - ps := DefaultPartitions() - - var expect map[string]Region - var serviceID string - for _, s := range ps[0].Services() { - expect = s.Regions() - serviceID = s.ID() - if len(expect) > 0 { - break - } - } - - p, ok := ps.ForPartition(ps[0].ID()) - if !ok { - t.Fatalf("expect partition to exist") - } - - actual, ok := p.RegionsForService(serviceID) - if !ok { - t.Fatalf("expect service to exist") - } - if len(actual) == 0 { - t.Fatalf("expect service %s to have regions", serviceID) - } - if e, a := len(expect), len(actual); e != a { - t.Fatalf("expect %d regions, got %d", e, a) - } - - for id, r := range actual { - if e, a := id, r.ID(); e != a { - t.Errorf("expect %s region id, got %s", e, a) - } - if _, ok := expect[id]; !ok { - t.Errorf("expect %s region to be found", id) - } - } -} - -func TestRegionsForService_NotFound(t *testing.T) { - ps := testPartitions.Partitions() - - p, ok := ps.ForPartition(ps[0].ID()) - if !ok { - t.Fatalf("expect partition to exist") - } - - actual, ok := p.RegionsForService("service-not-exists") - if ok { - t.Fatalf("expect service to not exist") - } - if len(actual) != 0 { - t.Errorf("expect no regions, got %v", actual) - } -} - -func TestPartitionForRegion(t *testing.T) { - ps := DefaultPartitions() - expect := ps[len(ps)%2] - - var regionID string - for id := range expect.Regions() { - regionID = id - break - } - - actual, ok := ps.ForRegion(regionID) - if !ok { - t.Fatalf("expect partition to be found") - } - if e, a := expect.DNSSuffix(), actual.DNSSuffix(); e != a { - t.Errorf("expect %s partition DNSSuffix, got %s", e, a) - } - if e, a := expect.ID(), actual.ID(); e != a { - t.Errorf("expect %s partition ID, got %s", e, a) - } -} - -func TestPartitionForRegion_NotFound(t *testing.T) { - ps := DefaultPartitions() - - actual, ok := ps.ForRegion("regionNotExists") - if ok { - t.Errorf("expect no partition to be found, got %v", actual) - } -} diff --git a/aws/endpoints/example_test.go b/aws/endpoints/example_test.go deleted file mode 100644 index 8ecb18ef0cb..00000000000 --- a/aws/endpoints/example_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package endpoints_test - -import ( - "fmt" - - "github.com/aws/aws-sdk-go-v2/aws/endpoints" -) - -func ExampleResolver_Partitions() { - partitions := endpoints.NewDefaultResolver().Partitions() - - for _, p := range partitions { - fmt.Println("Regions for", p.ID()) - for id := range p.Regions() { - fmt.Println("*", id) - } - - fmt.Println("Services for", p.ID()) - for id := range p.Services() { - fmt.Println("*", id) - } - } -} diff --git a/aws/endpoints/resolver.go b/aws/endpoints/resolver.go new file mode 100644 index 00000000000..4e562713540 --- /dev/null +++ b/aws/endpoints/resolver.go @@ -0,0 +1,102 @@ +package endpoints + +import ( + "fmt" + + "github.com/aws/aws-sdk-go-v2/aws" +) + +// ResolveOptions provide the configuration needed to direct how the +// endpoints will be resolved. +type ResolveOptions struct { + // DisableSSL forces the endpoint to be resolved as HTTP. + // instead of HTTPS if the service supports it. + DisableSSL bool + + // Sets the resolver to resolve the endpoint as a dualstack endpoint + // for the service. If dualstack support for a service is not known and + // StrictMatching is not enabled a dualstack endpoint for the service will + // be returned. This endpoint may not be valid. If StrictMatching is + // enabled only services that are known to support dualstack will return + // dualstack endpoints. + UseDualStack bool + + // Enables strict matching of services and regions resolved endpoints. + // If the partition doesn't enumerate the exact service and region an + // error will be returned. This option will prevent returning endpoints + // that look valid, but may not resolve to any real endpoint. + StrictMatching bool +} + +// A Resolver provides endpoint resolution based on modeled endpoint data. +type Resolver struct { + ResolveOptions + + partitions partitions +} + +// ResolveEndpoint attempts to resolve an endpoint againsted the modeled endpoint +// data. If an endpoint is found it will be returned. An error will be returned +// otherwise. +// +// Searches through the partitions in the order they are defined. +func (r *Resolver) ResolveEndpoint(service, region string) (aws.Endpoint, error) { + return r.partitions.EndpointFor(service, region, r.ResolveOptions) +} + +// A UnknownServiceError is returned when the service does not resolve to an +// endpoint. Includes a list of all known services for the partition. Returned +// when a partition does not support the service. +type UnknownServiceError struct { + Partition string + Service string + Known []string +} + +// NewUnknownServiceError builds and returns UnknownServiceError. +func NewUnknownServiceError(p, s string, known []string) UnknownServiceError { + return UnknownServiceError{ + Partition: p, + Service: s, + Known: known, + } +} + +// String returns the string representation of the error. +func (e UnknownServiceError) Error() string { + extra := fmt.Sprintf("partition: %q, service: %q", e.Partition, e.Service) + if len(e.Known) > 0 { + extra += fmt.Sprintf(", known: %v", e.Known) + } + return "unknown service, could not resolve endpoint, " + extra +} + +// A UnknownEndpointError is returned when in StrictMatching mode and the +// service is valid, but the region does not resolve to an endpoint. Includes +// a list of all known endpoints for the service. +type UnknownEndpointError struct { + Partition string + Service string + Region string + Known []string +} + +// NewUnknownEndpointError builds and returns UnknownEndpointError. +func NewUnknownEndpointError(p, s, r string, known []string) UnknownEndpointError { + return UnknownEndpointError{ + Partition: p, + Service: s, + Region: r, + Known: known, + } +} + +// String returns the string representation of the error. +func (e UnknownEndpointError) Error() string { + extra := fmt.Sprintf("partition: %q, service: %q, region: %q", + e.Partition, e.Service, e.Region) + if len(e.Known) > 0 { + extra += fmt.Sprintf(", known: %v", e.Known) + } + return "unknown endpoint, could not resolve endpoint, " + extra +} diff --git a/aws/endpoints/v3model.go b/aws/endpoints/v3model.go index ce27fa804bd..6c2e0b15d29 100644 --- a/aws/endpoints/v3model.go +++ b/aws/endpoints/v3model.go @@ -29,18 +29,6 @@ func (ps partitions) EndpointFor(service, region string, opts ResolveOptions) (a return aws.Endpoint{}, NewUnknownEndpointError("all partitions", service, region, []string{}) } -// Partitions satisfies the EnumPartitions interface and returns a list -// of Partitions representing each partition represented in the SDK's -// endpoints model. -func (ps partitions) Partitions() Partitions { - parts := make(Partitions, 0, len(ps)) - for i := 0; i < len(ps); i++ { - parts = append(parts, ps[i].Partition()) - } - - return parts -} - type partition struct { ID string `json:"partition"` Name string `json:"partitionName"` @@ -51,14 +39,6 @@ type partition struct { Services services `json:"services"` } -func (p partition) Partition() Partition { - return Partition{ - dnsSuffix: p.DNSSuffix, - id: p.ID, - p: &p, - } -} - func (p partition) canResolveEndpoint(service, region string, strictMatch bool) bool { s, hasService := p.Services[service] _, hasEndpoint := s.Endpoints[region] @@ -304,7 +284,8 @@ type credentialScope struct { Service string `json:"service"` } -type boxedBool int +// boxedBool is an aws.Ternary alias that allows for unmarshalling bool values from a JSON string +type boxedBool aws.Ternary func (b *boxedBool) UnmarshalJSON(buf []byte) error { v, err := strconv.ParseBool(string(buf)) @@ -322,7 +303,7 @@ func (b *boxedBool) UnmarshalJSON(buf []byte) error { } const ( - boxedBoolUnset boxedBool = iota - boxedFalse - boxedTrue + boxedBoolUnset = boxedBool(aws.UnknownTernary) + boxedFalse = boxedBool(aws.FalseTernary) + boxedTrue = boxedBool(aws.TrueTernary) ) diff --git a/aws/endpoints/v3model_codegen.go b/aws/endpoints/v3model_codegen.go index 9ea0a1511e3..8de5e5a27ae 100644 --- a/aws/endpoints/v3model_codegen.go +++ b/aws/endpoints/v3model_codegen.go @@ -166,55 +166,14 @@ import ( "regexp" ) - {{ template "partition consts" . }} - - {{ range $_, $partition := . }} - {{ template "partition region consts" $partition }} - {{ end }} - - {{ template "endpoint resolvers" . }} -{{- end }} - -{{ define "partition consts" }} - // Partition identifiers - const ( - {{ range $_, $p := . -}} - {{ ToSymbol $p.ID }}PartitionID = {{ QuoteString $p.ID }} // {{ $p.Name }} partition. - {{ end -}} - ) -{{- end }} - -{{ define "partition region consts" }} - // {{ .Name }} partition's regions. - const ( - {{ range $id, $region := .Regions -}} - {{ ToSymbol $id }}RegionID = {{ QuoteString $id }} // {{ $region.Description }}. - {{ end -}} - ) -{{- end }} - -{{ define "endpoint resolvers" }} // NewDefaultResolver returns an Endpoint resolver that will be able // to resolve endpoints for: {{ ListPartitionNames . }}. - // - // Use DefaultPartitions() to get the list of the default partitions. func NewDefaultResolver() *Resolver { return &Resolver{ partitions: defaultPartitions, } } - // DefaultPartitions returns a list of the partitions the SDK is bundled - // with. The available partitions are: {{ ListPartitionNames . }}. - // - // partitions := endpoints.DefaultPartitions - // for _, p := range partitions { - // // ... inspect partitions - // } - func DefaultPartitions() Partitions { - return defaultPartitions.Partitions() - } - var defaultPartitions = partitions{ {{ range $_, $partition := . -}} {{ PartitionVarName $partition.ID }}, @@ -222,14 +181,10 @@ import ( } {{ range $_, $partition := . -}} - {{ $name := PartitionGetter $partition.ID -}} - // {{ $name }} returns the Resolver for {{ $partition.Name }}. - func {{ $name }}() Partition { - return {{ PartitionVarName $partition.ID }}.Partition() - } var {{ PartitionVarName $partition.ID }} = {{ template "gocode Partition" $partition }} {{ end }} -{{ end }} + +{{- end }} {{ define "gocode Partition" -}} partition{ diff --git a/aws/example_test.go b/aws/example_test.go index 2b86e881878..c82442e873a 100644 --- a/aws/example_test.go +++ b/aws/example_test.go @@ -25,7 +25,7 @@ func ExampleEndpointResolverFunc() { } cfg := defaults.Config() - cfg.Region = endpoints.UsWest2RegionID + cfg.Region = "us-west-2" cfg.EndpointResolver = aws.EndpointResolverFunc(myCustomResolver) // Create the S3 service client with the shared config. This will diff --git a/example/aws/endpoints/enumEndpoints/README.md b/example/aws/endpoints/enumEndpoints/README.md deleted file mode 100644 index 4f8744c6860..00000000000 --- a/example/aws/endpoints/enumEndpoints/README.md +++ /dev/null @@ -1,37 +0,0 @@ -Enumerate Regions and Endpoints Example -=== - -Demonstrates how the SDK's endpoints can be enumerated over to discover regions, services, and endpoints defined by the SDK's Regions and Endpoints metadata. - -Usage ---- - -The following parameters can be used to enumerate the SDK's partition metadata. - -Example: - - go run -tags example enumEndpoints.go -p aws -services -r us-west-2 - -Output: - - Services with endpoint us-west-2 in aws: - ec2 - dynamodb - s3 - ... - -CLI parameters ---- - -``` - -p=id partition id, e.g: aws - -r=id region id, e.g: us-west-2 - -s=id service id, e.g: s3 - - -partitions Lists all partitions. - -regions Lists all regions in a partition. Requires partition ID. - If service ID is also provided will show endpoints for a service. - -services Lists all services in a partition. Requires partition ID. - If region ID is also provided, will show services available in that region. -``` - diff --git a/example/aws/endpoints/enumEndpoints/enumEndpoints.go b/example/aws/endpoints/enumEndpoints/enumEndpoints.go deleted file mode 100644 index c7759844279..00000000000 --- a/example/aws/endpoints/enumEndpoints/enumEndpoints.go +++ /dev/null @@ -1,126 +0,0 @@ -// +build example - -package main - -import ( - "flag" - "fmt" - "os" - - "github.com/aws/aws-sdk-go-v2/aws/endpoints" -) - -// Demostrates how the SDK's endpoints can be enumerated over to discover -// regions, services, and endpoints defined by the SDK's Regions and Endpoints -// metadata. -// -// Usage: -// -p=id partition id, e.g: aws -// -r=id region id, e.g: us-west-2 -// -s=id service id, e.g: s3 -// -// -partitions Lists all partitions. -// -regions Lists all regions in a partition. Requires partition ID. -// If service ID is also provided will show endpoints for a service. -// -services Lists all services in a partition. Requires partition ID. -// If region ID is also provided, will show services available in that region. -// -// Example: -// go run enumEndpoints.go -p aws -services -r us-west-2 -// -// Output: -// Services with endpoint us-west-2 in aws: -// ... -func main() { - var partitionID, regionID, serviceID string - flag.StringVar(&partitionID, "p", "", "Partition ID") - flag.StringVar(®ionID, "r", "", "Region ID") - flag.StringVar(&serviceID, "s", "", "Service ID") - - var cmdPartitions, cmdRegions, cmdServices bool - flag.BoolVar(&cmdPartitions, "partitions", false, "Lists partitions.") - flag.BoolVar(&cmdRegions, "regions", false, "Lists regions of a partition. Requires partition ID to be provided. Will filter by a service if '-s' is set.") - flag.BoolVar(&cmdServices, "services", false, "Lists services for a partition. Requires partition ID to be provided. Will filter by a region if '-r' is set.") - flag.Parse() - - partitions := endpoints.NewDefaultResolver().Partitions() - - if cmdPartitions { - printPartitions(partitions) - } - - if !(cmdRegions || cmdServices) { - return - } - - p, ok := findPartition(partitions, partitionID) - if !ok { - fmt.Fprintf(os.Stderr, "Partition %q not found", partitionID) - os.Exit(1) - } - - if cmdRegions { - printRegions(p, serviceID) - } - - if cmdServices { - printServices(p, regionID) - } -} - -func printPartitions(ps []endpoints.Partition) { - fmt.Println("Partitions:") - for _, p := range ps { - fmt.Println(p.ID()) - } -} - -func printRegions(p endpoints.Partition, serviceID string) { - if len(serviceID) != 0 { - s, ok := p.Services()[serviceID] - if !ok { - fmt.Fprintf(os.Stderr, "service %q does not exist in partition %q", serviceID, p.ID()) - os.Exit(1) - } - es := s.Endpoints() - fmt.Printf("Endpoints for %s in %s:\n", serviceID, p.ID()) - for _, e := range es { - r, _ := e.Resolve(endpoints.ResolveOptions{}) - fmt.Printf("%s: %s\n", e.ID(), r.URL) - } - - } else { - rs := p.Regions() - fmt.Printf("Regions in %s:\n", p.ID()) - for _, r := range rs { - fmt.Println(r.ID()) - } - } -} - -func printServices(p endpoints.Partition, endpointID string) { - ss := p.Services() - - if len(endpointID) > 0 { - fmt.Printf("Services with endpoint %s in %s:\n", endpointID, p.ID()) - } else { - fmt.Printf("Services in %s:\n", p.ID()) - } - - for id, s := range ss { - if _, ok := s.Endpoints()[endpointID]; !ok && len(endpointID) > 0 { - continue - } - fmt.Println(id) - } -} - -func findPartition(ps []endpoints.Partition, partitionID string) (endpoints.Partition, bool) { - for _, p := range ps { - if p.ID() == partitionID { - return p, true - } - } - - return endpoints.Partition{}, false -} diff --git a/example/service/s3/presignURL/server/server.go b/example/service/s3/presignURL/server/server.go index ffec4966cb9..b54b0afad77 100644 --- a/example/service/s3/presignURL/server/server.go +++ b/example/service/s3/presignURL/server/server.go @@ -15,7 +15,6 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/endpoints" "github.com/aws/aws-sdk-go-v2/aws/external" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/s3iface" @@ -54,7 +53,7 @@ func main() { // to look in those partitions instead of AWS. if len(region) == 0 { var err error - region, err = s3manager.GetBucketRegion(context.Background(), cfg, bucket, endpoints.UsWest2RegionID) + region, err = s3manager.GetBucketRegion(context.Background(), cfg, bucket, "us-west-2") if err != nil { exitErrorf("failed to get bucket region, %v", err) } diff --git a/internal/awstesting/cmd/op_crawler/codegen/codegen.go b/internal/awstesting/cmd/op_crawler/codegen/codegen.go deleted file mode 100644 index 1555ac0e16c..00000000000 --- a/internal/awstesting/cmd/op_crawler/codegen/codegen.go +++ /dev/null @@ -1,147 +0,0 @@ -// +build codegen - -package main - -import ( - "bytes" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "text/template" -) - -var tplCreateServiceCase = template.Must(template.New("create-serviice").Funcs(template.FuncMap{ - "ServiceImport": serviceImport, -}).Parse(` -// Code generated by internal/awstesting/cmd/op_crawler/generate.go. DO NOT EDIT. -// +build sdktool - -package main - -import ( - "reflect" - - "github.com/aws/aws-sdk-go-v2/aws" - {{ range $_, $service := $.Packages -}} - {{ ServiceImport $service }} - {{- end }} -) - -type service struct { - name string - value reflect.Value -} - -func createServices(cfg aws.Config) []service { - {{ range $_, $service := $.Packages -}} - {{ $.CustomConfiguration $service }} - {{- end }} - - return []service{ - {{ range $_, $service := $.Packages -}} - {{ $.ServiceClient $service }} - {{- end }} - } -} - -`)) - -const ( - sdkPath = "github.com/aws/aws-sdk-go-v2/service" -) - -type serviceInfo struct { - clientNames map[string]string - basePath string - Packages []string -} - -// getServices will crawl the basepath and any folder found will be assumed -// to be a service and stored in the serviceInfo -func (si *serviceInfo) getServices() { - filepath.Walk(si.basePath, func(path string, info os.FileInfo, err error) error { - if filepath.Dir(path) != si.basePath { - return nil - } - if !info.IsDir() { - return nil - } - - serviceName := info.Name() - si.Packages = append(si.Packages, serviceName) - return nil - }) -} - -// serviceImport will create the proper import path for the given service package -func serviceImport(p string) string { - return fmt.Sprintf("%q\n", filepath.Join(sdkPath, p)) -} - -type customConfig interface { - GoCode(*serviceInfo) string -} - -var customConfigs = map[string]customConfig{ - "s3": s3CustomConfig{}, - "sqs": sqsCustomConfig{}, -} - -type s3CustomConfig struct{} - -func (config s3CustomConfig) GoCode(si *serviceInfo) string { - si.clientNames["s3"] = "s3Client" - buf := bytes.NewBuffer(nil) - buf.WriteString("s3Client := s3.New(cfg)\n") - buf.WriteString("s3Client.ForcePathStyle = true\n") - return buf.String() -} - -type sqsCustomConfig struct{} - -func (config sqsCustomConfig) GoCode(si *serviceInfo) string { - si.clientNames["sqs"] = "sqsClient" - buf := bytes.NewBuffer(nil) - buf.WriteString("sqsClient := sqs.New(cfg)\n") - buf.WriteString("sqsClient.DisableComputeChecksums = true\n") - return buf.String() -} - -// CustomConfigurations is used to setup any custom configuration on a given -// service client -func (si *serviceInfo) CustomConfiguration(p string) string { - if c, ok := customConfigs[p]; ok { - return c.GoCode(si) - } - - return "" -} - -// Services will construct each service as a reflect.Value and its name. -func (si *serviceInfo) ServiceClient(p string) string { - if name, ok := si.clientNames[p]; ok { - return fmt.Sprintf("{name: %q, value: reflect.ValueOf(%s)},\n", p, name) - } - - return fmt.Sprintf("{name: %q, value: reflect.ValueOf(%s.New(cfg))},\n", p, p) -} - -func main() { - si := &serviceInfo{ - clientNames: map[string]string{}, - basePath: os.Args[1], - Packages: []string{}, - } - - si.getServices() - - var buf bytes.Buffer - if err := tplCreateServiceCase.Execute(&buf, si); err != nil { - panic(err) - } - - if err := ioutil.WriteFile("./create_service.go", buf.Bytes(), 0644); err != nil { - panic(err) - } -} diff --git a/internal/awstesting/cmd/op_crawler/create_service.go b/internal/awstesting/cmd/op_crawler/create_service.go deleted file mode 100644 index b0b5745e9f5..00000000000 --- a/internal/awstesting/cmd/op_crawler/create_service.go +++ /dev/null @@ -1,463 +0,0 @@ -// Code generated by internal/awstesting/cmd/op_crawler/generate.go. DO NOT EDIT. -// +build sdktool - -package main - -import ( - "reflect" - - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/accessanalyzer" - "github.com/aws/aws-sdk-go-v2/service/acm" - "github.com/aws/aws-sdk-go-v2/service/acmpca" - "github.com/aws/aws-sdk-go-v2/service/alexaforbusiness" - "github.com/aws/aws-sdk-go-v2/service/amplify" - "github.com/aws/aws-sdk-go-v2/service/apigateway" - "github.com/aws/aws-sdk-go-v2/service/apigatewaymanagementapi" - "github.com/aws/aws-sdk-go-v2/service/apigatewayv2" - "github.com/aws/aws-sdk-go-v2/service/appconfig" - "github.com/aws/aws-sdk-go-v2/service/applicationautoscaling" - "github.com/aws/aws-sdk-go-v2/service/applicationdiscoveryservice" - "github.com/aws/aws-sdk-go-v2/service/applicationinsights" - "github.com/aws/aws-sdk-go-v2/service/appmesh" - "github.com/aws/aws-sdk-go-v2/service/appstream" - "github.com/aws/aws-sdk-go-v2/service/appsync" - "github.com/aws/aws-sdk-go-v2/service/athena" - "github.com/aws/aws-sdk-go-v2/service/autoscaling" - "github.com/aws/aws-sdk-go-v2/service/autoscalingplans" - "github.com/aws/aws-sdk-go-v2/service/backup" - "github.com/aws/aws-sdk-go-v2/service/batch" - "github.com/aws/aws-sdk-go-v2/service/budgets" - "github.com/aws/aws-sdk-go-v2/service/chime" - "github.com/aws/aws-sdk-go-v2/service/cloud9" - "github.com/aws/aws-sdk-go-v2/service/clouddirectory" - "github.com/aws/aws-sdk-go-v2/service/cloudformation" - "github.com/aws/aws-sdk-go-v2/service/cloudfront" - "github.com/aws/aws-sdk-go-v2/service/cloudhsm" - "github.com/aws/aws-sdk-go-v2/service/cloudhsmv2" - "github.com/aws/aws-sdk-go-v2/service/cloudsearch" - "github.com/aws/aws-sdk-go-v2/service/cloudsearchdomain" - "github.com/aws/aws-sdk-go-v2/service/cloudtrail" - "github.com/aws/aws-sdk-go-v2/service/cloudwatch" - "github.com/aws/aws-sdk-go-v2/service/cloudwatchevents" - "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs" - "github.com/aws/aws-sdk-go-v2/service/codebuild" - "github.com/aws/aws-sdk-go-v2/service/codecommit" - "github.com/aws/aws-sdk-go-v2/service/codedeploy" - "github.com/aws/aws-sdk-go-v2/service/codeguruprofiler" - "github.com/aws/aws-sdk-go-v2/service/codegurureviewer" - "github.com/aws/aws-sdk-go-v2/service/codepipeline" - "github.com/aws/aws-sdk-go-v2/service/codestar" - "github.com/aws/aws-sdk-go-v2/service/codestarconnections" - "github.com/aws/aws-sdk-go-v2/service/codestarnotifications" - "github.com/aws/aws-sdk-go-v2/service/cognitoidentity" - "github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider" - "github.com/aws/aws-sdk-go-v2/service/cognitosync" - "github.com/aws/aws-sdk-go-v2/service/comprehend" - "github.com/aws/aws-sdk-go-v2/service/comprehendmedical" - "github.com/aws/aws-sdk-go-v2/service/computeoptimizer" - "github.com/aws/aws-sdk-go-v2/service/configservice" - "github.com/aws/aws-sdk-go-v2/service/connect" - "github.com/aws/aws-sdk-go-v2/service/connectparticipant" - "github.com/aws/aws-sdk-go-v2/service/costandusagereportservice" - "github.com/aws/aws-sdk-go-v2/service/costexplorer" - "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice" - "github.com/aws/aws-sdk-go-v2/service/dataexchange" - "github.com/aws/aws-sdk-go-v2/service/datapipeline" - "github.com/aws/aws-sdk-go-v2/service/datasync" - "github.com/aws/aws-sdk-go-v2/service/dax" - "github.com/aws/aws-sdk-go-v2/service/detective" - "github.com/aws/aws-sdk-go-v2/service/devicefarm" - "github.com/aws/aws-sdk-go-v2/service/directconnect" - "github.com/aws/aws-sdk-go-v2/service/directoryservice" - "github.com/aws/aws-sdk-go-v2/service/dlm" - "github.com/aws/aws-sdk-go-v2/service/docdb" - "github.com/aws/aws-sdk-go-v2/service/dynamodb" - "github.com/aws/aws-sdk-go-v2/service/dynamodbstreams" - "github.com/aws/aws-sdk-go-v2/service/ebs" - "github.com/aws/aws-sdk-go-v2/service/ec2" - "github.com/aws/aws-sdk-go-v2/service/ec2instanceconnect" - "github.com/aws/aws-sdk-go-v2/service/ecr" - "github.com/aws/aws-sdk-go-v2/service/ecs" - "github.com/aws/aws-sdk-go-v2/service/efs" - "github.com/aws/aws-sdk-go-v2/service/eks" - "github.com/aws/aws-sdk-go-v2/service/elasticache" - "github.com/aws/aws-sdk-go-v2/service/elasticbeanstalk" - "github.com/aws/aws-sdk-go-v2/service/elasticinference" - "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" - "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" - "github.com/aws/aws-sdk-go-v2/service/elasticsearchservice" - "github.com/aws/aws-sdk-go-v2/service/elastictranscoder" - "github.com/aws/aws-sdk-go-v2/service/emr" - "github.com/aws/aws-sdk-go-v2/service/eventbridge" - "github.com/aws/aws-sdk-go-v2/service/firehose" - "github.com/aws/aws-sdk-go-v2/service/fms" - "github.com/aws/aws-sdk-go-v2/service/forecast" - "github.com/aws/aws-sdk-go-v2/service/forecastquery" - "github.com/aws/aws-sdk-go-v2/service/frauddetector" - "github.com/aws/aws-sdk-go-v2/service/fsx" - "github.com/aws/aws-sdk-go-v2/service/gamelift" - "github.com/aws/aws-sdk-go-v2/service/glacier" - "github.com/aws/aws-sdk-go-v2/service/globalaccelerator" - "github.com/aws/aws-sdk-go-v2/service/glue" - "github.com/aws/aws-sdk-go-v2/service/greengrass" - "github.com/aws/aws-sdk-go-v2/service/groundstation" - "github.com/aws/aws-sdk-go-v2/service/guardduty" - "github.com/aws/aws-sdk-go-v2/service/health" - "github.com/aws/aws-sdk-go-v2/service/iam" - "github.com/aws/aws-sdk-go-v2/service/imagebuilder" - "github.com/aws/aws-sdk-go-v2/service/inspector" - "github.com/aws/aws-sdk-go-v2/service/iot" - "github.com/aws/aws-sdk-go-v2/service/iot1clickdevicesservice" - "github.com/aws/aws-sdk-go-v2/service/iot1clickprojects" - "github.com/aws/aws-sdk-go-v2/service/iotanalytics" - "github.com/aws/aws-sdk-go-v2/service/iotdataplane" - "github.com/aws/aws-sdk-go-v2/service/iotevents" - "github.com/aws/aws-sdk-go-v2/service/ioteventsdata" - "github.com/aws/aws-sdk-go-v2/service/iotjobsdataplane" - "github.com/aws/aws-sdk-go-v2/service/iotsecuretunneling" - "github.com/aws/aws-sdk-go-v2/service/iotthingsgraph" - "github.com/aws/aws-sdk-go-v2/service/kafka" - "github.com/aws/aws-sdk-go-v2/service/kendra" - "github.com/aws/aws-sdk-go-v2/service/kinesis" - "github.com/aws/aws-sdk-go-v2/service/kinesisanalytics" - "github.com/aws/aws-sdk-go-v2/service/kinesisanalyticsv2" - "github.com/aws/aws-sdk-go-v2/service/kinesisvideo" - "github.com/aws/aws-sdk-go-v2/service/kinesisvideoarchivedmedia" - "github.com/aws/aws-sdk-go-v2/service/kinesisvideomedia" - "github.com/aws/aws-sdk-go-v2/service/kinesisvideosignaling" - "github.com/aws/aws-sdk-go-v2/service/kms" - "github.com/aws/aws-sdk-go-v2/service/lakeformation" - "github.com/aws/aws-sdk-go-v2/service/lambda" - "github.com/aws/aws-sdk-go-v2/service/lexmodelbuildingservice" - "github.com/aws/aws-sdk-go-v2/service/lexruntimeservice" - "github.com/aws/aws-sdk-go-v2/service/licensemanager" - "github.com/aws/aws-sdk-go-v2/service/lightsail" - "github.com/aws/aws-sdk-go-v2/service/machinelearning" - "github.com/aws/aws-sdk-go-v2/service/macie" - "github.com/aws/aws-sdk-go-v2/service/managedblockchain" - "github.com/aws/aws-sdk-go-v2/service/marketplacecatalog" - "github.com/aws/aws-sdk-go-v2/service/marketplacecommerceanalytics" - "github.com/aws/aws-sdk-go-v2/service/marketplaceentitlementservice" - "github.com/aws/aws-sdk-go-v2/service/marketplacemetering" - "github.com/aws/aws-sdk-go-v2/service/mediaconnect" - "github.com/aws/aws-sdk-go-v2/service/mediaconvert" - "github.com/aws/aws-sdk-go-v2/service/medialive" - "github.com/aws/aws-sdk-go-v2/service/mediapackage" - "github.com/aws/aws-sdk-go-v2/service/mediapackagevod" - "github.com/aws/aws-sdk-go-v2/service/mediastore" - "github.com/aws/aws-sdk-go-v2/service/mediastoredata" - "github.com/aws/aws-sdk-go-v2/service/mediatailor" - "github.com/aws/aws-sdk-go-v2/service/migrationhub" - "github.com/aws/aws-sdk-go-v2/service/migrationhubconfig" - "github.com/aws/aws-sdk-go-v2/service/mobile" - "github.com/aws/aws-sdk-go-v2/service/mobileanalytics" - "github.com/aws/aws-sdk-go-v2/service/mq" - "github.com/aws/aws-sdk-go-v2/service/mturk" - "github.com/aws/aws-sdk-go-v2/service/neptune" - "github.com/aws/aws-sdk-go-v2/service/networkmanager" - "github.com/aws/aws-sdk-go-v2/service/opsworks" - "github.com/aws/aws-sdk-go-v2/service/opsworkscm" - "github.com/aws/aws-sdk-go-v2/service/organizations" - "github.com/aws/aws-sdk-go-v2/service/outposts" - "github.com/aws/aws-sdk-go-v2/service/personalize" - "github.com/aws/aws-sdk-go-v2/service/personalizeevents" - "github.com/aws/aws-sdk-go-v2/service/personalizeruntime" - "github.com/aws/aws-sdk-go-v2/service/pi" - "github.com/aws/aws-sdk-go-v2/service/pinpoint" - "github.com/aws/aws-sdk-go-v2/service/pinpointemail" - "github.com/aws/aws-sdk-go-v2/service/pinpointsmsvoice" - "github.com/aws/aws-sdk-go-v2/service/polly" - "github.com/aws/aws-sdk-go-v2/service/pricing" - "github.com/aws/aws-sdk-go-v2/service/qldb" - "github.com/aws/aws-sdk-go-v2/service/qldbsession" - "github.com/aws/aws-sdk-go-v2/service/quicksight" - "github.com/aws/aws-sdk-go-v2/service/ram" - "github.com/aws/aws-sdk-go-v2/service/rds" - "github.com/aws/aws-sdk-go-v2/service/rdsdata" - "github.com/aws/aws-sdk-go-v2/service/redshift" - "github.com/aws/aws-sdk-go-v2/service/rekognition" - "github.com/aws/aws-sdk-go-v2/service/resourcegroups" - "github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi" - "github.com/aws/aws-sdk-go-v2/service/robomaker" - "github.com/aws/aws-sdk-go-v2/service/route53" - "github.com/aws/aws-sdk-go-v2/service/route53domains" - "github.com/aws/aws-sdk-go-v2/service/route53resolver" - "github.com/aws/aws-sdk-go-v2/service/s3" - "github.com/aws/aws-sdk-go-v2/service/s3control" - "github.com/aws/aws-sdk-go-v2/service/sagemaker" - "github.com/aws/aws-sdk-go-v2/service/sagemakera2iruntime" - "github.com/aws/aws-sdk-go-v2/service/sagemakerruntime" - "github.com/aws/aws-sdk-go-v2/service/savingsplans" - "github.com/aws/aws-sdk-go-v2/service/schemas" - "github.com/aws/aws-sdk-go-v2/service/secretsmanager" - "github.com/aws/aws-sdk-go-v2/service/securityhub" - "github.com/aws/aws-sdk-go-v2/service/serverlessapplicationrepository" - "github.com/aws/aws-sdk-go-v2/service/servicecatalog" - "github.com/aws/aws-sdk-go-v2/service/servicediscovery" - "github.com/aws/aws-sdk-go-v2/service/servicequotas" - "github.com/aws/aws-sdk-go-v2/service/ses" - "github.com/aws/aws-sdk-go-v2/service/sesv2" - "github.com/aws/aws-sdk-go-v2/service/sfn" - "github.com/aws/aws-sdk-go-v2/service/shield" - "github.com/aws/aws-sdk-go-v2/service/signer" - "github.com/aws/aws-sdk-go-v2/service/simpledb" - "github.com/aws/aws-sdk-go-v2/service/sms" - "github.com/aws/aws-sdk-go-v2/service/snowball" - "github.com/aws/aws-sdk-go-v2/service/sns" - "github.com/aws/aws-sdk-go-v2/service/sqs" - "github.com/aws/aws-sdk-go-v2/service/ssm" - "github.com/aws/aws-sdk-go-v2/service/sso" - "github.com/aws/aws-sdk-go-v2/service/ssooidc" - "github.com/aws/aws-sdk-go-v2/service/storagegateway" - "github.com/aws/aws-sdk-go-v2/service/sts" - "github.com/aws/aws-sdk-go-v2/service/support" - "github.com/aws/aws-sdk-go-v2/service/swf" - "github.com/aws/aws-sdk-go-v2/service/textract" - "github.com/aws/aws-sdk-go-v2/service/transcribe" - "github.com/aws/aws-sdk-go-v2/service/transfer" - "github.com/aws/aws-sdk-go-v2/service/translate" - "github.com/aws/aws-sdk-go-v2/service/waf" - "github.com/aws/aws-sdk-go-v2/service/wafregional" - "github.com/aws/aws-sdk-go-v2/service/wafv2" - "github.com/aws/aws-sdk-go-v2/service/workdocs" - "github.com/aws/aws-sdk-go-v2/service/worklink" - "github.com/aws/aws-sdk-go-v2/service/workmail" - "github.com/aws/aws-sdk-go-v2/service/workmailmessageflow" - "github.com/aws/aws-sdk-go-v2/service/workspaces" - "github.com/aws/aws-sdk-go-v2/service/xray" -) - -type service struct { - name string - value reflect.Value -} - -func createServices(cfg aws.Config) []service { - s3Client := s3.New(cfg) - s3Client.ForcePathStyle = true - sqsClient := sqs.New(cfg) - sqsClient.DisableComputeChecksums = true - - return []service{ - {name: "accessanalyzer", value: reflect.ValueOf(accessanalyzer.New(cfg))}, - {name: "acm", value: reflect.ValueOf(acm.New(cfg))}, - {name: "acmpca", value: reflect.ValueOf(acmpca.New(cfg))}, - {name: "alexaforbusiness", value: reflect.ValueOf(alexaforbusiness.New(cfg))}, - {name: "amplify", value: reflect.ValueOf(amplify.New(cfg))}, - {name: "apigateway", value: reflect.ValueOf(apigateway.New(cfg))}, - {name: "apigatewaymanagementapi", value: reflect.ValueOf(apigatewaymanagementapi.New(cfg))}, - {name: "apigatewayv2", value: reflect.ValueOf(apigatewayv2.New(cfg))}, - {name: "appconfig", value: reflect.ValueOf(appconfig.New(cfg))}, - {name: "applicationautoscaling", value: reflect.ValueOf(applicationautoscaling.New(cfg))}, - {name: "applicationdiscoveryservice", value: reflect.ValueOf(applicationdiscoveryservice.New(cfg))}, - {name: "applicationinsights", value: reflect.ValueOf(applicationinsights.New(cfg))}, - {name: "appmesh", value: reflect.ValueOf(appmesh.New(cfg))}, - {name: "appstream", value: reflect.ValueOf(appstream.New(cfg))}, - {name: "appsync", value: reflect.ValueOf(appsync.New(cfg))}, - {name: "athena", value: reflect.ValueOf(athena.New(cfg))}, - {name: "autoscaling", value: reflect.ValueOf(autoscaling.New(cfg))}, - {name: "autoscalingplans", value: reflect.ValueOf(autoscalingplans.New(cfg))}, - {name: "backup", value: reflect.ValueOf(backup.New(cfg))}, - {name: "batch", value: reflect.ValueOf(batch.New(cfg))}, - {name: "budgets", value: reflect.ValueOf(budgets.New(cfg))}, - {name: "chime", value: reflect.ValueOf(chime.New(cfg))}, - {name: "cloud9", value: reflect.ValueOf(cloud9.New(cfg))}, - {name: "clouddirectory", value: reflect.ValueOf(clouddirectory.New(cfg))}, - {name: "cloudformation", value: reflect.ValueOf(cloudformation.New(cfg))}, - {name: "cloudfront", value: reflect.ValueOf(cloudfront.New(cfg))}, - {name: "cloudhsm", value: reflect.ValueOf(cloudhsm.New(cfg))}, - {name: "cloudhsmv2", value: reflect.ValueOf(cloudhsmv2.New(cfg))}, - {name: "cloudsearch", value: reflect.ValueOf(cloudsearch.New(cfg))}, - {name: "cloudsearchdomain", value: reflect.ValueOf(cloudsearchdomain.New(cfg))}, - {name: "cloudtrail", value: reflect.ValueOf(cloudtrail.New(cfg))}, - {name: "cloudwatch", value: reflect.ValueOf(cloudwatch.New(cfg))}, - {name: "cloudwatchevents", value: reflect.ValueOf(cloudwatchevents.New(cfg))}, - {name: "cloudwatchlogs", value: reflect.ValueOf(cloudwatchlogs.New(cfg))}, - {name: "codebuild", value: reflect.ValueOf(codebuild.New(cfg))}, - {name: "codecommit", value: reflect.ValueOf(codecommit.New(cfg))}, - {name: "codedeploy", value: reflect.ValueOf(codedeploy.New(cfg))}, - {name: "codeguruprofiler", value: reflect.ValueOf(codeguruprofiler.New(cfg))}, - {name: "codegurureviewer", value: reflect.ValueOf(codegurureviewer.New(cfg))}, - {name: "codepipeline", value: reflect.ValueOf(codepipeline.New(cfg))}, - {name: "codestar", value: reflect.ValueOf(codestar.New(cfg))}, - {name: "codestarconnections", value: reflect.ValueOf(codestarconnections.New(cfg))}, - {name: "codestarnotifications", value: reflect.ValueOf(codestarnotifications.New(cfg))}, - {name: "cognitoidentity", value: reflect.ValueOf(cognitoidentity.New(cfg))}, - {name: "cognitoidentityprovider", value: reflect.ValueOf(cognitoidentityprovider.New(cfg))}, - {name: "cognitosync", value: reflect.ValueOf(cognitosync.New(cfg))}, - {name: "comprehend", value: reflect.ValueOf(comprehend.New(cfg))}, - {name: "comprehendmedical", value: reflect.ValueOf(comprehendmedical.New(cfg))}, - {name: "computeoptimizer", value: reflect.ValueOf(computeoptimizer.New(cfg))}, - {name: "configservice", value: reflect.ValueOf(configservice.New(cfg))}, - {name: "connect", value: reflect.ValueOf(connect.New(cfg))}, - {name: "connectparticipant", value: reflect.ValueOf(connectparticipant.New(cfg))}, - {name: "costandusagereportservice", value: reflect.ValueOf(costandusagereportservice.New(cfg))}, - {name: "costexplorer", value: reflect.ValueOf(costexplorer.New(cfg))}, - {name: "databasemigrationservice", value: reflect.ValueOf(databasemigrationservice.New(cfg))}, - {name: "dataexchange", value: reflect.ValueOf(dataexchange.New(cfg))}, - {name: "datapipeline", value: reflect.ValueOf(datapipeline.New(cfg))}, - {name: "datasync", value: reflect.ValueOf(datasync.New(cfg))}, - {name: "dax", value: reflect.ValueOf(dax.New(cfg))}, - {name: "detective", value: reflect.ValueOf(detective.New(cfg))}, - {name: "devicefarm", value: reflect.ValueOf(devicefarm.New(cfg))}, - {name: "directconnect", value: reflect.ValueOf(directconnect.New(cfg))}, - {name: "directoryservice", value: reflect.ValueOf(directoryservice.New(cfg))}, - {name: "dlm", value: reflect.ValueOf(dlm.New(cfg))}, - {name: "docdb", value: reflect.ValueOf(docdb.New(cfg))}, - {name: "dynamodb", value: reflect.ValueOf(dynamodb.New(cfg))}, - {name: "dynamodbstreams", value: reflect.ValueOf(dynamodbstreams.New(cfg))}, - {name: "ebs", value: reflect.ValueOf(ebs.New(cfg))}, - {name: "ec2", value: reflect.ValueOf(ec2.New(cfg))}, - {name: "ec2instanceconnect", value: reflect.ValueOf(ec2instanceconnect.New(cfg))}, - {name: "ecr", value: reflect.ValueOf(ecr.New(cfg))}, - {name: "ecs", value: reflect.ValueOf(ecs.New(cfg))}, - {name: "efs", value: reflect.ValueOf(efs.New(cfg))}, - {name: "eks", value: reflect.ValueOf(eks.New(cfg))}, - {name: "elasticache", value: reflect.ValueOf(elasticache.New(cfg))}, - {name: "elasticbeanstalk", value: reflect.ValueOf(elasticbeanstalk.New(cfg))}, - {name: "elasticinference", value: reflect.ValueOf(elasticinference.New(cfg))}, - {name: "elasticloadbalancing", value: reflect.ValueOf(elasticloadbalancing.New(cfg))}, - {name: "elasticloadbalancingv2", value: reflect.ValueOf(elasticloadbalancingv2.New(cfg))}, - {name: "elasticsearchservice", value: reflect.ValueOf(elasticsearchservice.New(cfg))}, - {name: "elastictranscoder", value: reflect.ValueOf(elastictranscoder.New(cfg))}, - {name: "emr", value: reflect.ValueOf(emr.New(cfg))}, - {name: "eventbridge", value: reflect.ValueOf(eventbridge.New(cfg))}, - {name: "firehose", value: reflect.ValueOf(firehose.New(cfg))}, - {name: "fms", value: reflect.ValueOf(fms.New(cfg))}, - {name: "forecast", value: reflect.ValueOf(forecast.New(cfg))}, - {name: "forecastquery", value: reflect.ValueOf(forecastquery.New(cfg))}, - {name: "frauddetector", value: reflect.ValueOf(frauddetector.New(cfg))}, - {name: "fsx", value: reflect.ValueOf(fsx.New(cfg))}, - {name: "gamelift", value: reflect.ValueOf(gamelift.New(cfg))}, - {name: "glacier", value: reflect.ValueOf(glacier.New(cfg))}, - {name: "globalaccelerator", value: reflect.ValueOf(globalaccelerator.New(cfg))}, - {name: "glue", value: reflect.ValueOf(glue.New(cfg))}, - {name: "greengrass", value: reflect.ValueOf(greengrass.New(cfg))}, - {name: "groundstation", value: reflect.ValueOf(groundstation.New(cfg))}, - {name: "guardduty", value: reflect.ValueOf(guardduty.New(cfg))}, - {name: "health", value: reflect.ValueOf(health.New(cfg))}, - {name: "iam", value: reflect.ValueOf(iam.New(cfg))}, - {name: "imagebuilder", value: reflect.ValueOf(imagebuilder.New(cfg))}, - {name: "inspector", value: reflect.ValueOf(inspector.New(cfg))}, - {name: "iot", value: reflect.ValueOf(iot.New(cfg))}, - {name: "iot1clickdevicesservice", value: reflect.ValueOf(iot1clickdevicesservice.New(cfg))}, - {name: "iot1clickprojects", value: reflect.ValueOf(iot1clickprojects.New(cfg))}, - {name: "iotanalytics", value: reflect.ValueOf(iotanalytics.New(cfg))}, - {name: "iotdataplane", value: reflect.ValueOf(iotdataplane.New(cfg))}, - {name: "iotevents", value: reflect.ValueOf(iotevents.New(cfg))}, - {name: "ioteventsdata", value: reflect.ValueOf(ioteventsdata.New(cfg))}, - {name: "iotjobsdataplane", value: reflect.ValueOf(iotjobsdataplane.New(cfg))}, - {name: "iotsecuretunneling", value: reflect.ValueOf(iotsecuretunneling.New(cfg))}, - {name: "iotthingsgraph", value: reflect.ValueOf(iotthingsgraph.New(cfg))}, - {name: "kafka", value: reflect.ValueOf(kafka.New(cfg))}, - {name: "kendra", value: reflect.ValueOf(kendra.New(cfg))}, - {name: "kinesis", value: reflect.ValueOf(kinesis.New(cfg))}, - {name: "kinesisanalytics", value: reflect.ValueOf(kinesisanalytics.New(cfg))}, - {name: "kinesisanalyticsv2", value: reflect.ValueOf(kinesisanalyticsv2.New(cfg))}, - {name: "kinesisvideo", value: reflect.ValueOf(kinesisvideo.New(cfg))}, - {name: "kinesisvideoarchivedmedia", value: reflect.ValueOf(kinesisvideoarchivedmedia.New(cfg))}, - {name: "kinesisvideomedia", value: reflect.ValueOf(kinesisvideomedia.New(cfg))}, - {name: "kinesisvideosignaling", value: reflect.ValueOf(kinesisvideosignaling.New(cfg))}, - {name: "kms", value: reflect.ValueOf(kms.New(cfg))}, - {name: "lakeformation", value: reflect.ValueOf(lakeformation.New(cfg))}, - {name: "lambda", value: reflect.ValueOf(lambda.New(cfg))}, - {name: "lexmodelbuildingservice", value: reflect.ValueOf(lexmodelbuildingservice.New(cfg))}, - {name: "lexruntimeservice", value: reflect.ValueOf(lexruntimeservice.New(cfg))}, - {name: "licensemanager", value: reflect.ValueOf(licensemanager.New(cfg))}, - {name: "lightsail", value: reflect.ValueOf(lightsail.New(cfg))}, - {name: "machinelearning", value: reflect.ValueOf(machinelearning.New(cfg))}, - {name: "macie", value: reflect.ValueOf(macie.New(cfg))}, - {name: "managedblockchain", value: reflect.ValueOf(managedblockchain.New(cfg))}, - {name: "marketplacecatalog", value: reflect.ValueOf(marketplacecatalog.New(cfg))}, - {name: "marketplacecommerceanalytics", value: reflect.ValueOf(marketplacecommerceanalytics.New(cfg))}, - {name: "marketplaceentitlementservice", value: reflect.ValueOf(marketplaceentitlementservice.New(cfg))}, - {name: "marketplacemetering", value: reflect.ValueOf(marketplacemetering.New(cfg))}, - {name: "mediaconnect", value: reflect.ValueOf(mediaconnect.New(cfg))}, - {name: "mediaconvert", value: reflect.ValueOf(mediaconvert.New(cfg))}, - {name: "medialive", value: reflect.ValueOf(medialive.New(cfg))}, - {name: "mediapackage", value: reflect.ValueOf(mediapackage.New(cfg))}, - {name: "mediapackagevod", value: reflect.ValueOf(mediapackagevod.New(cfg))}, - {name: "mediastore", value: reflect.ValueOf(mediastore.New(cfg))}, - {name: "mediastoredata", value: reflect.ValueOf(mediastoredata.New(cfg))}, - {name: "mediatailor", value: reflect.ValueOf(mediatailor.New(cfg))}, - {name: "migrationhub", value: reflect.ValueOf(migrationhub.New(cfg))}, - {name: "migrationhubconfig", value: reflect.ValueOf(migrationhubconfig.New(cfg))}, - {name: "mobile", value: reflect.ValueOf(mobile.New(cfg))}, - {name: "mobileanalytics", value: reflect.ValueOf(mobileanalytics.New(cfg))}, - {name: "mq", value: reflect.ValueOf(mq.New(cfg))}, - {name: "mturk", value: reflect.ValueOf(mturk.New(cfg))}, - {name: "neptune", value: reflect.ValueOf(neptune.New(cfg))}, - {name: "networkmanager", value: reflect.ValueOf(networkmanager.New(cfg))}, - {name: "opsworks", value: reflect.ValueOf(opsworks.New(cfg))}, - {name: "opsworkscm", value: reflect.ValueOf(opsworkscm.New(cfg))}, - {name: "organizations", value: reflect.ValueOf(organizations.New(cfg))}, - {name: "outposts", value: reflect.ValueOf(outposts.New(cfg))}, - {name: "personalize", value: reflect.ValueOf(personalize.New(cfg))}, - {name: "personalizeevents", value: reflect.ValueOf(personalizeevents.New(cfg))}, - {name: "personalizeruntime", value: reflect.ValueOf(personalizeruntime.New(cfg))}, - {name: "pi", value: reflect.ValueOf(pi.New(cfg))}, - {name: "pinpoint", value: reflect.ValueOf(pinpoint.New(cfg))}, - {name: "pinpointemail", value: reflect.ValueOf(pinpointemail.New(cfg))}, - {name: "pinpointsmsvoice", value: reflect.ValueOf(pinpointsmsvoice.New(cfg))}, - {name: "polly", value: reflect.ValueOf(polly.New(cfg))}, - {name: "pricing", value: reflect.ValueOf(pricing.New(cfg))}, - {name: "qldb", value: reflect.ValueOf(qldb.New(cfg))}, - {name: "qldbsession", value: reflect.ValueOf(qldbsession.New(cfg))}, - {name: "quicksight", value: reflect.ValueOf(quicksight.New(cfg))}, - {name: "ram", value: reflect.ValueOf(ram.New(cfg))}, - {name: "rds", value: reflect.ValueOf(rds.New(cfg))}, - {name: "rdsdata", value: reflect.ValueOf(rdsdata.New(cfg))}, - {name: "redshift", value: reflect.ValueOf(redshift.New(cfg))}, - {name: "rekognition", value: reflect.ValueOf(rekognition.New(cfg))}, - {name: "resourcegroups", value: reflect.ValueOf(resourcegroups.New(cfg))}, - {name: "resourcegroupstaggingapi", value: reflect.ValueOf(resourcegroupstaggingapi.New(cfg))}, - {name: "robomaker", value: reflect.ValueOf(robomaker.New(cfg))}, - {name: "route53", value: reflect.ValueOf(route53.New(cfg))}, - {name: "route53domains", value: reflect.ValueOf(route53domains.New(cfg))}, - {name: "route53resolver", value: reflect.ValueOf(route53resolver.New(cfg))}, - {name: "s3", value: reflect.ValueOf(s3Client)}, - {name: "s3control", value: reflect.ValueOf(s3control.New(cfg))}, - {name: "sagemaker", value: reflect.ValueOf(sagemaker.New(cfg))}, - {name: "sagemakera2iruntime", value: reflect.ValueOf(sagemakera2iruntime.New(cfg))}, - {name: "sagemakerruntime", value: reflect.ValueOf(sagemakerruntime.New(cfg))}, - {name: "savingsplans", value: reflect.ValueOf(savingsplans.New(cfg))}, - {name: "schemas", value: reflect.ValueOf(schemas.New(cfg))}, - {name: "secretsmanager", value: reflect.ValueOf(secretsmanager.New(cfg))}, - {name: "securityhub", value: reflect.ValueOf(securityhub.New(cfg))}, - {name: "serverlessapplicationrepository", value: reflect.ValueOf(serverlessapplicationrepository.New(cfg))}, - {name: "servicecatalog", value: reflect.ValueOf(servicecatalog.New(cfg))}, - {name: "servicediscovery", value: reflect.ValueOf(servicediscovery.New(cfg))}, - {name: "servicequotas", value: reflect.ValueOf(servicequotas.New(cfg))}, - {name: "ses", value: reflect.ValueOf(ses.New(cfg))}, - {name: "sesv2", value: reflect.ValueOf(sesv2.New(cfg))}, - {name: "sfn", value: reflect.ValueOf(sfn.New(cfg))}, - {name: "shield", value: reflect.ValueOf(shield.New(cfg))}, - {name: "signer", value: reflect.ValueOf(signer.New(cfg))}, - {name: "simpledb", value: reflect.ValueOf(simpledb.New(cfg))}, - {name: "sms", value: reflect.ValueOf(sms.New(cfg))}, - {name: "snowball", value: reflect.ValueOf(snowball.New(cfg))}, - {name: "sns", value: reflect.ValueOf(sns.New(cfg))}, - {name: "sqs", value: reflect.ValueOf(sqsClient)}, - {name: "ssm", value: reflect.ValueOf(ssm.New(cfg))}, - {name: "sso", value: reflect.ValueOf(sso.New(cfg))}, - {name: "ssooidc", value: reflect.ValueOf(ssooidc.New(cfg))}, - {name: "storagegateway", value: reflect.ValueOf(storagegateway.New(cfg))}, - {name: "sts", value: reflect.ValueOf(sts.New(cfg))}, - {name: "support", value: reflect.ValueOf(support.New(cfg))}, - {name: "swf", value: reflect.ValueOf(swf.New(cfg))}, - {name: "textract", value: reflect.ValueOf(textract.New(cfg))}, - {name: "transcribe", value: reflect.ValueOf(transcribe.New(cfg))}, - {name: "transfer", value: reflect.ValueOf(transfer.New(cfg))}, - {name: "translate", value: reflect.ValueOf(translate.New(cfg))}, - {name: "waf", value: reflect.ValueOf(waf.New(cfg))}, - {name: "wafregional", value: reflect.ValueOf(wafregional.New(cfg))}, - {name: "wafv2", value: reflect.ValueOf(wafv2.New(cfg))}, - {name: "workdocs", value: reflect.ValueOf(workdocs.New(cfg))}, - {name: "worklink", value: reflect.ValueOf(worklink.New(cfg))}, - {name: "workmail", value: reflect.ValueOf(workmail.New(cfg))}, - {name: "workmailmessageflow", value: reflect.ValueOf(workmailmessageflow.New(cfg))}, - {name: "workspaces", value: reflect.ValueOf(workspaces.New(cfg))}, - {name: "xray", value: reflect.ValueOf(xray.New(cfg))}, - } -} diff --git a/internal/awstesting/cmd/op_crawler/generate.go b/internal/awstesting/cmd/op_crawler/generate.go deleted file mode 100644 index 846aaa37c1e..00000000000 --- a/internal/awstesting/cmd/op_crawler/generate.go +++ /dev/null @@ -1,6 +0,0 @@ -// +build sdktool - -package main - -//go:generate go run -tags codegen ./codegen/codegen.go ../../../../service -//go:generate gofmt -s -w . diff --git a/internal/awstesting/cmd/op_crawler/main.go b/internal/awstesting/cmd/op_crawler/main.go deleted file mode 100644 index 3ef7f0ac3cf..00000000000 --- a/internal/awstesting/cmd/op_crawler/main.go +++ /dev/null @@ -1,457 +0,0 @@ -// +build sdktool - -package main - -import ( - "bytes" - "crypto/tls" - "flag" - "fmt" - "io" - "io/ioutil" - "net" - "net/http" - "net/http/httptest" - "net/url" - "os" - "reflect" - "sort" - "strconv" - "strings" - "time" - - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/defaults" - "github.com/aws/aws-sdk-go-v2/aws/endpoints" - "github.com/aws/aws-sdk-go-v2/aws/external" -) - -func main() { - var filterService, filterOp string - flag.StringVar(&filterService, "s", "", "The `service` to execute. If unset will run all services.") - flag.StringVar(&filterOp, "o", "", "The `operation` to execute. If unset will run all operations. Requires service set.") - flag.Parse() - - if len(filterOp) > 0 && len(filterService) == 0 { - flag.PrintDefaults() - panic("operation filter requires service set also") - } - - w := writer{ - buf: bytes.NewBuffer(nil), - indentStr: "\t", - } - server := setupServer(w.Indent()) - defer server.Close() - - cfg, err := external.LoadDefaultAWSConfig() - if err != nil { - panic("failed to load config " + err.Error()) - } - cfg.EndpointResolver = aws.ResolveWithEndpointURL(server.URL) - cfg.Region = endpoints.UsWest2RegionID - cfg.Credentials = aws.AnonymousCredentials - cfg.Handlers.Validate.Remove(defaults.ValidateParametersHandler) - - cfg.HTTPClient = &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - DialContext: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - DualStack: true, - }).DialContext, - MaxIdleConns: 100, - IdleConnTimeout: 90 * time.Second, - TLSHandshakeTimeout: 10 * time.Second, - ExpectContinueTimeout: 1 * time.Second, - }, - } - - cfg.Handlers.Send.PushFront(func(r *aws.Request) { - w.Writef("%s.%s:", r.Metadata.ServiceName, r.Operation.Name) - }) - - for _, service := range createServices(cfg) { - if len(filterService) > 0 && service.name != filterService { - continue - } - - fmt.Println("Processing:", service.name) - if err := callService(service.value, filterOp); err != nil { - panic(fmt.Sprintf("Service, %s failed, %v", service.name, err)) - } - } - - io.Copy(os.Stdout, w.buf) -} - -const ( - allowedRecursion = 2 - sliceSize = 3 -) - -func callService(svcV reflect.Value, filterOp string) error { - reqOption := aws.Option( - func(r *aws.Request) { - r.Handlers.Build.PushBack(func(req *aws.Request) { - endpoint, _ := r.Config.EndpointResolver.ResolveEndpoint(r.Metadata.ServiceName, r.Config.Region) - origURL, _ := url.Parse(endpoint.URL) - // Correct ContentLength fields for S3 operations - switch r.Metadata.ServiceName { - case "s3": - switch r.Operation.Name { - case "PutObject", "UploadPart": - n, _ := computeBodyLength(r.GetBody()) - r.HTTPRequest.Header.Set("Content-Length", strconv.FormatInt(n, 10)) - } - case "machinelearning": - newURL := r.HTTPRequest.URL - r.HTTPRequest.URL = origURL - r.HTTPRequest.URL.Path = newURL.Path - if !strings.HasPrefix(r.HTTPRequest.URL.Path, "/") { - r.HTTPRequest.URL.Path = "/" + r.HTTPRequest.URL.Path - } - r.HTTPRequest.URL.RawPath = newURL.RawPath - r.HTTPRequest.URL.RawQuery = newURL.RawQuery - } - }) - - r.Handlers.Complete.PushBack(func(req *aws.Request) { - if r.Error != nil { - fmt.Println(r.Params) - } - }) - }, - ) - - svcT := svcV.Type() - n := svcT.NumMethod() - - ops := []string{} - for i := 0; i < n; i++ { - fm := svcT.Method(i) - fName := fm.Name - - if fName == "NewRequest" || !strings.HasSuffix(fName, "Request") || (len(filterOp) > 0 && fName != filterOp) { - continue - } - - ops = append(ops, strings.TrimSuffix(fName, "Request")) - } - - sort.Strings(ops) - for _, op := range ops { - fName := op + "Request" - - fv := svcV.MethodByName(fName) - fm, _ := svcT.MethodByName(fName) - ft := fm.Type - - fmt.Println("-", op) - - it := ft.In(1) - iv := valueForType(it, visitType(it)) - - ovs := fv.Call([]reflect.Value{iv}) - - m := findMethod(ovs[0], "ApplyOptions") - m.Call([]reflect.Value{reflect.ValueOf(reqOption)}) - - m = findMethod(ovs[0], "Send") - ovs = m.Call([]reflect.Value{}) - - if v := ovs[1]; !v.IsNil() { - return v.Interface().(error) - } - } - - return nil -} - -// findMethod finds the method name on the v type using a case-insensitive -// lookup. Returns nil if no method is found. -func findMethod(v reflect.Value, methodName string) *reflect.Value { - if v.Kind() != reflect.Struct { - return nil - } - - t := v.Type() - for i := 0; i < t.NumMethod(); i++ { - if name := t.Method(i).Name; name == methodName { - m := v.MethodByName(name) - return &m - } - } - - // Check if the method exists on a field - for i := 0; i < t.NumField(); i++ { - if m := findMethod(reflect.Indirect(v).Field(i), methodName); m != nil { - return m - } - } - - return nil -} - -func asVisited(v map[reflect.Type]int, t reflect.Type) (map[reflect.Type]int, bool) { - if c, ok := v[t]; ok { - if c == 0 { - return v, false - } - c-- - v[t] = c - } else { - v[t] = allowedRecursion - } - - return v, true -} - -var ioReadSeekerType = reflect.TypeOf((*io.ReadSeeker)(nil)).Elem() -var emptyInterfaceType = reflect.TypeOf((*interface{})(nil)).Elem() - -func valueForType(vt reflect.Type, visited *visitedType) reflect.Value { - var v reflect.Value - - vtt := vt - if vtt.Kind() == reflect.Ptr { - vtt = vtt.Elem() - } - - switch vtt.Kind() { - case reflect.Map: - v = reflect.MakeMap(vtt) - kt := vtt.Key() - kv := valueForType(kt, visited) - et := vtt.Elem() - ev := valueForType(et, visited) - v.SetMapIndex(kv, ev) - - case reflect.Slice: - v = reflect.MakeSlice(vtt, sliceSize, sliceSize) - vet := vtt.Elem() - for i := 0; i < sliceSize; i++ { - sv := v.Index(i) - nsv := valueForType(vet, visited) - sv.Set(nsv) - } - - case reflect.Interface: - switch vtt { - case ioReadSeekerType: - v = reflect.New(vtt) - v.Elem().Set(reflect.ValueOf(bytes.NewReader([]byte("byte value")))) - case emptyInterfaceType: - v = reflect.ValueOf("empty interface value") - default: - panic("value for interface, unknown type" + vtt.String()) - } - - case reflect.String: - v = reflect.New(vtt) - v.Elem().SetString("stringValue") - - case reflect.Bool: - v = reflect.New(vtt) - v.Elem().SetBool(true) - - case reflect.Uint8: // byte - v = reflect.New(vtt) - v.Elem().Set(reflect.ValueOf(uint8('b'))) - - case reflect.Int64: - v = reflect.New(vtt) - v.Elem().SetInt(987654321) - - case reflect.Float64: - v = reflect.New(vtt) - v.Elem().SetFloat(123456789.321) - - case reflect.Struct: - v = reflect.New(vtt) - ve := v.Elem() - n := ve.NumField() - for i := 0; i < n; i++ { - fv := ve.Field(i) - fs := vtt.Field(i) - ft := fv.Type() - if len(fs.PkgPath) != 0 { - continue - } - nested, keep := visited.Visit(ft) - if !keep { - continue - } - nfv := valueForType(ft, nested) - fv.Set(nfv) - } - default: - panic("unknown type, " + vtt.String()) - } - - if vt.Kind() != reflect.Ptr && v.Kind() == reflect.Ptr { - v = v.Elem() - } - - return v -} - -func setupServer(out writer) *httptest.Server { - server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - - out.Writef("Path:") - out.Indent().Writef(r.URL.Path) - out.Writef("Query:") - var keys []string - query := r.URL.Query() - for k := range query { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - for _, v := range query[k] { - out.Indent().Writef("%s: %s", k, v) - } - } - out.Writef("Headers:") - keys = keys[0:0] - for k := range r.Header { - keys = append(keys, k) - } - sort.Strings(keys) - for _, k := range keys { - for _, v := range r.Header[k] { - out.Indent().Writef("%s: %s", k, v) - } - } - body, err := ioutil.ReadAll(r.Body) - if err != nil { - panic(err) - } - r.Body.Close() - out.Writef("Body:") - out.Indent().Writef(string(body)) - })) - - return server -} - -type writer struct { - buf *bytes.Buffer - indent int - indentStr string -} - -func (w writer) Writef(format string, args ...interface{}) error { - indent := strings.Repeat(w.indentStr, w.indent) - w.buf.WriteString(indent) - w.buf.WriteString(fmt.Sprintf(format, args...)) - w.buf.WriteRune('\n') - return nil -} -func (w writer) Indent() writer { - newW := w - newW.indent++ - return newW -} - -type visitedType struct { - typ reflect.Type - left int - next *visitedType -} - -func visitType(t reflect.Type) *visitedType { - return &visitedType{ - typ: t, - left: allowedRecursion, - } -} - -func (v *visitedType) String() string { - if v == nil { - return "END" - } - return fmt.Sprintf("Type:%v,Kind:%v,Left:%v->%v", v.typ.Name(), v.typ.Kind(), v.left, v.next.String()) -} - -func (v *visitedType) copy() *visitedType { - nv := &visitedType{} - - oldNext := v - newNext := nv - - for { - *newNext = *oldNext - oldNext = oldNext.next - - if oldNext == nil { - break - } - - newNext.next = &visitedType{} - newNext = newNext.next - } - - return nv -} - -func (v *visitedType) Visit(t reflect.Type) (*visitedType, bool) { - if v == nil { - return visitType(t), true - } - - nv := v.copy() - - last := nv - next := nv - for next != nil { - last = next - if next.typ != t { - next = next.next - continue - } - - next.left-- - return nv, next.left >= 0 - } - - last.next = visitType(t) - - return nv, true -} - -func computeBodyLength(r io.ReadSeeker) (int64, error) { - seekable := true - // Determine if the seeker is actually seekable. ReaderSeekerCloser - // hides the fact that a io.Readers might not actually be seekable. - switch v := r.(type) { - case aws.ReaderSeekerCloser: - seekable = v.IsSeeker() - case *aws.ReaderSeekerCloser: - seekable = v.IsSeeker() - } - if !seekable { - return -1, nil - } - - curOffset, err := r.Seek(0, io.SeekCurrent) - if err != nil { - return 0, err - } - - endOffset, err := r.Seek(0, io.SeekEnd) - if err != nil { - return 0, err - } - - _, err = r.Seek(curOffset, io.SeekStart) - if err != nil { - return 0, err - } - - return endOffset - curOffset, nil -} diff --git a/private/protocol/restxml/build_bench_test.go b/private/protocol/restxml/build_bench_test.go index 97dfbdcf8bc..787be24d282 100644 --- a/private/protocol/restxml/build_bench_test.go +++ b/private/protocol/restxml/build_bench_test.go @@ -1,16 +1,14 @@ package restxml_test import ( + "bytes" + "encoding/xml" "net/http" "net/http/httptest" "os" "testing" - "bytes" - "encoding/xml" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/aws/endpoints" "github.com/aws/aws-sdk-go-v2/internal/awstesting/unit" "github.com/aws/aws-sdk-go-v2/private/protocol/restxml" "github.com/aws/aws-sdk-go-v2/service/cloudfront" @@ -30,7 +28,7 @@ func TestMain(m *testing.M) { cfg := unit.Config() cfg.Credentials = aws.NewStaticCredentialsProvider("Key", "Secret", "Token") - cfg.Region = endpoints.UsWest2RegionID + cfg.Region = "us-west-2" cfg.EndpointResolver = aws.ResolveWithEndpointURL(server.URL) cloudfrontSvc = cloudfront.New(cfg)