Skip to content

Commit

Permalink
Replace 'internal/endpoints' with top-level 'endpoints' package.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Sep 17, 2024
1 parent 1b1dd67 commit 94d0344
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 176 deletions.
6 changes: 4 additions & 2 deletions aws_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/aws/aws-sdk-go-v2/feature/ec2/imds"
"github.com/aws/smithy-go/middleware"
"github.com/hashicorp/aws-sdk-go-base/v2/diag"
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
"github.com/hashicorp/aws-sdk-go-base/v2/internal/awsconfig"
"github.com/hashicorp/aws-sdk-go-base/v2/internal/constants"
"github.com/hashicorp/aws-sdk-go-base/v2/internal/endpoints"
"github.com/hashicorp/aws-sdk-go-base/v2/logging"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -337,7 +337,9 @@ func GetAwsAccountIDAndPartition(ctx context.Context, awsConfig aws.Config, c *C
"Errors: %w", err))
}

return "", endpoints.PartitionForRegion(awsConfig.Region), nil
partition, _ := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), awsConfig.Region)

return "", partition.ID(), nil
}

func commonLoadOptions(ctx context.Context, c *Config) ([]func(*config.LoadOptions) error, error) {
Expand Down
129 changes: 0 additions & 129 deletions internal/endpoints/endpoints.go

This file was deleted.

37 changes: 0 additions & 37 deletions internal/endpoints/endpoints_test.go

This file was deleted.

16 changes: 8 additions & 8 deletions validation/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ package validation

import (
"fmt"
"slices"

"github.com/hashicorp/aws-sdk-go-base/v2/internal/endpoints"
"github.com/hashicorp/aws-sdk-go-base/v2/endpoints"
)

type InvalidRegionError struct {
region string
}

func (e *InvalidRegionError) Error() string {
return fmt.Sprintf("Invalid AWS Region: %s", e.region)
return fmt.Sprintf("invalid AWS Region: %s", e.region)
}

// SupportedRegion checks if the given region is a valid AWS region.
func SupportedRegion(region string) error {
for _, partition := range endpoints.Partitions() {
for _, partitionRegion := range partition.Regions() {
if region == partitionRegion {
return nil
}
}
if slices.ContainsFunc(endpoints.DefaultPartitions(), func(p endpoints.Partition) bool {
_, ok := p.Regions()[region]
return ok
}) {
return nil
}

return &InvalidRegionError{
Expand Down

0 comments on commit 94d0344

Please sign in to comment.