resolver.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 auth
  14. import (
  15. "context"
  16. "fmt"
  17. "net/url"
  18. "os"
  19. "github.com/aws/aws-sdk-go-v2/service/sts"
  20. smithyendpoints "github.com/aws/smithy-go/endpoints"
  21. )
  22. const (
  23. STSEndpointEnv = "AWS_STS_ENDPOINT"
  24. )
  25. type customEndpointResolver struct{}
  26. // ResolveEndpoint returns a ResolverFunc with
  27. // customizable endpoints.
  28. // should this reside somewhere else since it's specific to sts?
  29. func (c customEndpointResolver) ResolveEndpoint(ctx context.Context, params sts.EndpointParameters) (smithyendpoints.Endpoint, error) {
  30. endpoint := smithyendpoints.Endpoint{}
  31. if v := os.Getenv(STSEndpointEnv); v != "" {
  32. url, err := url.Parse(v)
  33. if err != nil {
  34. return endpoint, fmt.Errorf("failed to parse sts endpoint %s: %w", v, err)
  35. }
  36. endpoint.URI = *url
  37. return endpoint, nil
  38. }
  39. defaultResolver := sts.NewDefaultEndpointResolverV2()
  40. return defaultResolver.ResolveEndpoint(ctx, params)
  41. }