Skip to content

Instantly share code, notes, and snippets.

View kyouheicf's full-sized avatar
🍊

kyouheicf

🍊
  • 22:00 (UTC +09:00)
View GitHub Profile
curl --request POST \
--url https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/alerting/v3/policies \
-H "X-Auth-Email: $EMAIL" \
-H "X-Auth-Key: $APIKEY" \
-H "Content-Type: application/json" \
--data '{
"name": "Magic Tunnel Health Alert",
"alert_type": "magic_tunnel_health_check_event",
"description": "My Magic tunnel health alert",
"enabled": true,
{
"id": "8ac8bc2a661e475d940980f9317f28e1",
"action": "score",
"description": "911100: Method is not allowed by policy",
"enabled": true,
"action_parameters": {
"increment": 5
}
}
{
# Get the current CLI user
# https://stackoverflow.com/questions/35311686/how-to-get-the-active-authenticated-gcloud-account
gcloud config list account --format "value(core.account)"
# Login through the browser
gcloud auth login
# Use Credential from json file
gcloud auth activate-service-account \
--key-file=/Users/xxx/key.json
export ZONE_ID='YOUR_ZONE_ID'
http -A creds "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/scripts?order_by=last_seen_at&direction=desc&status=active,inactive,infrequent" \
| jq -r '.result[0].id' | (read id ;http -A creds GET https://api.cloudflare.com/client/v4/zones/$ZONE_ID/page_shield/scripts/$id) \
| jq -r '.result'
# Ref. HTTPie を Cloudflare API / GraphQL 用に設定する - Qiita
# https://qiita.com/khayama/items/1738c3b98e9c4108a35d
// npm i puppeteer
const puppeteer = require('puppeteer');
puppeteer.launch({
headless: false,
devtools: true,
product: 'firefox',
}).then(async browser => {
const page = (await browser.pages())[0];
await page.setCacheEnabled(false);
// npm install puppeteer puppeteer-extra puppeteer-extra-plugin-user-preferences
const puppeteer = require('puppeteer-extra');
const ppUserPrefs = require('puppeteer-extra-plugin-user-preferences');
puppeteer.use(ppUserPrefs({
userPrefs: {
devtools: {
preferences: {
'InspectorView.splitViewState': JSON.stringify({
vertical: { size: 1500 },
# Normal Chrome
PUPPETEER_PRODUCT=chrome \
PUPPETEER_EXECUTABLE_PATH=/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
node chrome-pageshield-cspreport-once.js
# Beta Chrome
PUPPETEER_PRODUCT=chrome \
PUPPETEER_EXECUTABLE_PATH=/Applications/Google\ Chrome\ Beta.app/Contents/MacOS/Google\ Chrome\ Beta \
node chrome-pageshield-cspreport-once.js
initial_settings = [
{
always_online = "off"
always_use_https = "on"
automatic_https_rewrites = "off"
binary_ast = "off"
brotli = "off"
browser_cache_ttl = 14400
browser_check = "on"
cache_level = "aggressive"
export EMAIL='YOUR_EMAIL'
export APIKEY='YOUR_APIKEY'
export ZONE_ID='YOUR_ZONE_ID'
# Purge Everything
curl --request POST \
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache \
--header 'Content-Type: application/json' \
--header "X-Auth-Email: $EMAIL" \
--header "X-Auth-Key: $APIKEY" \
export EMAIL='YOUR_EMAIL'
export APIKEY='YOUR_APIKEY'
export ZONE_ID='YOUR_ZONE_ID'
# Purge by prefix
curl --request POST \
--url https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache \
--header 'Content-Type: application/json' \
--header "X-Auth-Email: $EMAIL" \
--header "X-Auth-Key: $APIKEY" \