Skip to content

Commit

Permalink
fix rate limit failure on empty auth token
Browse files Browse the repository at this point in the history
/close #219

changes:

- down: fix bad bearer token check for wget
- fetch: fix empty tokens still being added, fix bad bearer token check for wget and curl
- service-helper: fix likewise but unrelated bad test
  • Loading branch information
balupton committed Apr 22, 2024
1 parent bd6581a commit 6ab04b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion commands/down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function down_() (
# bar is nicer than dot, and noscroll prevents issues with our clearing
wget_options+=('--progress=bar:noscroll')
fi
if test "$option_bearer_token"; then
if test -n "$option_bearer_token"; then
wget_options+=(
"--header=Authorization: Bearer $option_bearer_token"
)
Expand Down
20 changes: 15 additions & 5 deletions commands/fetch
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ function fetch_() (
case "$item" in
'--help' | '-h') help ;;
'--auth-token='*) option_auth_token="${item#*=}" ;;
'--bot-token='*) option_auth_token="Bot ${item#*=}" ;;
'--bearer-token='*) option_auth_token="Bearer ${item#*=}" ;;
'--bot-token='*)
option_auth_token="${item#*=}"
if test -n "$option_auth_token"; then
option_auth_token="Bot $option_auth_token"
fi
;;
'--bearer-token='*)
option_auth_token="${item#*=}"
if test -n "$option_auth_token"; then
option_auth_token="Bearer $option_auth_token"
fi
;;
'--content-type='*) option_content_type="${item#*=}" ;;
'--json') option_content_type='application/json' ;;
'--body='*) option_body="${item#*=}" ;;
Expand Down Expand Up @@ -74,7 +84,7 @@ function fetch_() (

function __log_failure {
local status="$?"
echo-style --error="Failed to fetch the URL:" ' ' --code="$option_url" >/dev/stderr || return
echo-style --error='Failed to fetch the URL:' ' ' --code="$option_url" >/dev/stderr || return
return "$status"
}

Expand All @@ -89,7 +99,7 @@ function fetch_() (
# -S, --show-error When used with -s, --silent, it makes curl show an error message if it fails.
function do_curl {
local options=("$@")
if test "$option_auth_token"; then
if test -n "$option_auth_token"; then
options+=(
'--header'
"Authorization: $option_auth_token"
Expand All @@ -112,7 +122,7 @@ function fetch_() (
}
function do_wget {
local options=("$@")
if test "$option_auth_token"; then
if test -n "$option_auth_token"; then
options+=(
"--header=Authorization: $option_auth_token"
)
Expand Down
4 changes: 2 additions & 2 deletions commands/service-helper
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ function fs_own() (
fi

# unmask, do before load
if test "$this_unmask"; then
if test "$this_unmask" = 'yes'; then
this_unmask=''
do_unmask "$this_service"

Expand All @@ -537,7 +537,7 @@ function fs_own() (
fi

# load
if test "$this_load"; then
if test "$this_load" = 'yes'; then
this_load=''
do_load "$this_service"

Expand Down

0 comments on commit 6ab04b2

Please sign in to comment.