Huawei Cloud CDN (Content Delivery Network) Accelerated Domain List
Overview
Query the CDN accelerated-domain list of a tenant through KooCLI
hcloud CDN ListDomains --cli-region=<region> (official read-only GET
/v1.0/cdn/domains, verified
in the huaweicloudsdkcdn v1 client _list_domains_http_info metadata). The
skill is aimed at CDN inventory inspection, daily operations patrol, and as a
pre-query step for other CDN workflows that need a domain name or CNAME.
Architecture:
agent → python3 scripts/list_cdn.py → hcloud CDN ListDomains --cli-region=<region>
→ Huawei Cloud CDN OpenAPI → parsed JSON → table / --json / --names-only
(hcloud binary missing) → fallback: huaweicloudsdkcdn v1 CdnClient.list_domains
Key properties:
- Read-only by design — the only API ever invoked is
ListDomains(GET). A write-intent guard scans user arguments and validates the operation name; mutating intents (create / delete / update / modify / enable / disable / refresh / preheat ...) are rejected with an explicit message before any command runs. - CLI first, SDK fallback — KooCLI is the primary execution path; when the
KooCLI binary is absent, the script falls back to the official
huaweicloudsdkcdnv1 SDK (list_domains). Credentials are always read by the CLI profile / SDK environment — never handled by the script. - Full-field table output — the default table renders the union of all
fields returned by ListDomains, with
tagsflattened for readability and the key columns (域名/加速域名状态/CNAME/业务类型) first. - Offline-testable — every code path (paging, filters, error classification, guard, SDK fallback) is covered by unit tests that mock the hcloud subprocess.
Out of scope: every mutating CDN action (create / delete / enable / disable / update a domain, origin or config changes, refresh / preheat tasks, certificate management). Those require a dedicated write-capable skill and explicit user confirmation (确认).
Prerequisites
- KooCLI (
hcloud) installed — see references/cli-installation-guide.md. Alternative:pip install huaweicloudsdkcdnto enable the SDK fallback path. - Active credential profile — configure credentials out-of-band (run the KooCLI configure command in your terminal, or set credential environment variables). Never paste AK/SK into chat; the script never reads, echoes, or stores secrets itself — authentication is delegated entirely to the hcloud profile / SDK environment.
- IAM permission — read-only
cdn:domain:list; least-privilege policy in references/iam-policies.md. - Python 3.8+ (standard library only — argparse / json / subprocess).
- Outbound HTTPS access to
cdn.myhuaweicloud.com.
Workflow
- Confirm the target region (default
cn-north-4); CDN accelerated domains are queried through the CDN endpoint, and the credential project is region-scoped. - Confirm KooCLI readiness (optional, read-only) by listing the active credential profile.
- Run the list script with the desired output mode and filters.
- Read the result — table for humans,
--jsonfor downstream tooling,--names-onlyfor a compact inventory. - Handle the empty / error cases per the Edge Cases table below (the script prints an explicit hint for empty region, 403, and missing AK/SK).
Core Commands
# Full-field table (default)
python3 scripts/list_cdn.py --region cn-north-4
# Raw JSON of every returned field
python3 scripts/list_cdn.py --json
# Compact accelerated-domain name list only
python3 scripts/list_cdn.py --names-only
# Filter by accelerated-domain status (server-side query parameter)
python3 scripts/list_cdn.py --domain-status online
# Filter by accelerated domain name / business type
python3 scripts/list_cdn.py --domain-name www.example.com
python3 scripts/list_cdn.py --business-type web
# Combine filters
python3 scripts/list_cdn.py --region cn-north-4 --domain-status online --names-only
Equivalent direct KooCLI command (the script wraps exactly this call, with page_number paging):
hcloud CDN ListDomains --cli-region=cn-north-4 --page_size=100 --page_number=1
Parameter Confirmation
| Parameter | Required | Description | Example |
|---|---|---|---|
--region / -r |
No | Huawei Cloud region (default cn-north-4) |
cn-south-1 |
--json |
No | Output the raw domain array as JSON | — |
--names-only |
No | Output accelerated-domain names only | — |
--domain-name |
No | Filter by accelerated domain name — real server-side query parameter (fuzzy match) | www.example.com |
--domain-status |
No | Filter by accelerated-domain status — real server-side query parameter | online |
--business-type |
No | Filter by business type — real server-side query parameter | web |
--service-area |
No | Filter by service area — real server-side query parameter | mainland_china |
--enterprise-project-id |
No | Filter by enterprise project ID — real server-side query parameter | 0 |
--page-size |
No | Page size for ListDomains (default 100) | 100 |
--operation |
No | hcloud CDN operation name; only ListDomains is allowed |
ListDomains |
Output-mode precedence: --names-only → --json → table (default).
Write-Intent Guard
- The script scans all user arguments plus the
--operationvalue for mutating vocabulary (create,delete,update,modify,enable,disable,refresh,preheat, and CDN operation names such asCreateDomain,DeleteDomain,UpdateDomain,EnableDomain,DisableDomain). - Any hit raises
GuardError, prints[错误] 检测到写操作意图 ... 已被守卫拦截, and exits with code 1 before a single hcloud command is executed. - Only
hcloud CDN ListDomains --cli-region=<region>(GET) — or the SDKlist_domainscall in the fallback path — is ever constructed bybuild_command(); there is no code path that can issue a mutating CDN API call.
KooCLI Command Format Standard
hcloud <Service> <Operation> --cli-region=<region> [--key=value ...]
- Service name — exact KooCLI title-case service name:
CDN. - Operation name — PascalCase:
ListDomains. - Region parameter —
--cli-region=<value>, e.g.--cli-region=cn-north-4(required for every concrete CDN call). - Simple parameter —
--key=value, e.g.--page_size=100,--page_number=1,--domain_name=www.example.com,--domain_status=online,--business_type=web. All filters are real server-side ListDomains parameters (verified against thehuaweicloudsdkcdnv1ListDomainsRequestmodel). - Paging —
--page_size+--page_number; the loop advancespage_numberuntil the collected count reaches the responsetotal. - REST path (official SDK
_http_info) —GET /v1.0/cdn/domains(huaweicloudsdkcdnv1_list_domains_http_info).
Error Handling
| Scenario | Behavior |
|---|---|
| Empty domain list | Exit 0, prints 当前区域(<x>)无 CDN 加速域名 (+ active filters) |
| 403 / insufficient IAM permission | Exit 1, 无权限访问内容分发网络(CDN),请检查 IAM 权限 hint |
| Missing / invalid AK-SK | Exit 1, explicit hint to configure hcloud credentials out-of-band (never in chat) |
| hcloud not installed | Exit 1 after SDK fallback also unavailable, hint to install KooCLI or pip install huaweicloudsdkcdn |
| Network / API failure | Exit 1 with the hcloud stderr excerpt |
KooCLI usage error ([USE_ERROR] ..., even with exit code 0) |
Exit 1, explicit hcloud 参数错误 hint pointing to hcloud CDN ListDomains --cli-region=<region> --help |
| Write intent detected | Exit 1, GuardError message, no command executed |
Exit codes: 0 success / empty region; 1 config, auth, guard, or API error.
Edge Cases
| Scenario | Handling |
|---|---|
Non-online domains |
Reported with their state (offline / configuring ...), not treated as failure |
--domain-name / --domain-status / --business-type filters |
Forwarded as real server-side query parameters (verified API params) |
| Large domain count | Automatic page_number paging (total aware, max 100 pages) |
| Extra response fields | Table columns are built from the union of returned fields — new fields appear automatically |
| Field missing on a domain | Rendered as - in the table |
Nested tags |
Flattened into key=value,... for the table |
| Non-JSON hcloud output | ApiError with the raw excerpt (first 200 chars) |
| hcloud absent, SDK installed | Transparent fallback to huaweicloudsdkcdn list_domains, same output modes |
| User asks to create/delete/enable a domain | Out of scope — blocked by the write-intent guard; a write-capable skill with explicit user confirmation is required |
Testing
Offline unit tests with a mocked hcloud subprocess (no credentials, no network):
python3 -m unittest discover -s tests -v
Coverage: write-intent guard (read passes / create / delete / update / enable /
disable / normalized variants / operation whitelist), command construction
(filters forwarded server-side; page_number paging), JSON extraction, failure
classification (missing AK/SK, 403, generic, [USE_ERROR] with rc=0), total
paging (page_number / full page / empty), SDK fallback (success / unavailable /
pagination), rendering (table with 域名/状态/CNAME/业务类型 / names /
fallbacks), and all main() output modes including empty, filter, and error
paths.
Reference Documents
| Document | Content |
|---|---|
| references/iam-policies.md | Least-privilege read-only IAM policy |
| references/cli-installation-guide.md | KooCLI installation and credential configuration |
| references/verification-method.md | How the skill and its tests were verified |
| references/dataflow-diagram.md | Mermaid data flow diagram |
| references/acceptance-criteria.md | Acceptance criteria checklist |
