Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pkg/asset/installconfig/aws/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/efs"
elb "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi"
"github.com/aws/aws-sdk-go-v2/service/route53"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/servicequotas"
Expand Down Expand Up @@ -176,3 +178,50 @@ func NewS3Client(ctx context.Context, endpointOpts EndpointOptions, optFns ...fu

return s3.NewFromConfig(cfg, s3Opts...), nil
}

// NewEFSClient creates a new EFS API client.
func NewEFSClient(ctx context.Context, endpointOpts EndpointOptions, optFns ...func(*efs.Options)) (*efs.Client, error) {
cfg, err := GetConfigWithOptions(ctx, config.WithRegion(endpointOpts.Region))
if err != nil {
return nil, err
}

efsOpts := []func(*efs.Options){
func(o *efs.Options) {
o.EndpointResolverV2 = &EFSEndpointResolver{
ServiceEndpointResolver: NewServiceEndpointResolver(endpointOpts),
}
},
}
efsOpts = append(efsOpts, optFns...)

return efs.NewFromConfig(cfg, efsOpts...), nil
}

// NewResourceGroupsTaggingAPIClient creates a new Resource Groups Tagging API client.
func NewResourceGroupsTaggingAPIClient(ctx context.Context, endpointOpts EndpointOptions, roleArn string, optFns ...func(*resourcegroupstaggingapi.Options)) (*resourcegroupstaggingapi.Client, error) {
cfg, err := GetConfigWithOptions(ctx, config.WithRegion(endpointOpts.Region))
if err != nil {
return nil, err
}

if len(roleArn) > 0 {
stsClient, err := NewSTSClient(ctx, endpointOpts)
if err != nil {
return nil, err
}
creds := stscreds.NewAssumeRoleProvider(stsClient, roleArn)
cfg.Credentials = aws.NewCredentialsCache(creds)
}

taggingOpts := []func(*resourcegroupstaggingapi.Options){
func(o *resourcegroupstaggingapi.Options) {
o.EndpointResolverV2 = &ResourceGroupsTaggingAPIEndpointResolver{
ServiceEndpointResolver: NewServiceEndpointResolver(endpointOpts),
}
},
}
taggingOpts = append(taggingOpts, optFns...)

return resourcegroupstaggingapi.NewFromConfig(cfg, taggingOpts...), nil
}
44 changes: 44 additions & 0 deletions pkg/asset/installconfig/aws/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/efs"
elb "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
elbv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2"
"github.com/aws/aws-sdk-go-v2/service/iam"
Expand All @@ -28,6 +29,7 @@ var (
// For backwards compatibility, we copy those constants from the SDK v1 and map it to ServiceID in SDK v2.
compatServiceIDMap = map[string]string{
"ec2": ec2.ServiceID,
"elasticfilesystem": efs.ServiceID,
"elasticloadbalancing": elb.ServiceID,
"iam": iam.ServiceID,
"route53": route53.ServiceID,
Expand Down Expand Up @@ -269,6 +271,48 @@ func (s *S3EndpointResolver) ResolveEndpoint(ctx context.Context, params s3.Endp
return s3.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

// EFSEndpointResolver implements EndpointResolverV2 interface for EFS.
type EFSEndpointResolver struct {
*ServiceEndpointResolver
}

// ResolveEndpoint for EFS.
func (s *EFSEndpointResolver) ResolveEndpoint(ctx context.Context, params efs.EndpointParameters) (smithyendpoints.Endpoint, error) {
params.UseDualStack = aws.Bool(s.endpointOptions.UseDualStack)
params.UseFIPS = aws.Bool(s.endpointOptions.UseFIPS)

// If custom endpoint not found, return default endpoint for the service.
endpoint, ok := s.endpoints[efs.ServiceID]
if !ok {
return efs.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

params.Endpoint = aws.String(endpoint.URL)
params.Region = aws.String(s.endpointOptions.Region)
return efs.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

// ResourceGroupsTaggingAPIEndpointResolver implements EndpointResolverV2 interface for Resource Groups Tagging API.
type ResourceGroupsTaggingAPIEndpointResolver struct {
*ServiceEndpointResolver
}

// ResolveEndpoint for Resource Groups Tagging API.
func (s *ResourceGroupsTaggingAPIEndpointResolver) ResolveEndpoint(ctx context.Context, params resourcegroupstaggingapi.EndpointParameters) (smithyendpoints.Endpoint, error) {
params.UseDualStack = aws.Bool(s.endpointOptions.UseDualStack)
params.UseFIPS = aws.Bool(s.endpointOptions.UseFIPS)

// If custom endpoint not found, return default endpoint for the service.
endpoint, ok := s.endpoints[resourcegroupstaggingapi.ServiceID]
if !ok {
return resourcegroupstaggingapi.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

params.Endpoint = aws.String(endpoint.URL)
params.Region = aws.String(s.endpointOptions.Region)
return resourcegroupstaggingapi.NewDefaultEndpointResolverV2().ResolveEndpoint(ctx, params)
}

// GetDefaultServiceEndpoint will get the default service endpoint for a service and region.
// Note: This uses the v1 EndpointResolver, which exposes the partition ID.
func GetDefaultServiceEndpoint(ctx context.Context, service string, opts EndpointOptions) (aws.Endpoint, error) { //nolint: staticcheck
Expand Down
4 changes: 4 additions & 0 deletions pkg/asset/installconfig/aws/sessionv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const (
// when gather command is invoked.
OpenShiftInstallerGatherUserAgent = "OpenShift/4.x Gather"

// OpenShiftInstallerDestroyerUserAgent is the User Agent key to add to the AWS API request header
// when destroy command is invoked.
OpenShiftInstallerDestroyerUserAgent = "OpenShift/4.x Destroyer"

// RetryMaxAttempts is the total number of times an API request is retried.
RetryMaxAttempts = 25

Expand Down
Loading