resolver.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package secretsmanager
  13. import (
  14. "context"
  15. "fmt"
  16. "net/url"
  17. "os"
  18. "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
  19. smithyendpoints "github.com/aws/smithy-go/endpoints"
  20. )
  21. const (
  22. SecretsManagerEndpointEnv = "AWS_SECRETSMANAGER_ENDPOINT"
  23. )
  24. type customEndpointResolver struct{}
  25. // ResolveEndpoint returns a ResolverFunc with
  26. // customizable endpoints.
  27. func (c customEndpointResolver) ResolveEndpoint(ctx context.Context, params secretsmanager.EndpointParameters) (smithyendpoints.Endpoint, error) {
  28. endpoint := smithyendpoints.Endpoint{}
  29. if v := os.Getenv(SecretsManagerEndpointEnv); v != "" {
  30. url, err := url.Parse(v)
  31. if err != nil {
  32. return endpoint, fmt.Errorf("failed to parse secretsmanager endpoint %s: %w", v, err)
  33. }
  34. endpoint.URI = *url
  35. return endpoint, nil
  36. }
  37. defaultResolver := secretsmanager.NewDefaultEndpointResolverV2()
  38. return defaultResolver.ResolveEndpoint(ctx, params)
  39. }