Skip to content

Commit

Permalink
internal/endpoints: Add support for FIPS global partition endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
skmcgrail committed Apr 26, 2021
1 parent 6f28a0e commit 04abb4b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ func (p Partition) canResolveEndpoint(region string) bool {

// ResolveEndpoint resolves and service endpoint for the given region and options.
func (p Partition) ResolveEndpoint(region string, options Options) (resolved aws.Endpoint, err error) {
e, _ := p.endpointForRegion(region)

if len(region) == 0 && len(p.PartitionEndpoint) != 0 {
region = p.PartitionEndpoint
}

e, _ := p.endpointForRegion(region)

return e.resolve(p.ID, region, p.Defaults, options), nil
}

func (p Partition) endpointForRegion(region string) (Endpoint, bool) {
if !p.IsRegionalized {
return p.Endpoints[p.PartitionEndpoint], region == p.PartitionEndpoint
}

if e, ok := p.Endpoints[region]; ok {
return e, true
}

if !p.IsRegionalized {
return p.Endpoints[p.PartitionEndpoint], region == p.PartitionEndpoint
}

// Unable to find any matching endpoint, return
// blank that will be used for generic endpoint creation.
return Endpoint{}, false
Expand Down
26 changes: 26 additions & 0 deletions internal/endpoints/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ var testPartitions = Partitions{
Region: "cn-east-1",
},
},
"fips-partition": {
Hostname: "some-global-thing-fips.amazonaws.com.cn",
CredentialScope: CredentialScope{
Region: "cn-east-1",
},
},
},
},
{
Expand Down Expand Up @@ -182,6 +188,26 @@ func TestResolveEndpoint(t *testing.T) {
SigningMethod: "v4",
},
},
"specified partition endpoint": {
Region: "partition",
Expected: aws.Endpoint{
PartitionID: "part-id-2",
URL: "https://some-global-thing.amazonaws.com.cn",
SigningRegion: "cn-east-1",
SigningName: "foo",
SigningMethod: "v4",
},
},
"fips partition endpoint": {
Region: "fips-partition",
Expected: aws.Endpoint{
PartitionID: "part-id-2",
URL: "https://some-global-thing-fips.amazonaws.com.cn",
SigningRegion: "cn-east-1",
SigningName: "foo",
SigningMethod: "v4",
},
},
"region with unmodeled endpoints": {
Region: "eu-west-1",
Expected: aws.Endpoint{
Expand Down

0 comments on commit 04abb4b

Please sign in to comment.