Skip to content

feat: Add Huawei Cloud IP range fetcher#121

Merged
JasonLovesDoggo merged 2 commits intomainfrom
feat/huaweifetcher
Dec 25, 2025
Merged

feat: Add Huawei Cloud IP range fetcher#121
JasonLovesDoggo merged 2 commits intomainfrom
feat/huaweifetcher

Conversation

@JasonLovesDoggo
Copy link
Copy Markdown
Owner

Closes #97

Copilot AI review requested due to automatic review settings December 25, 2025 04:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for fetching Huawei Cloud IP ranges by implementing a new HuaweiCloudFetcher that scrapes CIDR blocks from networksdb.io. The implementation follows the established pattern used by other fetchers in the codebase.

Key Changes

  • New HuaweiCloudFetcher implementation that extracts IP ranges using regex pattern matching on HTML content
  • Integration of the fetcher into the main fetcher list
  • Generated data file updated with 97 Huawei Cloud CIDR blocks

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
ranges/fetchers/huawei.go New fetcher implementation using HTTP GET and regex to extract CIDR blocks from HTML
ranges/main.go Added HuaweiCloudFetcher to the list of active fetchers with appropriate comment
ranges/data/generated.go Generated data file updated with Huawei Cloud IP ranges and other provider updates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return nil, fmt.Errorf("failed to read Huawei Cloud response body: %v", err)
}

// Extract CIDR blocks using regex
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation relies on HTML scraping from a third-party website, which is fragile and could break if the HTML structure changes. Consider documenting this risk in a comment, or investigate if Huawei Cloud provides an official API or structured data source (like JSON or CSV) for their IP ranges, similar to how AWS, Azure, and GCP provide official sources.

Suggested change
// Extract CIDR blocks using regex
// Extract CIDR blocks using regex.
// NOTE: This implementation relies on scraping HTML from a third-party website
// (https://networksdb.io/ip-addresses-of/huawei-cloud). It is fragile and may
// break if the page structure or markup changes. If Huawei Cloud provides an
// official, structured source of IP ranges (for example a JSON, CSV, or API
// endpoint similar to those from AWS, Azure, or GCP), this fetcher should be
// updated to use that instead of HTML scraping.

Copilot uses AI. Check for mistakes.
}

// Extract CIDR blocks using regex
cidrRegex := regexp.MustCompile(`<b>CIDR:</b>\s*([^<]+)<br>`)
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern is being compiled on every call to FetchIPRanges(). For better performance, consider declaring this as a package-level variable that's compiled once, similar to how other Go projects handle frequently-used regex patterns.

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +53
cidr := match[1]
// Skip entries marked as "N/A"
if cidr != "N/A" {
ipRanges = append(ipRanges, cidr)
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extracted CIDR blocks should be trimmed for whitespace before being added to the slice. Other fetchers in this codebase (e.g., AliyunFetcher, LinodeFetcher, VPNFetcher) consistently use strings.TrimSpace() on extracted values to handle potential whitespace issues from the data source.

Copilot uses AI. Check for mistakes.
@JasonLovesDoggo JasonLovesDoggo merged commit f0d56e4 into main Dec 25, 2025
11 checks passed
@JasonLovesDoggo JasonLovesDoggo deleted the feat/huaweifetcher branch December 25, 2025 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a tag for Huawei Cloud's IP ranges

2 participants