-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate ecs-init to aws-sdk-go-v2 (#4372)
- Loading branch information
Showing
817 changed files
with
165,506 additions
and
130,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package awsrulesfn | ||
|
||
import "regexp" | ||
|
||
// Partition provides the metadata describing an AWS partition. | ||
type Partition struct { | ||
ID string `json:"id"` | ||
Regions map[string]RegionOverrides `json:"regions"` | ||
RegionRegex string `json:"regionRegex"` | ||
DefaultConfig PartitionConfig `json:"outputs"` | ||
} | ||
|
||
// PartitionConfig provides the endpoint metadata for an AWS region or partition. | ||
type PartitionConfig struct { | ||
Name string `json:"name"` | ||
DnsSuffix string `json:"dnsSuffix"` | ||
DualStackDnsSuffix string `json:"dualStackDnsSuffix"` | ||
SupportsFIPS bool `json:"supportsFIPS"` | ||
SupportsDualStack bool `json:"supportsDualStack"` | ||
ImplicitGlobalRegion string `json:"implicitGlobalRegion"` | ||
} | ||
|
||
type RegionOverrides struct { | ||
Name *string `json:"name"` | ||
DnsSuffix *string `json:"dnsSuffix"` | ||
DualStackDnsSuffix *string `json:"dualStackDnsSuffix"` | ||
SupportsFIPS *bool `json:"supportsFIPS"` | ||
SupportsDualStack *bool `json:"supportsDualStack"` | ||
} | ||
|
||
const defaultPartition = "aws" | ||
|
||
func getPartition(partitions []Partition, region string) *PartitionConfig { | ||
for _, partition := range partitions { | ||
if v, ok := partition.Regions[region]; ok { | ||
p := mergeOverrides(partition.DefaultConfig, v) | ||
return &p | ||
} | ||
} | ||
|
||
for _, partition := range partitions { | ||
regionRegex := regexp.MustCompile(partition.RegionRegex) | ||
if regionRegex.MatchString(region) { | ||
v := partition.DefaultConfig | ||
return &v | ||
} | ||
} | ||
|
||
for _, partition := range partitions { | ||
if partition.ID == defaultPartition { | ||
v := partition.DefaultConfig | ||
return &v | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func mergeOverrides(into PartitionConfig, from RegionOverrides) PartitionConfig { | ||
if from.Name != nil { | ||
into.Name = *from.Name | ||
} | ||
if from.DnsSuffix != nil { | ||
into.DnsSuffix = *from.DnsSuffix | ||
} | ||
if from.DualStackDnsSuffix != nil { | ||
into.DualStackDnsSuffix = *from.DualStackDnsSuffix | ||
} | ||
if from.SupportsFIPS != nil { | ||
into.SupportsFIPS = *from.SupportsFIPS | ||
} | ||
if from.SupportsDualStack != nil { | ||
into.SupportsDualStack = *from.SupportsDualStack | ||
} | ||
return into | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package awsrulesfn | ||
|
||
import "regexp" | ||
|
||
// aws-sdk-go-v2 does not export partition metadata, so copy the files from vendor to make it accessible. | ||
|
||
//go:generate cp ../../vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partition.go ../../vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partitions.go . | ||
|
||
// GetPartitionForRegion returns an AWS partition for the region provided. | ||
// Unlike GetPartition, this function | ||
// 1. returns a Partition instead of a PartitionConfig | ||
// 2. returns nil instead of falling back to the default partition (aws) if no match is found | ||
func GetPartitionForRegion(region string) *Partition { | ||
for _, partition := range partitions { | ||
if _, ok := partition.Regions[region]; ok { | ||
return &partition | ||
} | ||
|
||
regionRegex := regexp.MustCompile(partition.RegionRegex) | ||
if regionRegex.MatchString(region) { | ||
return &partition | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.