Skip to content

Commit

Permalink
add default timeouts to curl and requests calls
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrargyrum committed Sep 21, 2023
1 parent be49051 commit d931871
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions firefox-relay-tools/fxrelay-add
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ then
fi

curl -f -S -s https://relay.firefox.com/api/v1/relayaddresses/ \
-m 60 \
-H "Authorization: Token $FXRELAY_TOKEN" \
-H "content-type: application/json" \
-d "{\"enabled\": true, \"block_list_emails\": false, \"description\": \"${1-}\"}"
1 change: 1 addition & 0 deletions firefox-relay-tools/fxrelay-delete
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ fi

curl -f -S -s https://relay.firefox.com/api/v1/relayaddresses/"$1"/ \
-X DELETE \
-m 60 \
-H "Authorization: Token $FXRELAY_TOKEN" \
-H "content-type: application/json"
1 change: 1 addition & 0 deletions firefox-relay-tools/fxrelay-list
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ then
fi

curl -f -S -s https://relay.firefox.com/api/v1/relayaddresses/ \
-m 60 \
-H "Authorization: Token $FXRELAY_TOKEN"
1 change: 1 addition & 0 deletions firefox-relay-tools/fxrelay-set-block
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ esac

curl -f -S -s https://relay.firefox.com/api/v1/relayaddresses/"$1"/ \
-X PATCH \
-m 60 \
-H "Authorization: Token $FXRELAY_TOKEN" \
-H "content-type: application/json" \
-d "$json"
5 changes: 4 additions & 1 deletion gotify-tools/gotify-push.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
parser.add_argument("-t", "--title")
parser.add_argument("-p", "--priority", type=int, default=0)
parser.add_argument("-e", "--extra", action="append", metavar="NAMESPACE::ACTION::KEY=VALUE", default=[])
parser.add_argument("--timeout", type=int, default=60)
parser.add_argument("message", nargs="+")
args = parser.parse_args()

Expand Down Expand Up @@ -48,7 +49,9 @@
}

# request
response = session.post(urljoin(args.url, "message"), json=pdata)
response = session.post(
urljoin(args.url, "message"), json=pdata, timeout=args.timeout,
)
response.raise_for_status()

print(json.dumps(response.json(), indent=2))
2 changes: 2 additions & 0 deletions gotify-tools/gotify-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jsonstr () {

PRIORITY=1
TITLE=
TIMEOUT=60

while getopts p:u:k:K:t: f
do
Expand Down Expand Up @@ -85,6 +86,7 @@ TITLE=$(printf %s "$TITLE" | jsonstr)

curl \
-s -S -f \
-m "$TIMEOUT" \
-H 'Content-Type: application/json' \
-H "X-Gotify-Key: $GOTIFY_TOKEN" \
-d "{\"message\": \"$message\", \"title\": \"${TITLE}\", \"priority\": ${PRIORITY}}" \
Expand Down
2 changes: 1 addition & 1 deletion hibp/hibp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import requests
def verify(pass_cb=getpass, prompt='Password to check on HIBP: '):
expected = hashlib.sha1(pass_cb(prompt).encode('utf-8')).hexdigest().upper()
url = 'https://api.pwnedpasswords.com/range/%s' % expected[:5]
hashes = requests.get(url).text.split()
hashes = requests.get(url, timeout=60).text.split()
for h in hashes:
h = expected[:5] + h.upper()
if h.startswith(expected):
Expand Down
1 change: 1 addition & 0 deletions links2markdown/links2markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def fetch_title(url):
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0",
},
timeout=120,
)
except requests.exceptions.RequestException:
return None
Expand Down

0 comments on commit d931871

Please sign in to comment.