resolver.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 parameterstore
  14. import (
  15. "context"
  16. "fmt"
  17. "net/url"
  18. "os"
  19. "github.com/aws/aws-sdk-go-v2/service/ssm"
  20. smithyendpoints "github.com/aws/smithy-go/endpoints"
  21. )
  22. // SSMEndpointEnv is the environment variable to use for Parameter Store endpoint.
  23. const SSMEndpointEnv = "AWS_SSM_ENDPOINT"
  24. // customEndpointResolver is a custom resolver for AWS Parameter Store endpoint.
  25. type customEndpointResolver struct{}
  26. // ResolveEndpoint resolves the endpoint for the Parameter Store service.
  27. func (c customEndpointResolver) ResolveEndpoint(ctx context.Context, params ssm.EndpointParameters) (smithyendpoints.Endpoint, error) {
  28. endpoint := smithyendpoints.Endpoint{}
  29. if v := os.Getenv(SSMEndpointEnv); v != "" {
  30. url, err := url.Parse(v)
  31. if err != nil {
  32. return endpoint, fmt.Errorf("failed to parse ssm endpoint %s: %w", v, err)
  33. }
  34. endpoint.URI = *url
  35. return endpoint, nil
  36. }
  37. defaultResolver := ssm.NewDefaultEndpointResolverV2()
  38. return defaultResolver.ResolveEndpoint(ctx, params)
  39. }