code.dwrz.net

Go monorepo.
Log | Files | Refs

endpoints.go (8863B)


      1 package aws
      2 
      3 import (
      4 	"fmt"
      5 )
      6 
      7 // DualStackEndpointState is a constant to describe the dual-stack endpoint resolution behavior.
      8 type DualStackEndpointState uint
      9 
     10 const (
     11 	// DualStackEndpointStateUnset is the default value behavior for dual-stack endpoint resolution.
     12 	DualStackEndpointStateUnset DualStackEndpointState = iota
     13 
     14 	// DualStackEndpointStateEnabled enables dual-stack endpoint resolution for service endpoints.
     15 	DualStackEndpointStateEnabled
     16 
     17 	// DualStackEndpointStateDisabled disables dual-stack endpoint resolution for endpoints.
     18 	DualStackEndpointStateDisabled
     19 )
     20 
     21 // GetUseDualStackEndpoint takes a service's EndpointResolverOptions and returns the UseDualStackEndpoint value.
     22 // Returns boolean false if the provided options does not have a method to retrieve the DualStackEndpointState.
     23 func GetUseDualStackEndpoint(options ...interface{}) (value DualStackEndpointState, found bool) {
     24 	type iface interface {
     25 		GetUseDualStackEndpoint() DualStackEndpointState
     26 	}
     27 	for _, option := range options {
     28 		if i, ok := option.(iface); ok {
     29 			value = i.GetUseDualStackEndpoint()
     30 			found = true
     31 			break
     32 		}
     33 	}
     34 	return value, found
     35 }
     36 
     37 // FIPSEndpointState is a constant to describe the FIPS endpoint resolution behavior.
     38 type FIPSEndpointState uint
     39 
     40 const (
     41 	// FIPSEndpointStateUnset is the default value behavior for FIPS endpoint resolution.
     42 	FIPSEndpointStateUnset FIPSEndpointState = iota
     43 
     44 	// FIPSEndpointStateEnabled enables FIPS endpoint resolution for service endpoints.
     45 	FIPSEndpointStateEnabled
     46 
     47 	// FIPSEndpointStateDisabled disables FIPS endpoint resolution for endpoints.
     48 	FIPSEndpointStateDisabled
     49 )
     50 
     51 // GetUseFIPSEndpoint takes a service's EndpointResolverOptions and returns the UseDualStackEndpoint value.
     52 // Returns boolean false if the provided options does not have a method to retrieve the DualStackEndpointState.
     53 func GetUseFIPSEndpoint(options ...interface{}) (value FIPSEndpointState, found bool) {
     54 	type iface interface {
     55 		GetUseFIPSEndpoint() FIPSEndpointState
     56 	}
     57 	for _, option := range options {
     58 		if i, ok := option.(iface); ok {
     59 			value = i.GetUseFIPSEndpoint()
     60 			found = true
     61 			break
     62 		}
     63 	}
     64 	return value, found
     65 }
     66 
     67 // Endpoint represents the endpoint a service client should make API operation
     68 // calls to.
     69 //
     70 // The SDK will automatically resolve these endpoints per API client using an
     71 // internal endpoint resolvers. If you'd like to provide custom endpoint
     72 // resolving behavior you can implement the EndpointResolver interface.
     73 type Endpoint struct {
     74 	// The base URL endpoint the SDK API clients will use to make API calls to.
     75 	// The SDK will suffix URI path and query elements to this endpoint.
     76 	URL string
     77 
     78 	// Specifies if the endpoint's hostname can be modified by the SDK's API
     79 	// client.
     80 	//
     81 	// If the hostname is mutable the SDK API clients may modify any part of
     82 	// the hostname based on the requirements of the API, (e.g. adding, or
     83 	// removing content in the hostname). Such as, Amazon S3 API client
     84 	// prefixing "bucketname" to the hostname, or changing the
     85 	// hostname service name component from "s3." to "s3-accesspoint.dualstack."
     86 	// for the dualstack endpoint of an S3 Accesspoint resource.
     87 	//
     88 	// Care should be taken when providing a custom endpoint for an API. If the
     89 	// endpoint hostname is mutable, and the client cannot modify the endpoint
     90 	// correctly, the operation call will most likely fail, or have undefined
     91 	// behavior.
     92 	//
     93 	// If hostname is immutable, the SDK API clients will not modify the
     94 	// hostname of the URL. This may cause the API client not to function
     95 	// correctly if the API requires the operation specific hostname values
     96 	// to be used by the client.
     97 	//
     98 	// This flag does not modify the API client's behavior if this endpoint
     99 	// will be used instead of Endpoint Discovery, or if the endpoint will be
    100 	// used to perform Endpoint Discovery. That behavior is configured via the
    101 	// API Client's Options.
    102 	HostnameImmutable bool
    103 
    104 	// The AWS partition the endpoint belongs to.
    105 	PartitionID string
    106 
    107 	// The service name that should be used for signing the requests to the
    108 	// endpoint.
    109 	SigningName string
    110 
    111 	// The region that should be used for signing the request to the endpoint.
    112 	SigningRegion string
    113 
    114 	// The signing method that should be used for signing the requests to the
    115 	// endpoint.
    116 	SigningMethod string
    117 
    118 	// The source of the Endpoint. By default, this will be EndpointSourceServiceMetadata.
    119 	// When providing a custom endpoint, you should set the source as EndpointSourceCustom.
    120 	// If source is not provided when providing a custom endpoint, the SDK may not
    121 	// perform required host mutations correctly. Source should be used along with
    122 	// HostnameImmutable property as per the usage requirement.
    123 	Source EndpointSource
    124 }
    125 
    126 // EndpointSource is the endpoint source type.
    127 type EndpointSource int
    128 
    129 const (
    130 	// EndpointSourceServiceMetadata denotes service modeled endpoint metadata is used as Endpoint Source.
    131 	EndpointSourceServiceMetadata EndpointSource = iota
    132 
    133 	// EndpointSourceCustom denotes endpoint is a custom endpoint. This source should be used when
    134 	// user provides a custom endpoint to be used by the SDK.
    135 	EndpointSourceCustom
    136 )
    137 
    138 // EndpointNotFoundError is a sentinel error to indicate that the
    139 // EndpointResolver implementation was unable to resolve an endpoint for the
    140 // given service and region. Resolvers should use this to indicate that an API
    141 // client should fallback and attempt to use it's internal default resolver to
    142 // resolve the endpoint.
    143 type EndpointNotFoundError struct {
    144 	Err error
    145 }
    146 
    147 // Error is the error message.
    148 func (e *EndpointNotFoundError) Error() string {
    149 	return fmt.Sprintf("endpoint not found, %v", e.Err)
    150 }
    151 
    152 // Unwrap returns the underlying error.
    153 func (e *EndpointNotFoundError) Unwrap() error {
    154 	return e.Err
    155 }
    156 
    157 // EndpointResolver is an endpoint resolver that can be used to provide or
    158 // override an endpoint for the given service and region. API clients will
    159 // attempt to use the EndpointResolver first to resolve an endpoint if
    160 // available. If the EndpointResolver returns an EndpointNotFoundError error,
    161 // API clients will fallback to attempting to resolve the endpoint using its
    162 // internal default endpoint resolver.
    163 //
    164 // Deprecated: See EndpointResolverWithOptions
    165 type EndpointResolver interface {
    166 	ResolveEndpoint(service, region string) (Endpoint, error)
    167 }
    168 
    169 // EndpointResolverFunc wraps a function to satisfy the EndpointResolver interface.
    170 //
    171 // Deprecated: See EndpointResolverWithOptionsFunc
    172 type EndpointResolverFunc func(service, region string) (Endpoint, error)
    173 
    174 // ResolveEndpoint calls the wrapped function and returns the results.
    175 //
    176 // Deprecated: See EndpointResolverWithOptions.ResolveEndpoint
    177 func (e EndpointResolverFunc) ResolveEndpoint(service, region string) (Endpoint, error) {
    178 	return e(service, region)
    179 }
    180 
    181 // EndpointResolverWithOptions is an endpoint resolver that can be used to provide or
    182 // override an endpoint for the given service, region, and the service client's EndpointOptions. API clients will
    183 // attempt to use the EndpointResolverWithOptions first to resolve an endpoint if
    184 // available. If the EndpointResolverWithOptions returns an EndpointNotFoundError error,
    185 // API clients will fallback to attempting to resolve the endpoint using its
    186 // internal default endpoint resolver.
    187 type EndpointResolverWithOptions interface {
    188 	ResolveEndpoint(service, region string, options ...interface{}) (Endpoint, error)
    189 }
    190 
    191 // EndpointResolverWithOptionsFunc wraps a function to satisfy the EndpointResolverWithOptions interface.
    192 type EndpointResolverWithOptionsFunc func(service, region string, options ...interface{}) (Endpoint, error)
    193 
    194 // ResolveEndpoint calls the wrapped function and returns the results.
    195 func (e EndpointResolverWithOptionsFunc) ResolveEndpoint(service, region string, options ...interface{}) (Endpoint, error) {
    196 	return e(service, region, options...)
    197 }
    198 
    199 // GetDisableHTTPS takes a service's EndpointResolverOptions and returns the DisableHTTPS value.
    200 // Returns boolean false if the provided options does not have a method to retrieve the DisableHTTPS.
    201 func GetDisableHTTPS(options ...interface{}) (value bool, found bool) {
    202 	type iface interface {
    203 		GetDisableHTTPS() bool
    204 	}
    205 	for _, option := range options {
    206 		if i, ok := option.(iface); ok {
    207 			value = i.GetDisableHTTPS()
    208 			found = true
    209 			break
    210 		}
    211 	}
    212 	return value, found
    213 }
    214 
    215 // GetResolvedRegion takes a service's EndpointResolverOptions and returns the ResolvedRegion value.
    216 // Returns boolean false if the provided options does not have a method to retrieve the ResolvedRegion.
    217 func GetResolvedRegion(options ...interface{}) (value string, found bool) {
    218 	type iface interface {
    219 		GetResolvedRegion() string
    220 	}
    221 	for _, option := range options {
    222 		if i, ok := option.(iface); ok {
    223 			value = i.GetResolvedRegion()
    224 			found = true
    225 			break
    226 		}
    227 	}
    228 	return value, found
    229 }