Skip to content

Commit

Permalink
Show error on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanVaughn committed Dec 2, 2023
1 parent 3b31015 commit 740447a
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -137,4 +137,6 @@ dmypy.json
# Cython debug symbols
cython_debug/

.vscode/*
.vscode/*
# my own testing
token.txt
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ c2547eb745079dac9320b638f5e225cf483cc5cfdda41

### `files` (optional)

A space seperated list of URLs to purge. Example:
A space separated list of URLs to purge. Example:

```yml
files: https://nathanv.me/assets/images/profile.png https://nathanv.me/assets/images/favicons/apple-touch-icon.png
@@ -39,23 +39,23 @@ The key `urls` is also accepted for backwards compatibility.

### `tags` (optional)

A space seperated list of tags to purge. Example:
A space separated list of tags to purge. Example:

```yml
tags: some-tag another-tag
```

### `hosts` (optional)

A space seperated list of hosts to purge. Example:
A space separated list of hosts to purge. Example:

```yml
hosts: nathanv.me blog.nathanv.me
```

### `prefixes` (optional)

A space seperated list of prefixes to purge. Example:
A space separated list of prefixes to purge. Example:

```yml
prefixes: nathanv.me/assets/ blog.nathanv.me/assets
18 changes: 8 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse
import http.client
import json
import os
import sys
from typing import List
from urllib import request


def split_and_flatten_list(items: List[str]) -> List[str]:
@@ -107,7 +107,8 @@ def main() -> None:
req_data["purge_everything"] = True

# create the request
url = f"https://api.cloudflare.com/client/v4/zones/{args.cf_zone}/purge_cache"
conn = http.client.HTTPSConnection("api.cloudflare.com")
url = f"/client/v4/zones/{args.cf_zone}/purge_cache"
headers = {
"Authorization": f"Bearer {args.cf_auth}",
"Content-Type": "application/json",
@@ -116,31 +117,28 @@ def main() -> None:

if os.getenv("NATHANVAUGHN_TESTING"):
# when testing, don't actually make a request
print(url)
print(f"https://{conn.host}{url}")
print(json.dumps(headers))
print(json.dumps(req_data))
sys.exit()
else:
print("Request:")
print_blue(url)
print_blue(f"https://{conn.host}{url}")
print("Headers:")
print_blue(json.dumps(headers, indent=4))
print("Payload:")
print_blue(json.dumps(req_data, indent=4))

req = request.Request(
url, data=json.dumps(req_data).encode("utf-8"), headers=headers
)
resp = request.urlopen(req)
conn.request("POST", url, json.dumps(req_data).encode("utf-8"), headers)
resp = conn.getresponse()

# process response
resp_data = json.loads(resp.read())

print("=========")
print("Response:")
print_blue(json.dumps(resp_data, indent=4))

if resp_data["success"] != True:
if resp_data["success"] is not True:
print("::error::Success NOT True")
sys.exit(1)

0 comments on commit 740447a

Please sign in to comment.