Skip to content

Commit a2d0ef0

Browse files
committed
expand to all active aws regions
1 parent 46f59a2 commit a2d0ef0

File tree

9 files changed

+151
-124
lines changed

9 files changed

+151
-124
lines changed

cmd/archeio/internal/app/buckets.go

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,112 @@ func awsRegionToHostURL(region, defaultURL string) string {
3333
// and then additional regions we're mapping to that bucket
3434
// based roughly on physical adjacency (and therefore _presumed_ latency)
3535
//
36-
// if you add a bucket, add a case for the region it is in, and consider
37-
// shifting other regions that do not have their own bucket
36+
// As of late 2025, we don't have access to cn-northwest-1 or cn-north-1 regions as they are part of the aws-cn partition.
37+
// So we are mapping them to ap-east-1(Hong Kong) for now.
38+
// aws ec2 describe-regions --all-regions --query "Regions[].RegionName" --output json | jq .[] | awk '{print $0","}' | sort --version-sort
3839

40+
// Africa (Cape Town)
41+
case "af-south-1":
42+
return "https://prod-registry-k8s-io-af-south-1.s3.dualstack.af-south-1.amazonaws.com"
43+
// Asia Pacific (Hong Kong) and China Regions
44+
case "ap-east-1", "cn-northwest-1", "cn-north-1":
45+
return "https://prod-registry-k8s-io-ap-east-1.s3.dualstack.ap-east-1.amazonaws.com"
46+
// Asia Pacific (Taipei)
47+
case "ap-east-2":
48+
return "https://prod-registry-k8s-io-ap-east-1.s3.dualstack.ap-east-1.amazonaws.com"
49+
// Asia Pacific (Tokyo)
50+
case "ap-northeast-1":
51+
return "https://prod-registry-k8s-io-ap-northeast-1.s3.dualstack.ap-northeast-1.amazonaws.com"
52+
// Asia Pacific (Seoul)
53+
case "ap-northeast-2":
54+
return "https://prod-registry-k8s-io-ap-northeast-2.s3.dualstack.ap-northeast-2.amazonaws.com"
55+
// Asia Pacific (Osaka)
56+
case "ap-northeast-3":
57+
return "https://prod-registry-k8s-io-ap-northeast-3.s3.dualstack.ap-northeast-3.amazonaws.com"
58+
// Asia Pacific (Singapore)
59+
case "ap-southeast-1":
60+
return "https://prod-registry-k8s-io-ap-southeast-1.s3.dualstack.ap-southeast-1.amazonaws.com"
61+
// Asia Pacific (Sydney)
62+
case "ap-southeast-2":
63+
return "https://prod-registry-k8s-io-ap-southeast-2.s3.dualstack.ap-southeast-2.amazonaws.com"
64+
// Asia Pacific (Jakarta)
65+
case "ap-southeast-3":
66+
return "https://prod-registry-k8s-io-ap-southeast-3.s3.dualstack.ap-southeast-3.amazonaws.com"
67+
// Asia Pacific (Melbourne)
68+
case "ap-southeast-4":
69+
return "https://prod-registry-k8s-io-ap-southeast-4.s3.dualstack.ap-southeast-4.amazonaws.com"
70+
// Asia Pacific (Singapore)
71+
case "ap-southeast-5":
72+
return "https://prod-registry-k8s-io-ap-southeast-5.s3.dualstack.ap-southeast-5.amazonaws.com"
73+
// Asia Pacific (New Zealand)
74+
case "ap-southeast-6":
75+
return "https://prod-registry-k8s-io-ap-southeast-6.s3.dualstack.ap-southeast-6.amazonaws.com"
76+
// Asia Pacific (Thailand)
77+
case "ap-southeast-7":
78+
return "https://prod-registry-k8s-io-ap-southeast-7.s3.dualstack.ap-southeast-7.amazonaws.com"
79+
// Asia Pacific (Mumbai)
80+
case "ap-south-1":
81+
return "https://prod-registry-k8s-io-ap-south-1.s3.dualstack.ap-south-1.amazonaws.com"
82+
// Asia Pacific (Hyderabad)
83+
case "ap-south-2":
84+
return "https://prod-registry-k8s-io-ap-south-2.s3.dualstack.ap-south-2.amazonaws.com"
85+
// Canada (Central)
86+
case "ca-central-1":
87+
return "https://prod-registry-k8s-io-ca-central-1.s3.dualstack.ca-central-1.amazonaws.com"
88+
// Canada (Calgary)
89+
case "ca-west-1":
90+
return "https://prod-registry-k8s-io-ca-west-1.s3.dualstack.ca-west-1.amazonaws.com"
91+
// Europe (Frankfurt)
92+
case "eu-central-1":
93+
return "https://prod-registry-k8s-io-eu-central-1.s3.dualstack.eu-central-1.amazonaws.com"
94+
// Europe (Zurich)
95+
case "eu-central-2":
96+
return "https://prod-registry-k8s-io-eu-central-2.s3.dualstack.eu-central-2.amazonaws.com"
97+
// Europe (Stockholm)
98+
case "eu-north-1":
99+
return "https://prod-registry-k8s-io-eu-north-1.s3.dualstack.eu-north-1.amazonaws.com"
100+
// Europe (Milan)
101+
case "eu-south-1":
102+
return "https://prod-registry-k8s-io-eu-south-1.s3.dualstack.eu-south-1.amazonaws.com"
103+
// Europe (Spain)
104+
case "eu-south-2":
105+
return "https://prod-registry-k8s-io-eu-south-2.s3.dualstack.eu-south-2.amazonaws.com"
106+
// Europe (Ireland)
107+
case "eu-west-1":
108+
return "https://prod-registry-k8s-io-eu-west-1.s3.dualstack.eu-west-1.amazonaws.com"
109+
// Europe (London)
110+
case "eu-west-2":
111+
return "https://prod-registry-k8s-io-eu-west-2.s3.dualstack.eu-west-2.amazonaws.com"
112+
// Europe (Paris)
113+
case "eu-west-3":
114+
return "https://prod-registry-k8s-io-eu-west-3.s3.dualstack.eu-west-3.amazonaws.com"
115+
// Israel (Tel Aviv)
116+
case "il-central-1":
117+
return "https://prod-registry-k8s-io-il-central-1.s3.dualstack.il-central-1.amazonaws.com"
118+
// Middle East (UAE)
119+
case "me-central-1":
120+
return "https://prod-registry-k8s-io-me-central-1.s3.dualstack.me-central-1.amazonaws.com"
121+
// Middle East (Bahrain)
122+
case "me-south-1":
123+
return "https://prod-registry-k8s-io-me-south-1.s3.dualstack.me-south-1.amazonaws.com"
124+
// Mexico (Central)
125+
case "mx-central-1":
126+
return "https://prod-registry-k8s-io-mx-central-1.s3.dualstack.mx-central-1.amazonaws.com"
127+
// South America (São Paulo)
128+
case "sa-east-1":
129+
return "https://prod-registry-k8s-io-sa-east-1.s3.dualstack.sa-east-1.amazonaws.com"
39130
// US East (N. Virginia)
40-
case "us-east-1", "sa-east-1", "mx-central-1":
131+
case "us-east-1":
41132
return "https://prod-registry-k8s-io-us-east-1.s3.dualstack.us-east-1.amazonaws.com"
42133
// US East (Ohio)
43-
case "us-east-2", "ca-central-1":
134+
case "us-east-2":
44135
return "https://prod-registry-k8s-io-us-east-2.s3.dualstack.us-east-2.amazonaws.com"
45136
// US West (N. California)
46137
case "us-west-1":
47138
return "https://prod-registry-k8s-io-us-west-1.s3.dualstack.us-west-1.amazonaws.com"
48139
// US West (Oregon)
49-
case "us-west-2", "ca-west-1":
140+
case "us-west-2":
50141
return "https://prod-registry-k8s-io-us-west-2.s3.dualstack.us-west-2.amazonaws.com"
51-
// Asia Pacific (Mumbai)
52-
case "ap-south-1", "ap-south-2", "me-south-1", "me-central-1", "me-west-1":
53-
return "https://prod-registry-k8s-io-ap-south-1.s3.dualstack.ap-south-1.amazonaws.com"
54-
// Asia Pacific (Tokyo)
55-
case "ap-northeast-1", "ap-northeast-2", "ap-northeast-3":
56-
return "https://prod-registry-k8s-io-ap-northeast-1.s3.dualstack.ap-northeast-1.amazonaws.com"
57-
// Asia Pacific (Singapore)
58-
case "ap-southeast-1", "ap-southeast-2", "ap-southeast-3", "ap-southeast-4", "ap-southeast-5", "ap-southeast-6", "ap-southeast-7", "ap-east-1", "ap-east-2", "cn-northwest-1", "cn-north-1":
59-
return "https://prod-registry-k8s-io-ap-southeast-1.s3.dualstack.ap-southeast-1.amazonaws.com"
60-
// Europe (Frankfurt)
61-
case "eu-central-1", "eu-central-2", "eu-south-1", "eu-south-2", "il-central-1":
62-
return "https://prod-registry-k8s-io-eu-central-1.s3.dualstack.eu-central-1.amazonaws.com"
63-
// Europe (Ireland)
64-
case "eu-west-1", "af-south-1", "eu-west-2", "eu-west-3", "eu-north-1":
65-
return "https://prod-registry-k8s-io-eu-west-1.s3.dualstack.eu-west-1.amazonaws.com"
66142
default:
67143
return defaultURL
68144
}

