Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resty: Add workaround for new curl versions #157

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion resty
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ HELP

# Forge command and display it if dry-run
local cmd
cmd=(curl -sLv $curl_opt $(printf "%q" "$body") -X $method -b \"$cookies/$domain\" -c \"$cookies/$domain\" "$(\
# Flatcar: Add workaround for new curl versions
local body_arg=()
body_arg=($(printf "%q" "$body"))
if [ "${body_arg[*]}" = "" ] || [ "${body_arg[*]}" = "''" ]; then
body_arg=()
fi
cmd=(curl -sLv $curl_opt "${body_arg[@]}" -X $method -b \"$cookies/$domain\" -c \"$cookies/$domain\" "$(\
[ -n "$curlopt_cmd" ] && printf '%s ' ${curlopt_cmd[@]})"\"$_path$query\")
if [ "$dry_run" = "yes" ] ; then
echo "${cmd[@]}"
Expand Down
27 changes: 19 additions & 8 deletions upload_package
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,21 @@ echo "Environment variable ARCH is specified as ${ARCH}"

COREOS_APP_ID="e96281a6-d1af-4bde-9a0a-97b76e56dc57"

. resty -W "${NEBRASKA_URL}/api" -H "Authorization: Bearer $GITHUB_TOKEN" \
. resty -W "${NEBRASKA_URL}/api" -f -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/json" -H "Content-Type: application/json"

function get_package_id() {
local tmpfile="$(mktemp)"
local output
local package_id
local r

GET /apps/"${COREOS_APP_ID}"/packages >& ${tmpfile}
if jq -e 'has("packages")' ${tmpfile} > /dev/null; then
package_id=$(cat ${tmpfile} | jq '.packages' | jq '.[] | select(.version=="'${VERSION}'" and .arch=='${ARCH_ID}').id')
# Use || here to disable "set -e" as resty does not like it
output=$(GET /apps/"${COREOS_APP_ID}"/packages 2>&1) || { r="$?"; echo "${output}" ; return "$r"; }
if jq -e 'has("packages")' <(echo "${output}") > /dev/null; then
package_id=$(echo "${output}" | jq '.packages' | jq '.[] | select(.version=="'${VERSION}'" and .arch=='${ARCH_ID}').id')
else
package_id=$(cat ${tmpfile} | jq '.[] | select(.version=="'${VERSION}'" and .arch=='${ARCH_ID}').id')
package_id=$(echo "${output}" | jq '.[] | select(.version=="'${VERSION}'" and .arch=='${ARCH_ID}').id')
fi
rm -f ${tmpfile}

echo ${package_id}
}
Expand Down Expand Up @@ -88,9 +89,17 @@ else
exit 1
fi

if ! PACKAGE_ID=$(get_package_id); then
set +e
PACKAGE_ID=$(
set -e
get_package_id
)
r="$?"
set -e
if ! [ "$r" -eq 0 ]; then
echo "Failed to get metadata from Nebraska."
echo "Please make sure that you have configured a valid GITHUB_TOKEN."
echo "Error: ${PACKAGE_ID}"
exit 1
fi

Expand All @@ -106,6 +115,7 @@ for EXTRA_FILE in "${EXTRA_FILES[@]}"; do
done
EMBED_EXTRA_JOINED=$(IFS=, ; echo "${EMBED_EXTRA[*]}")
if [ -z "${PACKAGE_ID}" ]; then
# Using 'if POST' here disables set -e as resty expects
if ! PACKAGE_JSON=$(POST /apps/"${COREOS_APP_ID}"/packages " \
{
\"application_id\": \"${COREOS_APP_ID}\",
Expand All @@ -127,6 +137,7 @@ if [ -z "${PACKAGE_ID}" ]; then
" 2>&1); then
echo "Failed to update metadata on Nebraska."
echo "Please make sure that you have configured a valid GITHUB_TOKEN."
echo "Error: ${PACKAGE_JSON}"
exit 1
fi
PACKAGE_ID=$(echo "${PACKAGE_JSON}" | jq .id)
Expand Down