resolver.go 1.6 KB

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