This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
87 lines (76 loc) · 1.89 KB
/
main.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
package main
import (
"fmt"
"os"
"sort"
"strings"
"golang.org/x/exp/maps"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/sts"
)
// product returns the cartesion product of given lists
func product[T any](lists ...[]T) [][]T {
result := [][]T{{}}
for _, pool := range lists {
var newResult [][]T
for _, x := range result {
for _, y := range pool {
temp := append([]T{}, x...)
temp = append(temp, y)
newResult = append(newResult, temp)
}
}
result = newResult
}
return result
}
func stsEndpoints() []string {
nullOption := func(*endpoints.Options) {}
// Generate all combinations of endpoint resolution options with one choice
// from each layer.
layers := [][]func(*endpoints.Options){
{
endpoints.StrictMatchingOption,
},
{
nullOption,
endpoints.STSRegionalEndpointOption,
},
{
nullOption,
endpoints.UseFIPSEndpointOption,
endpoints.UseDualStackEndpointOption,
},
}
allOptions := product(layers...)
endpointsSet := make(map[string]struct{})
for _, partition := range endpoints.DefaultPartitions() {
for region := range partition.Regions() {
for _, opts := range allOptions {
endpoint, err := partition.EndpointFor(sts.ServiceName, region, opts...)
if err != nil {
// Likely there's no fips or dualstack endpoint for this region.
continue
}
endpointsSet[strings.TrimPrefix(endpoint.URL, "https://")] = struct{}{}
}
}
}
endpointsSlice := maps.Keys(endpointsSet)
sort.Strings(endpointsSlice)
return endpointsSlice
}
func main() {
if len(os.Args) > 1 && (os.Args[1] == "--help" || os.Args[1] != "--go-list" || len(os.Args) > 2) {
fmt.Printf("usage: %s [--go-list]\n", os.Args[0])
return
}
formatGoList := len(os.Args) == 2 && os.Args[1] == "--go-list"
for _, e := range stsEndpoints() {
if formatGoList {
fmt.Println(`"` + e + `",`)
} else {
fmt.Println(e)
}
}
}