Última atividade 1 day ago

Hudi revisou este gist 1 day ago. Ir para a revisão

Sem alterações

Hudi revisou este gist 1 day ago. Ir para a revisão

1 file changed, 48 insertions

腾讯云EO缓存刷新(arquivo criado)

@@ -0,0 +1,48 @@
1 + #!/bin/bash
2 +
3 + secret_id=""
4 + secret_key=""
5 + token=""
6 +
7 + service="teo"
8 + host="teo.tencentcloudapi.com"
9 + region=""
10 + action="CreatePurgeTask"
11 + version="2022-09-01"
12 + algorithm="TC3-HMAC-SHA256"
13 + timestamp=$(date +%s)
14 + date=$(date -u -d @$timestamp +"%Y-%m-%d")
15 + payload="{\"ZoneId\":\"",\"Type\":\"purge_host\",\"Method\":\"invalidate\",\"Targets\":[\"www.hudi.space\"]}"
16 +
17 + # ************* 步骤 1:拼接规范请求串 *************
18 + http_request_method="POST"
19 + canonical_uri="/"
20 + canonical_querystring=""
21 + canonical_headers="content-type:application/json; charset=utf-8\nhost:$host\nx-tc-action:$(echo $action | awk '{print tolower($0)}')\n"
22 + signed_headers="content-type;host;x-tc-action"
23 + hashed_request_payload=$(echo -n "$payload" | openssl sha256 -hex | awk '{print $2}')
24 + canonical_request="$http_request_method\n$canonical_uri\n$canonical_querystring\n$canonical_headers\n$signed_headers\n$hashed_request_payload"
25 + echo "$canonical_request"
26 +
27 + # ************* 步骤 2:拼接待签名字符串 *************
28 + credential_scope="$date/$service/tc3_request"
29 + hashed_canonical_request=$(printf "$canonical_request" | openssl sha256 -hex | awk '{print $2}')
30 + string_to_sign="$algorithm\n$timestamp\n$credential_scope\n$hashed_canonical_request"
31 + echo "$string_to_sign"
32 +
33 + # ************* 步骤 3:计算签名 *************
34 + secret_date=$(printf "$date" | openssl sha256 -hmac "TC3$secret_key" | awk '{print $2}')
35 + echo $secret_date
36 + secret_service=$(printf $service | openssl dgst -sha256 -mac hmac -macopt hexkey:"$secret_date" | awk '{print $2}')
37 + echo $secret_service
38 + secret_signing=$(printf "tc3_request" | openssl dgst -sha256 -mac hmac -macopt hexkey:"$secret_service" | awk '{print $2}')
39 + echo $secret_signing
40 + signature=$(printf "$string_to_sign" | openssl dgst -sha256 -mac hmac -macopt hexkey:"$secret_signing" | awk '{print $2}')
41 + echo "$signature"
42 +
43 + # ************* 步骤 4:拼接 Authorization *************
44 + authorization="$algorithm Credential=$secret_id/$credential_scope, SignedHeaders=$signed_headers, Signature=$signature"
45 + echo $authorization
46 +
47 + # ************* 步骤 5:构造并发起请求 *************
48 + curl -XPOST "https://$host" -d "$payload" -H "Authorization: $authorization" -H "Content-Type: application/json; charset=utf-8" -H "Host: $host" -H "X-TC-Action: $action" -H "X-TC-Timestamp: $timestamp" -H "X-TC-Version: $version" -H "X-TC-Region: $region" -H "X-TC-Token: $token"
Próximo Anterior