1. List Huawei Cloud CDN (Content Delivery Network) accelerated domains in a tenant through KooCLI (hcloud CDN ListDomains — read-only GET /v1.0/cdn/domains), with an automatic fallback to the official huaweicloudsdkcdn v1 SDK when hcloud is not installed. 2. Three output modes: full-field table (default, every returned field including 域名/加速域名状态/CNAME/业务类型), --json (raw response array), and --names-only (compact accelerated-domain name list). 3. Supports --domain-name / --domain-status / --business-type / --service-area / --enterprise-project-id filtering (all real server-side ListDomains query parameters), region override, and automatic page_number paging over the response `total` count. 4. Explicit error hints for empty domain lists (「当前区域无 CDN 加速域名」), 403 / insufficient IAM permission (「无权限访问内容分发网络(CDN)」), missing or invalid AK/SK credentials, and hcloud not installed. 5. Built-in write-intent guard: any mutating intent (create / delete / update / modify / enable / disable / refresh / preheat) or any operation other than ListDomains is rejected before execution — this skill is strictly read-only. 6. Triggers include: "list CDN domains", "cdn list", "加速域名列表", "查询 CDN", "查询加速域名", "CDN 域名列表", "CDN 域名盘点", "list cdn domains", "accelerated domain inventory", "华为云 CDN". 7. Offline unit tests (mocked hcloud subprocess) cover output modes, filters, page_number paging, error scenarios, SDK fallback, and the write-intent guard.
---
name: huawei-cloud-cdn-list
description: |
1. List Huawei Cloud CDN (Content Delivery Network) accelerated domains in a
tenant through KooCLI (hcloud CDN ListDomains — read-only GET
/v1.0/cdn/domains), with an automatic fallback to the official
huaweicloudsdkcdn v1 SDK when hcloud is not installed.
2. Three output modes: full-field table (default, every returned field
including 域名/加速域名状态/CNAME/业务类型), --json (raw response array),
and --names-only (compact accelerated-domain name list).
3. Supports --domain-name / --domain-status / --business-type /
--service-area / --enterprise-project-id filtering (all real server-side
ListDomains query parameters), region override, and automatic
page_number paging over the response `total` count.
4. Explicit error hints for empty domain lists (「当前区域无 CDN 加速域名」),
403 / insufficient IAM permission (「无权限访问内容分发网络(CDN)」),
missing or invalid AK/SK credentials, and hcloud not installed.
5. Built-in write-intent guard: any mutating intent (create / delete / update /
modify / enable / disable / refresh / preheat) or any operation other than
ListDomains is rejected before execution — this skill is strictly
read-only.
6. Triggers include: "list CDN domains", "cdn list", "加速域名列表",
"查询 CDN", "查询加速域名", "CDN 域名列表", "CDN 域名盘点",
"list cdn domains", "accelerated domain inventory", "华为云 CDN".
7. Offline unit tests (mocked hcloud subprocess) cover output modes, filters,
page_number paging, error scenarios, SDK fallback, and the write-intent
guard.
tags: [huawei-cloud, cdn, network, readonly, koo-cli]
---
# 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:
```text
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
`huaweicloudsdkcdn` v1 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 `tags` flattened 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
1. **KooCLI (`hcloud`) installed** — see
[references/cli-installation-guide.md](references/cli-installation-guide.md).
Alternative: `pip install huaweicloudsdkcdn` to enable the SDK fallback path.
2. **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.
3. **IAM permission** — read-only `cdn:domain:list`; least-privilege policy in
[references/iam-policies.md](references/iam-policies.md).
4. **Python 3.8+** (standard library only — argparse / json / subprocess).
5. **Outbound HTTPS** access to `cdn.myhuaweicloud.com`.
## Workflow
1. **Confirm the target region** (default `cn-north-4`); CDN accelerated domains
are queried through the CDN endpoint, and the credential project is
region-scoped.
2. **Confirm KooCLI readiness** (optional, read-only) by listing the active
credential profile.
3. **Run the list script** with the desired output mode and filters.
4. **Read the result** — table for humans, `--json` for downstream tooling,
`--names-only` for a compact inventory.
5. **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
```bash
# 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):
```bash
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 `--operation` value for mutating
vocabulary (`create`, `delete`, `update`, `modify`, `enable`, `disable`,
`refresh`, `preheat`, and CDN operation names such as `CreateDomain`,
`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 SDK
`list_domains` call in the
fallback path — is ever constructed by `build_command()`; there is no code
path that can issue a mutating CDN API call.
## KooCLI Command Format Standard
```text
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 the `huaweicloudsdkcdn` v1 `ListDomainsRequest`
model).
- **Paging** — `--page_size` + `--page_number`; the loop advances `page_number`
until the collected count reaches the response `total`.
- **REST path (official SDK `_http_info`)** —
`GET /v1.0/cdn/domains` (`huaweicloudsdkcdn` v1
`_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):
```bash
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](references/iam-policies.md) | Least-privilege read-only IAM policy |
| [references/cli-installation-guide.md](references/cli-installation-guide.md) | KooCLI installation and credential configuration |
| [references/verification-method.md](references/verification-method.md) | How the skill and its tests were verified |
| [references/dataflow-diagram.md](references/dataflow-diagram.md) | Mermaid data flow diagram |
| [references/acceptance-criteria.md](references/acceptance-criteria.md) | Acceptance criteria checklist |don't have the plugin yet? install it then click "run inline in claude" again.
extracted implicit decision logic into explicit if-else branches (koolci availability, error classification, guard/whitelist checks, paging loop termination), documented all external connections with setup guidance (koolci install, sdk fallback, credential env vars, iam scope, api endpoint), added edge case handling (rate limits via page_number loop max, auth expiry in credential validity, empty result sets, network timeouts, use error classification, json parse failures, field flattening), specified output contract with example formats and file locations, clarified outcome signals with concrete command examples and exit behaviors. preserved original procedure faithfully (9 steps became 10 with credential setup split out), kept author attribution implicit (original source clawhub), applied lowercase tech-bro voice throughout, avoided em-dashes entirely.
list all cdn accelerated domains in a huawei cloud tenant via koolci hcloud CDN ListDomains (read-only GET /v1.0/cdn/domains) with automatic sdk fallback. use this to audit cdn inventory, spot non-online domains, check cnames, pre-query for downstream cdn workflows, or validate tenant domain configuration. the skill enforces read-only semantics, rejecting any mutating intent (create/delete/update/enable/disable/refresh/preheat) before execution. supports three output modes (full-field table, raw json, names-only), server-side filters (domain-name, domain-status, business-type, service-area, enterprise-project-id), and automatic paging over large domain lists.
external connections:
hcloud CDN ListDomains or the official huaweicloudsdkcdn v1 sdkpip install huaweicloudsdkcdn for sdk fallbackHUAWEI_CLOUD_SDK_* environment variables (AK, SK, region). never paste secrets in chat; configure out-of-band via hcloud configure or envcdn.myhuaweicloud.com (https, outbound required)cdn:domain:list (least-privilege policy in references/iam-policies.md)runtime:
cn-north-4, override via --region flagparameters:
--region / -r , huawei cloud region (string, default cn-north-4, e.g. cn-south-1)--json , output raw json array of domains instead of table--names-only , output compact newline-separated domain names only--domain-name , server-side filter by accelerated domain name (string, fuzzy match)--domain-status , server-side filter by domain status (string, e.g. online, offline, configuring)--business-type , server-side filter by business type (string, e.g. web)--service-area , server-side filter by service area (string, e.g. mainland_china)--enterprise-project-id , server-side filter by enterprise project id (string, e.g. 0)--page-size , page size for listdomains api (integer, default 100, max 100)--operation , expected operation name (string, default ListDomains, whitelist enforced)parse command-line arguments (argparse: region, json, names-only, filters, page-size, operation). input: argv. output: parsed namespace object with all flags set to defaults or user values.
scan arguments for write-intent keywords (mutating vocabulary: create, delete, update, modify, enable, disable, refresh, preheat, and pascalcase operation names like CreateDomain, DeleteDomain). input: parsed namespace, operation flag. output: guardstatus (pass/block). if blocked, raise GuardError, print [错误] 检测到写操作意图 ... 已被守卫拦截, exit code 1. do not proceed to step 3.
validate operation name whitelist , only ListDomains allowed. input: --operation value. output: validation result (pass/fail). if fail, raise OperationError, print hint to use hcloud CDN ListDomains --cli-region=<region>, exit code 1.
build koolci command (hcloud CDN ListDomains --cli-region=
check koolci availability , attempt which hcloud or run hcloud with --version. input: system $PATH. output: boolean (installed/missing). if missing, skip to step 8 (sdk fallback).
execute koolci command (subprocess.run with page_number paging loop). input: command from step 4. output: stdout (raw json text), stderr (error messages), return code. loop: increment page_number after each call, repeat until collected domain count >= response total or page_number > max (100). if rc != 0, classify error (see decision points).
parse json response , extract domains array from koolci stdout. input: json text. output: list of domain dicts. if json parse fails, raise ApiError with raw excerpt (first 200 chars), exit code 1.
fallback to sdk (if koolci unavailable or failed with auth/permission error) , import huaweicloudsdkcdn, create CdnClient, call list_domains(ListDomainsRequest(region, filters, page_size, page_number)). input: region, filters, page-size. output: sdk response object. loop paging same as step 6. if sdk import fails, print hint to install, exit code 1. if sdk call fails (auth, permission, network), classify error (see decision points).
render output , precedence: --names-only (print each domain.domain_name, one per line) → --json (json.dumps(domains, indent=2)) → table (default). input: domains list, output mode flag. output: stdout text. if domains is empty, print 当前区域(<region>)无 CDN 加速域名[,当前条件: <active filters>], exit code 0 (success, not error).
exit , code 0 on success (domains found or empty region); code 1 on config/auth/guard/api error.
if write-intent guard blocks: reject immediately, print error message, exit code 1. do not invoke koolci or sdk.
if operation name is not ListDomains: reject, print hint, exit code 1.
if koolci is installed and available: use it (step 6, paging loop). proceed to step 7 (parse json).
else if koolci is missing or failed with 403/auth error: fall back to sdk (step 8). import huaweicloudsdkcdn, create client, call list_domains with same filters and paging logic. if sdk is also unavailable or import fails, print hint to install koolci or sdk, exit code 1.
if json parsing fails (hcloud output is not valid json): raise ApiError, print raw excerpt, exit code 1.
if response has [USE_ERROR] prefix (even if rc=0): treat as error, print hcloud 参数错误, hint to check hcloud CDN ListDomains --cli-region=<region> --help, exit code 1.
if response status code is 403: print 无权限访问内容分发网络(CDN),请检查 IAM 权限, exit code 1.
if response status code is 401 or ak/sk invalid: print hint to configure credentials out-of-band (never in chat), exit code 1.
if response is empty domains array: print 当前区域(<region>)无 CDN 加速域名, exit code 0.
if response has domains but paging loop reaches page_number > 100: assume api limit or loop bug, return collected domains so far (do not error), exit code 0.
if any network/timeout error: print hcloud stderr excerpt, exit code 1.
if output mode is --names-only: print each domain name as domain.domain_name on a separate line.
else if output mode is --json: print entire domains array as json (indent 2).
else (default table mode): build table columns from union of all returned fields in domain dicts. render 域名 (domain_name) / 加速域名状态 (domain_status) / CNAME (cname) / 业务类型 (business_type) first, then all other fields. flatten nested tags to key=value,... format. render missing fields as -. use a standard ascii table format (e.g. tabulate or bare print with aligned columns).
success (exit 0):
域名 加速域名状态 CNAME 业务类型
www.example.com online www.example.com.cdnimg.cn web
img.example.com online img.example.com.cdnimg.cn web
[
{
"domain_name": "www.example.com",
"domain_status": "online",
"cname": "www.example.com.cdnimg.cn",
"business_type": "web",
...
}
]
www.example.com
img.example.com
当前区域(cn-north-4)无 CDN 加速域名, exit 0.当前区域(cn-north-4)无 CDN 加速域名,当前条件: domain_status=online, exit 0.failure (exit 1):
[错误] 检测到写操作意图 ... 已被守卫拦截hcloud CDN ListDomains --cli-region=<region> --help无权限访问内容分发网络(CDN),请检查 IAM 权限pip install huaweicloudsdkcdnhcloud 参数错误,请检查:hcloud CDN ListDomains --cli-region=<region> --helpfile locations:
scripts/list_cdn.pytests/test_list_cdn.py (mocked hcloud subprocess, offline)references/iam-policies.md, references/cli-installation-guide.md, references/verification-method.md, references/dataflow-diagram.md, references/acceptance-criteria.mdthe skill worked if:
python3 scripts/list_cdn.py and see a table of domains with columns 域名 / 加速域名状态 / CNAME / 业务类型 within seconds (default region, no filters)python3 scripts/list_cdn.py --json and get a valid json array printed to stdoutpython3 scripts/list_cdn.py --names-only and see one domain name per linepython3 scripts/list_cdn.py --region cn-south-1 --domain-status online and the output is filtered to only online domains (or empty message if none match)python3 scripts/list_cdn.py --operation DeleteDomain and the script exits immediately with [错误] 检测到写操作意图 ... 已被守卫拦截 (guard block, no api call)当前区域(cn-north-4)无 CDN 加速域名, exit code 0