-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
partitions.go
133 lines (121 loc) · 3.74 KB
/
partitions.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
129
130
131
132
133
package v1alpha5
import "fmt"
// Partitions.
const (
PartitionAWS = "aws"
PartitionChina = "aws-cn"
PartitionUSGov = "aws-us-gov"
PartitionISO = "aws-iso"
PartitionISOB = "aws-iso-b"
)
// partition is an AWS partition.
type partition struct {
name string
serviceMappings map[string]string
regions []string
endpointServiceDomainPrefix string
}
type partitions []partition
var standardServiceMappings = map[string]string{
"EC2": "ec2.amazonaws.com",
"EKS": "eks.amazonaws.com",
"EKSFargatePods": "eks-fargate-pods.amazonaws.com",
}
const standardPartitionServiceDomainPrefix = "com.amazonaws"
var awsPartition = partition{
name: PartitionAWS,
serviceMappings: standardServiceMappings,
endpointServiceDomainPrefix: standardPartitionServiceDomainPrefix,
}
// Partitions is a list of supported AWS partitions.
var Partitions = partitions{
awsPartition,
{
name: PartitionUSGov,
serviceMappings: standardServiceMappings,
regions: []string{RegionUSGovEast1, RegionUSGovWest1},
endpointServiceDomainPrefix: standardPartitionServiceDomainPrefix,
},
{
name: PartitionChina,
serviceMappings: map[string]string{
"EC2": "ec2.amazonaws.com.cn",
"EKS": "eks.amazonaws.com",
"EKSFargatePods": "eks-fargate-pods.amazonaws.com",
},
regions: []string{RegionCNNorth1, RegionCNNorthwest1},
endpointServiceDomainPrefix: fmt.Sprintf("cn.%s", standardPartitionServiceDomainPrefix),
},
{
name: PartitionISO,
serviceMappings: map[string]string{
"EC2": "ec2.c2s.ic.gov",
"EKS": "eks.amazonaws.com",
"EKSFargatePods": "eks-fargate-pods.amazonaws.com",
},
regions: []string{RegionUSISOEast1, RegionUSISOWest1},
endpointServiceDomainPrefix: "gov.ic.c2s",
},
{
name: PartitionISOB,
serviceMappings: map[string]string{
"EC2": "ec2.sc2s.sgov.gov",
"EKS": "eks.amazonaws.com",
"EKSFargatePods": "eks-fargate-pods.amazonaws.com",
},
regions: []string{RegionUSISOBEast1},
endpointServiceDomainPrefix: "gov.sgov.sc2s",
},
}
// ForRegion returns the partition a region belongs to.
func (p partitions) ForRegion(region string) string {
for _, pt := range p {
for _, r := range pt.regions {
if r == region {
return pt.name
}
}
}
return PartitionAWS
}
// GetEndpointServiceDomainPrefix returns the domain prefix for the endpoint service.
func (p partitions) GetEndpointServiceDomainPrefix(endpointService EndpointService, region string) string {
for _, pt := range p {
for _, r := range pt.regions {
if r == region {
switch pt.name {
case PartitionChina:
if endpointService.RequiresChinaPrefix {
return pt.endpointServiceDomainPrefix
}
return standardPartitionServiceDomainPrefix
case PartitionISO, PartitionISOB:
if endpointService.RequiresISOPrefix {
return pt.endpointServiceDomainPrefix
}
return standardPartitionServiceDomainPrefix
default:
return pt.endpointServiceDomainPrefix
}
}
}
}
return awsPartition.endpointServiceDomainPrefix
}
// IsSupported returns true if the partition is supported.
func (p partitions) IsSupported(partition string) bool {
for _, pt := range p {
if pt.name == partition {
return true
}
}
return false
}
// ServicePrincipalPartitionMappings returns the service principal partition mappings for all supported partitions.
func (p partitions) ServicePrincipalPartitionMappings() map[string]map[string]string {
ret := make(map[string]map[string]string, len(p))
for _, pt := range p {
ret[pt.name] = pt.serviceMappings
}
return ret
}