endpoints.go 8.7 KB

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