-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpartition.go
72 lines (58 loc) · 1.74 KB
/
partition.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package endpoints
import (
"maps"
"regexp"
)
// Partition represents an AWS partition.
// See https://docs.aws.amazon.com/whitepapers/latest/aws-fault-isolation-boundaries/partitions.html.
type Partition struct {
id string
name string
dnsSuffix string
regionRegex *regexp.Regexp
regions map[string]Region
services map[string]Service
}
// ID returns the identifier of the partition.
func (p Partition) ID() string {
return p.id
}
// Name returns the name of the partition.
func (p Partition) Name() string {
return p.name
}
// DNSSuffix returns the base domain name of the partition.
func (p Partition) DNSSuffix() string {
return p.dnsSuffix
}
// RegionRegex return the regular expression that matches Region IDs for the partition.
func (p Partition) RegionRegex() *regexp.Regexp {
return p.regionRegex
}
// Regions returns a map of Regions for the partition, indexed by their ID.
func (p Partition) Regions() map[string]Region {
return maps.Clone(p.regions)
}
// Services returns a map of service endpoints for the partition, indexed by their ID.
func (p Partition) Services() map[string]Service {
return maps.Clone(p.services)
}
// DefaultPartitions returns a list of the partitions.
func DefaultPartitions() []Partition {
ps := make([]Partition, 0, len(partitions))
for _, p := range partitions {
ps = append(ps, p)
}
return ps
}
// PartitionForRegion returns the first partition which includes the specific Region.
func PartitionForRegion(ps []Partition, regionID string) (Partition, bool) {
for _, p := range ps {
if _, ok := p.regions[regionID]; ok || p.regionRegex.MatchString(regionID) {
return p, true
}
}
return Partition{}, false
}