-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate ecs-init to aws-sdk-go-v2 #4372
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ecae8a2
ec2metadata --> imds
tinnywang 2aee22b
s3
tinnywang 73cb27f
generate partitions
tinnywang fa913b8
remove endpoints package
tinnywang 0e6c735
implement our own GetPartition
tinnywang 6b18caa
cleanup go.mod
tinnywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
go generate
copies this AWS SDK file from vendor into our package.