18 lines
1.3 KiB
YAML
18 lines
1.3 KiB
YAML
version: 1
|
||
name: cf_dns_del
|
||
description: 删除 DNS 记录(按 record_id)
|
||
steps:
|
||
- id: del_dns
|
||
action: ssh.exec
|
||
on_fail: stop
|
||
with:
|
||
target: hwsg
|
||
command: "CF_API_TOKEN=${env_cf_api_token} INPUT_RECORD_ID=${env.INPUT_RECORD_ID} python3 - <<'PY'\nimport os,requests,json\nrec=os.getenv('INPUT_RECORD_ID','')\ntoken=os.getenv('CF_API_TOKEN','')\nemail=os.getenv('CF_API_EMAIL','')\nheaders={'Authorization':'Bearer '+token,'Content-Type':'application/json'}\n# find record across zones\nzones=requests.get('https://api.cloudflare.com/client/v4/zones?per_page=200', headers=headers, timeout=15).json().get('result',[])\nzone_id=None\nfor z in zones:\n zid=z.get('id')\n r=requests.get(f'https://api.cloudflare.com/client/v4/zones/{zid}/dns_records/{rec}', headers=headers, timeout=15)\n if r.status_code==200 and r.json().get('success'):\n zone_id=zid\n break\nif not zone_id:\n print(json.dumps({'success':False,'errors':['record_not_found']}))\n raise SystemExit(1)\nresp=requests.delete(f'https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records/{rec}', headers=headers, timeout=15)\nprint(resp.text)\nPY"
|
||
- id: assert
|
||
action: assert.json
|
||
on_fail: stop
|
||
with:
|
||
source_step: del_dns
|
||
required_paths:
|
||
- "success"
|