cmd/archeio/internal/app/handlers_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
func TestMakeHandler(t *testing.T) {
2727
registryConfig := RegistryConfig{
2828
// the v2 test below tests being redirected to k8s.gcr.io as that one doesn't have UpstreamRegistryPath
29-
UpstreamRegistryEndpoint: "https://us.gcr.io",
30-
UpstreamRegistryPath: "k8s-artifacts-prod",
29+
UpstreamRegistryEndpoint: "https://us-central1-docker.pkg.dev",
30+
UpstreamRegistryPath: "k8s-artifacts-prod/images",
3131
InfoURL: "https://github.com/kubernetes/k8s.io/tree/main/registry.k8s.io",
3232
PrivacyURL: "https://www.linuxfoundation.org/privacy-policy/",
3333
}
@@ -79,23 +79,23 @@ func TestMakeHandler(t *testing.T) {
7979
Name: "/v2/pause/manifests/latest",
8080
Request: httptest.NewRequest("GET", "http://localhost:8080/v2/pause/manifests/latest", nil),
8181
ExpectedStatus: http.StatusTemporaryRedirect,
82-
ExpectedURL: "https://us.gcr.io/v2/k8s-artifacts-prod/pause/manifests/latest",
82+
ExpectedURL: "https://us-central1-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/manifests/latest",
8383
},
8484
{
8585
Name: "/v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
8686
Request: httptest.NewRequest("GET", "http://localhost:8080/v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e", nil),
8787
ExpectedStatus: http.StatusTemporaryRedirect,
88-
ExpectedURL: "https://us.gcr.io/v2/k8s-artifacts-prod/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
88+
ExpectedURL: "https://us-central1-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
8989
},
9090
{
91-
Name: "AWS IP, /v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
91+
Name: "AWS eu-west-3 IP, /v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
9292
Request: func() *http.Request {
9393
r := httptest.NewRequest("GET", "http://localhost:8080/v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e", nil)
9494
r.RemoteAddr = "35.180.1.1:888"
9595
return r
9696
}(),
9797
ExpectedStatus: http.StatusTemporaryRedirect,
98-
ExpectedURL: "https://prod-registry-k8s-io-eu-west-1.s3.dualstack.eu-west-1.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
98+
ExpectedURL: "https://prod-registry-k8s-io-eu-west-3.s3.dualstack.eu-west-3.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
9999
},
100100
{
101101
Name: "GCP IP, /v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
@@ -105,7 +105,7 @@ func TestMakeHandler(t *testing.T) {
105105
return r
106106
}(),
107107
ExpectedStatus: http.StatusTemporaryRedirect,
108-
ExpectedURL: "https://us.gcr.io/v2/k8s-artifacts-prod/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
108+
ExpectedURL: "https://us-central1-docker.pkg.dev/v2/k8s-artifacts-prod/images/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
109109
},
110110
}
111111
for i := range testCases {
@@ -164,6 +164,7 @@ func TestMakeV2Handler(t *testing.T) {
164164
"https://prod-registry-k8s-io-ap-southeast-1.s3.dualstack.ap-southeast-1.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
165165
"https://prod-registry-k8s-io-eu-central-1.s3.dualstack.eu-central-1.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
166166
"https://prod-registry-k8s-io-eu-west-1.s3.dualstack.eu-west-1.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
167+
"https://prod-registry-k8s-io-eu-west-3.s3.dualstack.eu-west-3.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
167168
"https://prod-registry-k8s-io-us-east-1.s3.dualstack.us-east-2.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
168169
"https://prod-registry-k8s-io-us-east-2.s3.dualstack.us-east-2.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
169170
"https://prod-registry-k8s-io-us-west-1.s3.dualstack.us-west-1.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e": true,
@@ -210,23 +211,23 @@ func TestMakeV2Handler(t *testing.T) {
210211
ExpectedStatus: http.StatusNotFound,
211212
},
212213
{
213-
Name: "AWS IP, /v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
214+
Name: "AWS eu-west-3 IP, /v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
214215
Request: func() *http.Request {
215216
r := httptest.NewRequest("GET", "http://localhost:8080/v2/pause/blobs/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e", nil)
216217
r.RemoteAddr = "35.180.1.1:888"
217218
return r
218219
}(),
219220
ExpectedStatus: http.StatusTemporaryRedirect,
220-
ExpectedURL: "https://prod-registry-k8s-io-eu-west-1.s3.dualstack.eu-west-1.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
221+
ExpectedURL: "https://prod-registry-k8s-io-eu-west-3.s3.dualstack.eu-west-3.amazonaws.com/containers/images/sha256:da86e6ba6ca197bf6bc5e9d900febd906b133eaa4750e6bed647b0fbe50ed43e",
221222
},
222223
{
223-
Name: "AWS IP, /v2/pause/manifests/latest",
224+
Name: "Fetching image manifest, /v2/pause/manifests/latest",
224225
Request: httptest.NewRequest("GET", "http://localhost:8080/v2/pause/manifests/latest", nil),
225226
ExpectedStatus: http.StatusTemporaryRedirect,
226227
ExpectedURL: "https://k8s.gcr.io/v2/pause/manifests/latest",
227228
},
228229
{
229-
Name: "AWS IP, /v2/pause/blobs/sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1234567",
230+
Name: "AWS eu-west-3 IP, /v2/pause/blobs/sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1234567",
230231
Request: func() *http.Request {
231232
r := httptest.NewRequest("GET", "http://localhost:8080/v2/pause/blobs/sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1234567", nil)
232233
r.RemoteAddr = "35.180.1.1:888"

hack/make-rules/codegen.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ echo "Downloading AWS & GCP IP ranges data..."
2727
curl -fLo 'pkg/net/cloudcidrs/internal/ranges2go/data/aws-ip-ranges.json' 'https://ip-ranges.amazonaws.com/ip-ranges.json'
2828
curl -fLo 'pkg/net/cloudcidrs/internal/ranges2go/data/gcp-cloud.json' 'https://www.gstatic.com/ipranges/cloud.json'
2929

30-
go generate ./...
30+
# AWS adds IP ranges for unreleased regions which we want to exclude
31+
EXCLUDED_AWS_REGIONS="me-west-1,sa-west-1" \
32+
OUT_FILE=pkg/net/cloudcidrs/zz_generated_range_data.go \
33+
DATA_DIR=pkg/net/cloudcidrs/internal/ranges2go/data \
34+
go run ./pkg/net/cloudcidrs/internal/ranges2go

hack/make-rules/verify-generated.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ trap 'rm -rf ${tmpdir?}' EXIT
2828
# generate and compare
2929
OUT_FILE="${tmpdir}"/zz_generated_range_data.go
3030
export OUT_FILE
31-
DATA_DIR="${REPO_ROOT}"/pkg/net/cloudcidrs/internal/ranges2go/data
32-
export DATA_DIR
33-
go run ./pkg/net/cloudcidrs/internal/ranges2go
31+
# keep excluded list in sync with hack/make-rules/codegen.sh
32+
EXCLUDED_AWS_REGIONS="me-west-1,sa-west-1" \
33+
DATA_DIR="${REPO_ROOT}"/pkg/net/cloudcidrs/internal/ranges2go/data \
34+
go run ./pkg/net/cloudcidrs/internal/ranges2go
3435

3536
if ! diff "${OUT_FILE}" ./pkg/net/cloudcidrs/zz_generated_range_data.go; then
3637
>&2 echo ""

pkg/net/cloudcidrs/internal/ranges2go/gen_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ func TestGenerateRangesGo(t *testing.T) {
5050
"region": "me-south-1",
5151
"service": "AMAZON",
5252
"network_border_group": "me-south-1"
53+
},
54+
{
55+
"ip_prefix": "79.107.7.136/29",
56+
"region": "me-south-10",
57+
"service": "AMAZON",
58+
"network_border_group": "me-south-10"
5359
}
5460
],
5561
"ipv6_prefixes": [
@@ -76,11 +82,17 @@ func TestGenerateRangesGo(t *testing.T) {
7682
"region": "eu-south-1",
7783
"service": "AMAZON",
7884
"network_border_group": "eu-south-1"
85+
},
86+
{
87+
"ipv6_prefix": "2a06:d03a:a000::/56",
88+
"region": "eu-south-10",
89+
"service": "AMAZON",
90+
"network_border_group": "eu-south-10"
7991
}
8092
]
8193
}
8294
`
83-
awsRTP, err := parseAWS(rawAWSData)
95+
awsRTP, err := parseAWS(rawAWSData, []string{"me-south-10", "eu-south-10"})
8496
if err != nil {
8597
t.Fatalf("unexpected error parsing test data: %v", err)
8698
}

pkg/net/cloudcidrs/internal/ranges2go/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ limitations under the License.
1919
package main
2020

2121
import (
22+
"fmt"
2223
"os"
2324
"path/filepath"
25+
"strings"
2426
)
2527

2628
func main() {
2729
// overridable for make verify
2830
outputPath := os.Getenv("OUT_FILE")
2931
dataDir := os.Getenv("DATA_DIR")
32+
excludedAWSRegions := strings.Split(os.Getenv("EXCLUDED_AWS_REGIONS"), ",")
33+
if len(excludedAWSRegions) > 0 {
34+
fmt.Printf("Please make sure the following excluded AWS regions are added after they have been released: %v", excludedAWSRegions)
35+
}
3036
if outputPath == "" {
3137
outputPath = "./zz_generated_range_data.go"
3238
}
@@ -37,7 +43,7 @@ func main() {
3743
awsRaw := mustReadFile(filepath.Join(dataDir, "aws-ip-ranges.json"))
3844
gcpRaw := mustReadFile(filepath.Join(dataDir, "gcp-cloud.json"))
3945
// parse raw AWS IP range data
40-
awsRTP, err := parseAWS(awsRaw)
46+
awsRTP, err := parseAWS(awsRaw, excludedAWSRegions)
4147
if err != nil {
4248
panic(err)
4349
}

pkg/net/cloudcidrs/internal/ranges2go/parse_aws.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@ package main
1919
import (
2020
"encoding/json"
2121
"net/netip"
22+
"slices"
2223
"sort"
2324
)
2425

2526
// parseAWS parses raw AWS IP ranges JSON data
2627
// and processes it to a regionsToPrefixes map
27-
func parseAWS(raw string) (regionsToPrefixes, error) {
28+
func parseAWS(raw string, excludedRegions []string) (regionsToPrefixes, error) {
2829
parsed, err := parseAWSIPRangesJSON([]byte(raw))
2930
if err != nil {
3031
return nil, err
3132
}
32-
return awsRegionsToPrefixesFromData(parsed)
33+
return awsRegionsToPrefixesFromData(parsed, excludedRegions)
3334
}
3435

3536
/*
3637
For more on these datatypes see:
37-
https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html
38+
https://docs.aws.amazon.com/vpc/latest/userguide/aws-ip-ranges.html
3839
*/
3940

4041
type AWSIPRangesJSON struct {
@@ -68,7 +69,7 @@ func parseAWSIPRangesJSON(rawJSON []byte) (*AWSIPRangesJSON, error) {
6869
}
6970

7071
// awsRegionsToPrefixesFromData processes the raw unmarshalled JSON into regionsToPrefixes map
71-
func awsRegionsToPrefixesFromData(data *AWSIPRangesJSON) (regionsToPrefixes, error) {
72+
func awsRegionsToPrefixesFromData(data *AWSIPRangesJSON, excludedRegions []string) (regionsToPrefixes, error) {
7273
// convert from AWS published structure to a map by region, parse Prefixes
7374
rtp := regionsToPrefixes{}
7475
for _, prefix := range data.Prefixes {
@@ -77,6 +78,9 @@ func awsRegionsToPrefixesFromData(data *AWSIPRangesJSON) (regionsToPrefixes, err
7778
if err != nil {
7879
return nil, err
7980
}
81+
if slices.Contains(excludedRegions, region) {
82+
continue
83+
}
8084
rtp[region] = append(rtp[region], ipPrefix)
8185
}
8286
for _, prefix := range data.IPv6Prefixes {
@@ -85,6 +89,9 @@ func awsRegionsToPrefixesFromData(data *AWSIPRangesJSON) (regionsToPrefixes, err
8589
if err != nil {
8690
return nil, err
8791
}
92+
if slices.Contains(excludedRegions, region) {
93+
continue
94+
}
8895
rtp[region] = append(rtp[region], ipPrefix)
8996
}
9097

pkg/net/cloudcidrs/internal/ranges2go/parse_aws_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestAWSRegionsToPrefixesFromData(t *testing.T) {
9090
},
9191
},
9292
}
93-
_, err := awsRegionsToPrefixesFromData(badV4Prefixes)
93+
_, err := awsRegionsToPrefixesFromData(badV4Prefixes, nil)
9494
if err == nil {
9595
t.Fatal("expected error parsing bogus prefix but got none")
9696
}
@@ -113,7 +113,7 @@ func TestAWSRegionsToPrefixesFromData(t *testing.T) {
113113
},
114114
},
115115
}
116-
_, err := awsRegionsToPrefixesFromData(badV6Prefixes)
116+
_, err := awsRegionsToPrefixesFromData(badV6Prefixes, nil)
117117
if err == nil {
118118
t.Fatal("expected error parsing bogus prefix but got none")
119119
}
@@ -124,7 +124,7 @@ func TestParseAWS(t *testing.T) {
124124
t.Run("unparsable data", func(t *testing.T) {
125125
t.Parallel()
126126
badJSON := `{"prefixes":false}`
127-
_, err := parseAWS(badJSON)
127+
_, err := parseAWS(badJSON, nil)
128128
if err == nil {
129129
t.Fatal("expected error parsing bogus raw JSON but got none")
130130
}

0 commit comments

Comments
 (0)