-
Notifications
You must be signed in to change notification settings - Fork 36
/
endpoints.go
128 lines (118 loc) · 3.26 KB
/
endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package endpoints
import (
"regexp"
)
func Partitions() []Partition {
ps := make([]Partition, len(partitions))
for i := 0; i < len(partitions); i++ {
ps[i] = partitions[i].Partition()
}
return ps
}
type Partition struct {
id string
p *partition
}
func (p Partition) Regions() []string {
rs := make([]string, len(p.p.regions))
copy(rs, p.p.regions)
return rs
}
func PartitionForRegion(regionID string) string {
for _, p := range partitions {
if p.regionRegex.MatchString(regionID) {
return p.id
}
}
return ""
}
type partition struct {
id string
regionRegex *regexp.Regexp
regions []string
}
func (p partition) Partition() Partition {
return Partition{
id: p.id,
p: &p,
}
}
// TODO: this should be generated from the AWS SDK source data
// Data from https://github.com/aws/aws-sdk-go/blob/main/models/endpoints/endpoints.json.
var partitions = []partition{
{
id: "aws",
regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il)\-\w+\-\d+$`),
regions: []string{
"af-south-1", // Africa (Cape Town).
"ap-east-1", // Asia Pacific (Hong Kong).
"ap-northeast-1", // Asia Pacific (Tokyo).
"ap-northeast-2", // Asia Pacific (Seoul).
"ap-northeast-3", // Asia Pacific (Osaka).
"ap-south-1", // Asia Pacific (Mumbai).
"ap-south-2", // Asia Pacific (Hyderabad).
"ap-southeast-1", // Asia Pacific (Singapore).
"ap-southeast-2", // Asia Pacific (Sydney).
"ap-southeast-3", // Asia Pacific (Jakarta).
"ap-southeast-4", // Asia Pacific (Melbourne).
"ca-central-1", // Canada (Central).
"ca-west-1", // Canada (Calgary).
"eu-central-1", // Europe (Frankfurt).
"eu-central-2", // Europe (Zurich).
"eu-north-1", // Europe (Stockholm).
"eu-south-1", // Europe (Milan).
"eu-south-2", // Europe (Spain).
"eu-west-1", // Europe (Ireland).
"eu-west-2", // Europe (London).
"eu-west-3", // Europe (Paris).
"il-central-1", // Israel (Tel Aviv).
"me-central-1", // Middle East (UAE).
"me-south-1", // Middle East (Bahrain).
"sa-east-1", // South America (Sao Paulo).
"us-east-1", // US East (N. Virginia).
"us-east-2", // US East (Ohio).
"us-west-1", // US West (N. California).
"us-west-2", // US West (Oregon).
},
},
{
id: "aws-cn",
regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`),
regions: []string{
"cn-north-1", // China (Beijing).
"cn-northwest-1", // China (Ningxia).
},
},
{
id: "aws-us-gov",
regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`),
regions: []string{
"us-gov-east-1", // AWS GovCloud (US-East).
"us-gov-west-1", // AWS GovCloud (US-West).
},
},
{
id: "aws-iso",
regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`),
regions: []string{
"us-iso-east-1", // US ISO East.
"us-iso-west-1", // US ISO WEST.
},
},
{
id: "aws-iso-b",
regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`),
regions: []string{
"us-isob-east-1", // US ISOB East (Ohio).
},
},
{
id: "aws-iso-e",
regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`),
regions: []string{
"eu-isoe-west-1", // EU ISOE West.
},
},
}