Blame vendor/github.com/aws/aws-sdk-go/aws/endpoints/endpoints.go

Packit Service 4d2de5
package endpoints
Packit Service 4d2de5
Packit Service 4d2de5
import (
Packit Service 4d2de5
	"fmt"
Packit Service 4d2de5
	"regexp"
Packit Service 4d2de5
	"strings"
Packit Service 4d2de5
Packit Service 4d2de5
	"github.com/aws/aws-sdk-go/aws/awserr"
Packit Service 4d2de5
)
Packit Service 4d2de5
Packit Service 4d2de5
// Options provide the configuration needed to direct how the
Packit Service 4d2de5
// endpoints will be resolved.
Packit Service 4d2de5
type Options struct {
Packit Service 4d2de5
	// DisableSSL forces the endpoint to be resolved as HTTP.
Packit Service 4d2de5
	// instead of HTTPS if the service supports it.
Packit Service 4d2de5
	DisableSSL bool
Packit Service 4d2de5
Packit Service 4d2de5
	// Sets the resolver to resolve the endpoint as a dualstack endpoint
Packit Service 4d2de5
	// for the service. If dualstack support for a service is not known and
Packit Service 4d2de5
	// StrictMatching is not enabled a dualstack endpoint for the service will
Packit Service 4d2de5
	// be returned. This endpoint may not be valid. If StrictMatching is
Packit Service 4d2de5
	// enabled only services that are known to support dualstack will return
Packit Service 4d2de5
	// dualstack endpoints.
Packit Service 4d2de5
	UseDualStack bool
Packit Service 4d2de5
Packit Service 4d2de5
	// Enables strict matching of services and regions resolved endpoints.
Packit Service 4d2de5
	// If the partition doesn't enumerate the exact service and region an
Packit Service 4d2de5
	// error will be returned. This option will prevent returning endpoints
Packit Service 4d2de5
	// that look valid, but may not resolve to any real endpoint.
Packit Service 4d2de5
	StrictMatching bool
Packit Service 4d2de5
Packit Service 4d2de5
	// Enables resolving a service endpoint based on the region provided if the
Packit Service 4d2de5
	// service does not exist. The service endpoint ID will be used as the service
Packit Service 4d2de5
	// domain name prefix. By default the endpoint resolver requires the service
Packit Service 4d2de5
	// to be known when resolving endpoints.
Packit Service 4d2de5
	//
Packit Service 4d2de5
	// If resolving an endpoint on the partition list the provided region will
Packit Service 4d2de5
	// be used to determine which partition's domain name pattern to the service
Packit Service 4d2de5
	// endpoint ID with. If both the service and region are unknown and resolving
Packit Service 4d2de5
	// the endpoint on partition list an UnknownEndpointError error will be returned.
Packit Service 4d2de5
	//
Packit Service 4d2de5
	// If resolving and endpoint on a partition specific resolver that partition's
Packit Service 4d2de5
	// domain name pattern will be used with the service endpoint ID. If both
Packit Service 4d2de5
	// region and service do not exist when resolving an endpoint on a specific
Packit Service 4d2de5
	// partition the partition's domain pattern will be used to combine the
Packit Service 4d2de5
	// endpoint and region together.
Packit Service 4d2de5
	//
Packit Service 4d2de5
	// This option is ignored if StrictMatching is enabled.
Packit Service 4d2de5
	ResolveUnknownService bool
Packit Service 4d2de5
Packit Service 4d2de5
	// STS Regional Endpoint flag helps with resolving the STS endpoint
Packit Service 4d2de5
	STSRegionalEndpoint STSRegionalEndpoint
Packit Service 4d2de5
Packit Service 4d2de5
	// S3 Regional Endpoint flag helps with resolving the S3 endpoint
Packit Service 4d2de5
	S3UsEast1RegionalEndpoint S3UsEast1RegionalEndpoint
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// STSRegionalEndpoint is an enum for the states of the STS Regional Endpoint
Packit Service 4d2de5
// options.
Packit Service 4d2de5
type STSRegionalEndpoint int
Packit Service 4d2de5
Packit Service 4d2de5
func (e STSRegionalEndpoint) String() string {
Packit Service 4d2de5
	switch e {
Packit Service 4d2de5
	case LegacySTSEndpoint:
Packit Service 4d2de5
		return "legacy"
Packit Service 4d2de5
	case RegionalSTSEndpoint:
Packit Service 4d2de5
		return "regional"
Packit Service 4d2de5
	case UnsetSTSEndpoint:
Packit Service 4d2de5
		return ""
Packit Service 4d2de5
	default:
Packit Service 4d2de5
		return "unknown"
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
const (
Packit Service 4d2de5
Packit Service 4d2de5
	// UnsetSTSEndpoint represents that STS Regional Endpoint flag is not specified.
Packit Service 4d2de5
	UnsetSTSEndpoint STSRegionalEndpoint = iota
Packit Service 4d2de5
Packit Service 4d2de5
	// LegacySTSEndpoint represents when STS Regional Endpoint flag is specified
Packit Service 4d2de5
	// to use legacy endpoints.
Packit Service 4d2de5
	LegacySTSEndpoint
Packit Service 4d2de5
Packit Service 4d2de5
	// RegionalSTSEndpoint represents when STS Regional Endpoint flag is specified
Packit Service 4d2de5
	// to use regional endpoints.
Packit Service 4d2de5
	RegionalSTSEndpoint
Packit Service 4d2de5
)
Packit Service 4d2de5
Packit Service 4d2de5
// GetSTSRegionalEndpoint function returns the STSRegionalEndpointFlag based
Packit Service 4d2de5
// on the input string provided in env config or shared config by the user.
Packit Service 4d2de5
//
Packit Service 4d2de5
// `legacy`, `regional` are the only case-insensitive valid strings for
Packit Service 4d2de5
// resolving the STS regional Endpoint flag.
Packit Service 4d2de5
func GetSTSRegionalEndpoint(s string) (STSRegionalEndpoint, error) {
Packit Service 4d2de5
	switch {
Packit Service 4d2de5
	case strings.EqualFold(s, "legacy"):
Packit Service 4d2de5
		return LegacySTSEndpoint, nil
Packit Service 4d2de5
	case strings.EqualFold(s, "regional"):
Packit Service 4d2de5
		return RegionalSTSEndpoint, nil
Packit Service 4d2de5
	default:
Packit Service 4d2de5
		return UnsetSTSEndpoint, fmt.Errorf("unable to resolve the value of STSRegionalEndpoint for %v", s)
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// S3UsEast1RegionalEndpoint is an enum for the states of the S3 us-east-1
Packit Service 4d2de5
// Regional Endpoint options.
Packit Service 4d2de5
type S3UsEast1RegionalEndpoint int
Packit Service 4d2de5
Packit Service 4d2de5
func (e S3UsEast1RegionalEndpoint) String() string {
Packit Service 4d2de5
	switch e {
Packit Service 4d2de5
	case LegacyS3UsEast1Endpoint:
Packit Service 4d2de5
		return "legacy"
Packit Service 4d2de5
	case RegionalS3UsEast1Endpoint:
Packit Service 4d2de5
		return "regional"
Packit Service 4d2de5
	case UnsetS3UsEast1Endpoint:
Packit Service 4d2de5
		return ""
Packit Service 4d2de5
	default:
Packit Service 4d2de5
		return "unknown"
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
const (
Packit Service 4d2de5
Packit Service 4d2de5
	// UnsetS3UsEast1Endpoint represents that S3 Regional Endpoint flag is not
Packit Service 4d2de5
	// specified.
Packit Service 4d2de5
	UnsetS3UsEast1Endpoint S3UsEast1RegionalEndpoint = iota
Packit Service 4d2de5
Packit Service 4d2de5
	// LegacyS3UsEast1Endpoint represents when S3 Regional Endpoint flag is
Packit Service 4d2de5
	// specified to use legacy endpoints.
Packit Service 4d2de5
	LegacyS3UsEast1Endpoint
Packit Service 4d2de5
Packit Service 4d2de5
	// RegionalS3UsEast1Endpoint represents when S3 Regional Endpoint flag is
Packit Service 4d2de5
	// specified to use regional endpoints.
Packit Service 4d2de5
	RegionalS3UsEast1Endpoint
Packit Service 4d2de5
)
Packit Service 4d2de5
Packit Service 4d2de5
// GetS3UsEast1RegionalEndpoint function returns the S3UsEast1RegionalEndpointFlag based
Packit Service 4d2de5
// on the input string provided in env config or shared config by the user.
Packit Service 4d2de5
//
Packit Service 4d2de5
// `legacy`, `regional` are the only case-insensitive valid strings for
Packit Service 4d2de5
// resolving the S3 regional Endpoint flag.
Packit Service 4d2de5
func GetS3UsEast1RegionalEndpoint(s string) (S3UsEast1RegionalEndpoint, error) {
Packit Service 4d2de5
	switch {
Packit Service 4d2de5
	case strings.EqualFold(s, "legacy"):
Packit Service 4d2de5
		return LegacyS3UsEast1Endpoint, nil
Packit Service 4d2de5
	case strings.EqualFold(s, "regional"):
Packit Service 4d2de5
		return RegionalS3UsEast1Endpoint, nil
Packit Service 4d2de5
	default:
Packit Service 4d2de5
		return UnsetS3UsEast1Endpoint,
Packit Service 4d2de5
			fmt.Errorf("unable to resolve the value of S3UsEast1RegionalEndpoint for %v", s)
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Set combines all of the option functions together.
Packit Service 4d2de5
func (o *Options) Set(optFns ...func(*Options)) {
Packit Service 4d2de5
	for _, fn := range optFns {
Packit Service 4d2de5
		fn(o)
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// DisableSSLOption sets the DisableSSL options. Can be used as a functional
Packit Service 4d2de5
// option when resolving endpoints.
Packit Service 4d2de5
func DisableSSLOption(o *Options) {
Packit Service 4d2de5
	o.DisableSSL = true
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// UseDualStackOption sets the UseDualStack option. Can be used as a functional
Packit Service 4d2de5
// option when resolving endpoints.
Packit Service 4d2de5
func UseDualStackOption(o *Options) {
Packit Service 4d2de5
	o.UseDualStack = true
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// StrictMatchingOption sets the StrictMatching option. Can be used as a functional
Packit Service 4d2de5
// option when resolving endpoints.
Packit Service 4d2de5
func StrictMatchingOption(o *Options) {
Packit Service 4d2de5
	o.StrictMatching = true
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// ResolveUnknownServiceOption sets the ResolveUnknownService option. Can be used
Packit Service 4d2de5
// as a functional option when resolving endpoints.
Packit Service 4d2de5
func ResolveUnknownServiceOption(o *Options) {
Packit Service 4d2de5
	o.ResolveUnknownService = true
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// STSRegionalEndpointOption enables the STS endpoint resolver behavior to resolve
Packit Service 4d2de5
// STS endpoint to their regional endpoint, instead of the global endpoint.
Packit Service 4d2de5
func STSRegionalEndpointOption(o *Options) {
Packit Service 4d2de5
	o.STSRegionalEndpoint = RegionalSTSEndpoint
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A Resolver provides the interface for functionality to resolve endpoints.
Packit Service 4d2de5
// The build in Partition and DefaultResolver return value satisfy this interface.
Packit Service 4d2de5
type Resolver interface {
Packit Service 4d2de5
	EndpointFor(service, region string, opts ...func(*Options)) (ResolvedEndpoint, error)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// ResolverFunc is a helper utility that wraps a function so it satisfies the
Packit Service 4d2de5
// Resolver interface. This is useful when you want to add additional endpoint
Packit Service 4d2de5
// resolving logic, or stub out specific endpoints with custom values.
Packit Service 4d2de5
type ResolverFunc func(service, region string, opts ...func(*Options)) (ResolvedEndpoint, error)
Packit Service 4d2de5
Packit Service 4d2de5
// EndpointFor wraps the ResolverFunc function to satisfy the Resolver interface.
Packit Service 4d2de5
func (fn ResolverFunc) EndpointFor(service, region string, opts ...func(*Options)) (ResolvedEndpoint, error) {
Packit Service 4d2de5
	return fn(service, region, opts...)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
var schemeRE = regexp.MustCompile("^([^:]+)://")
Packit Service 4d2de5
Packit Service 4d2de5
// AddScheme adds the HTTP or HTTPS schemes to a endpoint URL if there is no
Packit Service 4d2de5
// scheme. If disableSSL is true HTTP will set HTTP instead of the default HTTPS.
Packit Service 4d2de5
//
Packit Service 4d2de5
// If disableSSL is set, it will only set the URL's scheme if the URL does not
Packit Service 4d2de5
// contain a scheme.
Packit Service 4d2de5
func AddScheme(endpoint string, disableSSL bool) string {
Packit Service 4d2de5
	if !schemeRE.MatchString(endpoint) {
Packit Service 4d2de5
		scheme := "https"
Packit Service 4d2de5
		if disableSSL {
Packit Service 4d2de5
			scheme = "http"
Packit Service 4d2de5
		}
Packit Service 4d2de5
		endpoint = fmt.Sprintf("%s://%s", scheme, endpoint)
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return endpoint
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// EnumPartitions a provides a way to retrieve the underlying partitions that
Packit Service 4d2de5
// make up the SDK's default Resolver, or any resolver decoded from a model
Packit Service 4d2de5
// file.
Packit Service 4d2de5
//
Packit Service 4d2de5
// Use this interface with DefaultResolver and DecodeModels to get the list of
Packit Service 4d2de5
// Partitions.
Packit Service 4d2de5
type EnumPartitions interface {
Packit Service 4d2de5
	Partitions() []Partition
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// RegionsForService returns a map of regions for the partition and service.
Packit Service 4d2de5
// If either the partition or service does not exist false will be returned
Packit Service 4d2de5
// as the second parameter.
Packit Service 4d2de5
//
Packit Service 4d2de5
// This example shows how  to get the regions for DynamoDB in the AWS partition.
Packit Service 4d2de5
//    rs, exists := endpoints.RegionsForService(endpoints.DefaultPartitions(), endpoints.AwsPartitionID, endpoints.DynamodbServiceID)
Packit Service 4d2de5
//
Packit Service 4d2de5
// This is equivalent to using the partition directly.
Packit Service 4d2de5
//    rs := endpoints.AwsPartition().Services()[endpoints.DynamodbServiceID].Regions()
Packit Service 4d2de5
func RegionsForService(ps []Partition, partitionID, serviceID string) (map[string]Region, bool) {
Packit Service 4d2de5
	for _, p := range ps {
Packit Service 4d2de5
		if p.ID() != partitionID {
Packit Service 4d2de5
			continue
Packit Service 4d2de5
		}
Packit Service 4d2de5
		if _, ok := p.p.Services[serviceID]; !ok {
Packit Service 4d2de5
			break
Packit Service 4d2de5
		}
Packit Service 4d2de5
Packit Service 4d2de5
		s := Service{
Packit Service 4d2de5
			id: serviceID,
Packit Service 4d2de5
			p:  p.p,
Packit Service 4d2de5
		}
Packit Service 4d2de5
		return s.Regions(), true
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return map[string]Region{}, false
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// PartitionForRegion returns the first partition which includes the region
Packit Service 4d2de5
// passed in. This includes both known regions and regions which match
Packit Service 4d2de5
// a pattern supported by the partition which may include regions that are
Packit Service 4d2de5
// not explicitly known by the partition. Use the Regions method of the
Packit Service 4d2de5
// returned Partition if explicit support is needed.
Packit Service 4d2de5
func PartitionForRegion(ps []Partition, regionID string) (Partition, bool) {
Packit Service 4d2de5
	for _, p := range ps {
Packit Service 4d2de5
		if _, ok := p.p.Regions[regionID]; ok || p.p.RegionRegex.MatchString(regionID) {
Packit Service 4d2de5
			return p, true
Packit Service 4d2de5
		}
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return Partition{}, false
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A Partition provides the ability to enumerate the partition's regions
Packit Service 4d2de5
// and services.
Packit Service 4d2de5
type Partition struct {
Packit Service 4d2de5
	id, dnsSuffix string
Packit Service 4d2de5
	p             *partition
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// DNSSuffix returns the base domain name of the partition.
Packit Service 4d2de5
func (p Partition) DNSSuffix() string { return p.dnsSuffix }
Packit Service 4d2de5
Packit Service 4d2de5
// ID returns the identifier of the partition.
Packit Service 4d2de5
func (p Partition) ID() string { return p.id }
Packit Service 4d2de5
Packit Service 4d2de5
// EndpointFor attempts to resolve the endpoint based on service and region.
Packit Service 4d2de5
// See Options for information on configuring how the endpoint is resolved.
Packit Service 4d2de5
//
Packit Service 4d2de5
// If the service cannot be found in the metadata the UnknownServiceError
Packit Service 4d2de5
// error will be returned. This validation will occur regardless if
Packit Service 4d2de5
// StrictMatching is enabled. To enable resolving unknown services set the
Packit Service 4d2de5
// "ResolveUnknownService" option to true. When StrictMatching is disabled
Packit Service 4d2de5
// this option allows the partition resolver to resolve a endpoint based on
Packit Service 4d2de5
// the service endpoint ID provided.
Packit Service 4d2de5
//
Packit Service 4d2de5
// When resolving endpoints you can choose to enable StrictMatching. This will
Packit Service 4d2de5
// require the provided service and region to be known by the partition.
Packit Service 4d2de5
// If the endpoint cannot be strictly resolved an error will be returned. This
Packit Service 4d2de5
// mode is useful to ensure the endpoint resolved is valid. Without
Packit Service 4d2de5
// StrictMatching enabled the endpoint returned may look valid but may not work.
Packit Service 4d2de5
// StrictMatching requires the SDK to be updated if you want to take advantage
Packit Service 4d2de5
// of new regions and services expansions.
Packit Service 4d2de5
//
Packit Service 4d2de5
// Errors that can be returned.
Packit Service 4d2de5
//   * UnknownServiceError
Packit Service 4d2de5
//   * UnknownEndpointError
Packit Service 4d2de5
func (p Partition) EndpointFor(service, region string, opts ...func(*Options)) (ResolvedEndpoint, error) {
Packit Service 4d2de5
	return p.p.EndpointFor(service, region, opts...)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Regions returns a map of Regions indexed by their ID. This is useful for
Packit Service 4d2de5
// enumerating over the regions in a partition.
Packit Service 4d2de5
func (p Partition) Regions() map[string]Region {
Packit Service 4d2de5
	rs := map[string]Region{}
Packit Service 4d2de5
	for id, r := range p.p.Regions {
Packit Service 4d2de5
		rs[id] = Region{
Packit Service 4d2de5
			id:   id,
Packit Service 4d2de5
			desc: r.Description,
Packit Service 4d2de5
			p:    p.p,
Packit Service 4d2de5
		}
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return rs
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Services returns a map of Service indexed by their ID. This is useful for
Packit Service 4d2de5
// enumerating over the services in a partition.
Packit Service 4d2de5
func (p Partition) Services() map[string]Service {
Packit Service 4d2de5
	ss := map[string]Service{}
Packit Service 4d2de5
	for id := range p.p.Services {
Packit Service 4d2de5
		ss[id] = Service{
Packit Service 4d2de5
			id: id,
Packit Service 4d2de5
			p:  p.p,
Packit Service 4d2de5
		}
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return ss
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A Region provides information about a region, and ability to resolve an
Packit Service 4d2de5
// endpoint from the context of a region, given a service.
Packit Service 4d2de5
type Region struct {
Packit Service 4d2de5
	id, desc string
Packit Service 4d2de5
	p        *partition
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// ID returns the region's identifier.
Packit Service 4d2de5
func (r Region) ID() string { return r.id }
Packit Service 4d2de5
Packit Service 4d2de5
// Description returns the region's description. The region description
Packit Service 4d2de5
// is free text, it can be empty, and it may change between SDK releases.
Packit Service 4d2de5
func (r Region) Description() string { return r.desc }
Packit Service 4d2de5
Packit Service 4d2de5
// ResolveEndpoint resolves an endpoint from the context of the region given
Packit Service 4d2de5
// a service. See Partition.EndpointFor for usage and errors that can be returned.
Packit Service 4d2de5
func (r Region) ResolveEndpoint(service string, opts ...func(*Options)) (ResolvedEndpoint, error) {
Packit Service 4d2de5
	return r.p.EndpointFor(service, r.id, opts...)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Services returns a list of all services that are known to be in this region.
Packit Service 4d2de5
func (r Region) Services() map[string]Service {
Packit Service 4d2de5
	ss := map[string]Service{}
Packit Service 4d2de5
	for id, s := range r.p.Services {
Packit Service 4d2de5
		if _, ok := s.Endpoints[r.id]; ok {
Packit Service 4d2de5
			ss[id] = Service{
Packit Service 4d2de5
				id: id,
Packit Service 4d2de5
				p:  r.p,
Packit Service 4d2de5
			}
Packit Service 4d2de5
		}
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return ss
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A Service provides information about a service, and ability to resolve an
Packit Service 4d2de5
// endpoint from the context of a service, given a region.
Packit Service 4d2de5
type Service struct {
Packit Service 4d2de5
	id string
Packit Service 4d2de5
	p  *partition
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// ID returns the identifier for the service.
Packit Service 4d2de5
func (s Service) ID() string { return s.id }
Packit Service 4d2de5
Packit Service 4d2de5
// ResolveEndpoint resolves an endpoint from the context of a service given
Packit Service 4d2de5
// a region. See Partition.EndpointFor for usage and errors that can be returned.
Packit Service 4d2de5
func (s Service) ResolveEndpoint(region string, opts ...func(*Options)) (ResolvedEndpoint, error) {
Packit Service 4d2de5
	return s.p.EndpointFor(s.id, region, opts...)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Regions returns a map of Regions that the service is present in.
Packit Service 4d2de5
//
Packit Service 4d2de5
// A region is the AWS region the service exists in. Whereas a Endpoint is
Packit Service 4d2de5
// an URL that can be resolved to a instance of a service.
Packit Service 4d2de5
func (s Service) Regions() map[string]Region {
Packit Service 4d2de5
	rs := map[string]Region{}
Packit Service 4d2de5
	for id := range s.p.Services[s.id].Endpoints {
Packit Service 4d2de5
		if r, ok := s.p.Regions[id]; ok {
Packit Service 4d2de5
			rs[id] = Region{
Packit Service 4d2de5
				id:   id,
Packit Service 4d2de5
				desc: r.Description,
Packit Service 4d2de5
				p:    s.p,
Packit Service 4d2de5
			}
Packit Service 4d2de5
		}
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return rs
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// Endpoints returns a map of Endpoints indexed by their ID for all known
Packit Service 4d2de5
// endpoints for a service.
Packit Service 4d2de5
//
Packit Service 4d2de5
// A region is the AWS region the service exists in. Whereas a Endpoint is
Packit Service 4d2de5
// an URL that can be resolved to a instance of a service.
Packit Service 4d2de5
func (s Service) Endpoints() map[string]Endpoint {
Packit Service 4d2de5
	es := map[string]Endpoint{}
Packit Service 4d2de5
	for id := range s.p.Services[s.id].Endpoints {
Packit Service 4d2de5
		es[id] = Endpoint{
Packit Service 4d2de5
			id:        id,
Packit Service 4d2de5
			serviceID: s.id,
Packit Service 4d2de5
			p:         s.p,
Packit Service 4d2de5
		}
Packit Service 4d2de5
	}
Packit Service 4d2de5
Packit Service 4d2de5
	return es
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A Endpoint provides information about endpoints, and provides the ability
Packit Service 4d2de5
// to resolve that endpoint for the service, and the region the endpoint
Packit Service 4d2de5
// represents.
Packit Service 4d2de5
type Endpoint struct {
Packit Service 4d2de5
	id        string
Packit Service 4d2de5
	serviceID string
Packit Service 4d2de5
	p         *partition
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// ID returns the identifier for an endpoint.
Packit Service 4d2de5
func (e Endpoint) ID() string { return e.id }
Packit Service 4d2de5
Packit Service 4d2de5
// ServiceID returns the identifier the endpoint belongs to.
Packit Service 4d2de5
func (e Endpoint) ServiceID() string { return e.serviceID }
Packit Service 4d2de5
Packit Service 4d2de5
// ResolveEndpoint resolves an endpoint from the context of a service and
Packit Service 4d2de5
// region the endpoint represents. See Partition.EndpointFor for usage and
Packit Service 4d2de5
// errors that can be returned.
Packit Service 4d2de5
func (e Endpoint) ResolveEndpoint(opts ...func(*Options)) (ResolvedEndpoint, error) {
Packit Service 4d2de5
	return e.p.EndpointFor(e.serviceID, e.id, opts...)
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A ResolvedEndpoint is an endpoint that has been resolved based on a partition
Packit Service 4d2de5
// service, and region.
Packit Service 4d2de5
type ResolvedEndpoint struct {
Packit Service 4d2de5
	// The endpoint URL
Packit Service 4d2de5
	URL string
Packit Service 4d2de5
Packit Service 4d2de5
	// The endpoint partition
Packit Service 4d2de5
	PartitionID string
Packit Service 4d2de5
Packit Service 4d2de5
	// The region that should be used for signing requests.
Packit Service 4d2de5
	SigningRegion string
Packit Service 4d2de5
Packit Service 4d2de5
	// The service name that should be used for signing requests.
Packit Service 4d2de5
	SigningName string
Packit Service 4d2de5
Packit Service 4d2de5
	// States that the signing name for this endpoint was derived from metadata
Packit Service 4d2de5
	// passed in, but was not explicitly modeled.
Packit Service 4d2de5
	SigningNameDerived bool
Packit Service 4d2de5
Packit Service 4d2de5
	// The signing method that should be used for signing requests.
Packit Service 4d2de5
	SigningMethod string
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// So that the Error interface type can be included as an anonymous field
Packit Service 4d2de5
// in the requestError struct and not conflict with the error.Error() method.
Packit Service 4d2de5
type awsError awserr.Error
Packit Service 4d2de5
Packit Service 4d2de5
// A EndpointNotFoundError is returned when in StrictMatching mode, and the
Packit Service 4d2de5
// endpoint for the service and region cannot be found in any of the partitions.
Packit Service 4d2de5
type EndpointNotFoundError struct {
Packit Service 4d2de5
	awsError
Packit Service 4d2de5
	Partition string
Packit Service 4d2de5
	Service   string
Packit Service 4d2de5
	Region    string
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A UnknownServiceError is returned when the service does not resolve to an
Packit Service 4d2de5
// endpoint. Includes a list of all known services for the partition. Returned
Packit Service 4d2de5
// when a partition does not support the service.
Packit Service 4d2de5
type UnknownServiceError struct {
Packit Service 4d2de5
	awsError
Packit Service 4d2de5
	Partition string
Packit Service 4d2de5
	Service   string
Packit Service 4d2de5
	Known     []string
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// NewUnknownServiceError builds and returns UnknownServiceError.
Packit Service 4d2de5
func NewUnknownServiceError(p, s string, known []string) UnknownServiceError {
Packit Service 4d2de5
	return UnknownServiceError{
Packit Service 4d2de5
		awsError: awserr.New("UnknownServiceError",
Packit Service 4d2de5
			"could not resolve endpoint for unknown service", nil),
Packit Service 4d2de5
		Partition: p,
Packit Service 4d2de5
		Service:   s,
Packit Service 4d2de5
		Known:     known,
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// String returns the string representation of the error.
Packit Service 4d2de5
func (e UnknownServiceError) Error() string {
Packit Service 4d2de5
	extra := fmt.Sprintf("partition: %q, service: %q",
Packit Service 4d2de5
		e.Partition, e.Service)
Packit Service 4d2de5
	if len(e.Known) > 0 {
Packit Service 4d2de5
		extra += fmt.Sprintf(", known: %v", e.Known)
Packit Service 4d2de5
	}
Packit Service 4d2de5
	return awserr.SprintError(e.Code(), e.Message(), extra, e.OrigErr())
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// String returns the string representation of the error.
Packit Service 4d2de5
func (e UnknownServiceError) String() string {
Packit Service 4d2de5
	return e.Error()
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// A UnknownEndpointError is returned when in StrictMatching mode and the
Packit Service 4d2de5
// service is valid, but the region does not resolve to an endpoint. Includes
Packit Service 4d2de5
// a list of all known endpoints for the service.
Packit Service 4d2de5
type UnknownEndpointError struct {
Packit Service 4d2de5
	awsError
Packit Service 4d2de5
	Partition string
Packit Service 4d2de5
	Service   string
Packit Service 4d2de5
	Region    string
Packit Service 4d2de5
	Known     []string
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// NewUnknownEndpointError builds and returns UnknownEndpointError.
Packit Service 4d2de5
func NewUnknownEndpointError(p, s, r string, known []string) UnknownEndpointError {
Packit Service 4d2de5
	return UnknownEndpointError{
Packit Service 4d2de5
		awsError: awserr.New("UnknownEndpointError",
Packit Service 4d2de5
			"could not resolve endpoint", nil),
Packit Service 4d2de5
		Partition: p,
Packit Service 4d2de5
		Service:   s,
Packit Service 4d2de5
		Region:    r,
Packit Service 4d2de5
		Known:     known,
Packit Service 4d2de5
	}
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// String returns the string representation of the error.
Packit Service 4d2de5
func (e UnknownEndpointError) Error() string {
Packit Service 4d2de5
	extra := fmt.Sprintf("partition: %q, service: %q, region: %q",
Packit Service 4d2de5
		e.Partition, e.Service, e.Region)
Packit Service 4d2de5
	if len(e.Known) > 0 {
Packit Service 4d2de5
		extra += fmt.Sprintf(", known: %v", e.Known)
Packit Service 4d2de5
	}
Packit Service 4d2de5
	return awserr.SprintError(e.Code(), e.Message(), extra, e.OrigErr())
Packit Service 4d2de5
}
Packit Service 4d2de5
Packit Service 4d2de5
// String returns the string representation of the error.
Packit Service 4d2de5
func (e UnknownEndpointError) String() string {
Packit Service 4d2de5
	return e.Error()
Packit Service 4d2de5
}