endpoints.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package configsources
  2. import (
  3. "context"
  4. )
  5. // ServiceBaseEndpointProvider is needed to search for all providers
  6. // that provide a configured service endpoint
  7. type ServiceBaseEndpointProvider interface {
  8. GetServiceBaseEndpoint(ctx context.Context, sdkID string) (string, bool, error)
  9. }
  10. // IgnoreConfiguredEndpointsProvider is needed to search for all providers
  11. // that provide a flag to disable configured endpoints.
  12. //
  13. // Currently duplicated from github.com/aws/aws-sdk-go-v2/config because
  14. // service packages cannot import github.com/aws/aws-sdk-go-v2/config
  15. // due to result import cycle error.
  16. type IgnoreConfiguredEndpointsProvider interface {
  17. GetIgnoreConfiguredEndpoints(ctx context.Context) (bool, bool, error)
  18. }
  19. // GetIgnoreConfiguredEndpoints is used in knowing when to disable configured
  20. // endpoints feature.
  21. //
  22. // Currently duplicated from github.com/aws/aws-sdk-go-v2/config because
  23. // service packages cannot import github.com/aws/aws-sdk-go-v2/config
  24. // due to result import cycle error.
  25. func GetIgnoreConfiguredEndpoints(ctx context.Context, configs []any) (value bool, found bool, err error) {
  26. for _, cfg := range configs {
  27. if p, ok := cfg.(IgnoreConfiguredEndpointsProvider); ok {
  28. value, found, err = p.GetIgnoreConfiguredEndpoints(ctx)
  29. if err != nil || found {
  30. break
  31. }
  32. }
  33. }
  34. return
  35. }
  36. // ResolveServiceBaseEndpoint is used to retrieve service endpoints from configured sources
  37. // while allowing for configured endpoints to be disabled
  38. func ResolveServiceBaseEndpoint(ctx context.Context, sdkID string, configs []any) (value string, found bool, err error) {
  39. if val, found, _ := GetIgnoreConfiguredEndpoints(ctx, configs); found && val {
  40. return "", false, nil
  41. }
  42. for _, cs := range configs {
  43. if p, ok := cs.(ServiceBaseEndpointProvider); ok {
  44. value, found, err = p.GetServiceBaseEndpoint(context.Background(), sdkID)
  45. if err != nil || found {
  46. break
  47. }
  48. }
  49. }
  50. return
  51. }