Skip to content

Commit

Permalink
update linode region check with new page
Browse files Browse the repository at this point in the history
  • Loading branch information
sa7mon committed Sep 8, 2024
1 parent bfe9bc2 commit 7149ff2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions cmd/regioncheck/regioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,18 @@ func GetRegionsDO() ([]string, error) {
// GetRegionsLinode fetches region names from Linode docs HTML page. Linode also provides this info via
// unauthenticated API (https://api.linode.com/v4/regions) but the region names do not include the trailing digit "-1".
func GetRegionsLinode() ([]string, error) {
requestURL := "https://www.linode.com/docs/products/storage/object-storage/"
res, err := http.Get(requestURL)
requestURL := "https://techdocs.akamai.com/cloud-computing/docs/object-storage"

req, err := http.NewRequest("GET", requestURL, nil)
if err != nil {
return nil, err
}
// server drops requests if user agent is set to the default go-http-client:
// `HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)`
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")

client := &http.Client{}
res, err := client.Do(req)
if err != nil {
return nil, err
}
Expand All @@ -95,7 +105,7 @@ func GetRegionsLinode() ([]string, error) {
}

regions := []string{}
doc.Find("h2#availability ~ div:nth-of-type(1) table tbody tr td:nth-of-type(2)").Each(func(i int, t *goquery.Selection) {
doc.Find(".rdmd-table:nth-of-type(1) tbody tr td:nth-of-type(2)").Each(func(i int, t *goquery.Selection) {
regions = append(regions, t.Text())
})

Expand Down
2 changes: 1 addition & 1 deletion cmd/regioncheck/regioncheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestGetRegionsDO(t *testing.T) {
func TestGetRegionsLinode(t *testing.T) {
r, err := GetRegionsLinode()
assert.Nil(t, err)
assert.GreaterOrEqual(t, len(r), 1)
assert.Equal(t, len(r), 18)
assert.Contains(t, r, "us-east-1")
}

Expand Down

0 comments on commit 7149ff2

Please sign in to comment.