feat(gitea-download): allow anonymous download

This commit is contained in:
wpetit 2023-10-19 13:14:38 +02:00
parent 3bf8e64888
commit 2c182df6a6
1 changed files with 13 additions and 2 deletions

View File

@ -5,6 +5,7 @@ set -eo pipefail
GITEA_DOWNLOAD_PROJECT=${GITEA_DOWNLOAD_PROJECT} GITEA_DOWNLOAD_PROJECT=${GITEA_DOWNLOAD_PROJECT}
GITEA_DOWNLOAD_ORG=${GITEA_DOWNLOAD_ORG} GITEA_DOWNLOAD_ORG=${GITEA_DOWNLOAD_ORG}
GITEA_DOWNLOAD_BASE_URL=${GITEA_BASE_URL:-https://forge.cadoles.com} GITEA_DOWNLOAD_BASE_URL=${GITEA_BASE_URL:-https://forge.cadoles.com}
GITEA_DOWNLOAD_ANONYMOUS=${GITEA_DOWNLOAD_ANONYMOUS:-no}
GITEA_DOWNLOAD_USERNAME=${GITEA_DOWNLOAD_USERNAME} GITEA_DOWNLOAD_USERNAME=${GITEA_DOWNLOAD_USERNAME}
GITEA_DOWNLOAD_PASSWORD=${GITEA_DOWNLOAD_PASSWORD} GITEA_DOWNLOAD_PASSWORD=${GITEA_DOWNLOAD_PASSWORD}
GITEA_DOWNLOAD_RELEASE_NAME=${GITEA_DOWNLOAD_RELEASE_NAME:-latest} GITEA_DOWNLOAD_RELEASE_NAME=${GITEA_DOWNLOAD_RELEASE_NAME:-latest}
@ -52,6 +53,10 @@ function assert_environment {
} }
function ask_credentials { function ask_credentials {
if [ "${GITEA_DOWNLOAD_ANONYMOUS}" == "yes" ]; then
return
fi
if [ -z "$GITEA_DOWNLOAD_USERNAME" ]; then if [ -z "$GITEA_DOWNLOAD_USERNAME" ]; then
echo -n "Username: " echo -n "Username: "
read GITEA_DOWNLOAD_USERNAME read GITEA_DOWNLOAD_USERNAME
@ -104,11 +109,14 @@ function gitea_api {
local path=$1 local path=$1
local args=${@:2} local args=${@:2}
if [ "${GITEA_DOWNLOAD_ANONYMOUS}" != 'yes' ]; then
args="-u "$GITEA_DOWNLOAD_USERNAME:$GITEA_DOWNLOAD_PASSWORD" ${args}"
fi
curl -L \ curl -L \
--fail \ --fail \
--ipv4 \ --ipv4 \
-k \ -k \
-u "$GITEA_DOWNLOAD_USERNAME:$GITEA_DOWNLOAD_PASSWORD" \
${args} \ ${args} \
"$GITEA_DOWNLOAD_BASE_URL/api/v1$path" "$GITEA_DOWNLOAD_BASE_URL/api/v1$path"
} }
@ -117,11 +125,14 @@ function gitea_download {
local attachment_id=$1 local attachment_id=$1
local output=$2 local output=$2
if [ "${GITEA_DOWNLOAD_ANONYMOUS}" != 'yes' ]; then
GITEA_DOWNLOAD_CURL_ARGS="-u "$GITEA_DOWNLOAD_USERNAME:$GITEA_DOWNLOAD_PASSWORD" ${GITEA_DOWNLOAD_CURL_ARGS}"
fi
curl -L \ curl -L \
--fail \ --fail \
--ipv4 \ --ipv4 \
-k \ -k \
-u "$GITEA_DOWNLOAD_USERNAME:$GITEA_DOWNLOAD_PASSWORD" \
--output "$output" \ --output "$output" \
$GITEA_DOWNLOAD_CURL_ARGS \ $GITEA_DOWNLOAD_CURL_ARGS \
"$GITEA_DOWNLOAD_BASE_URL/attachments/$attachment_id" "$GITEA_DOWNLOAD_BASE_URL/attachments/$attachment_id"