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