Skip to content

Commit

Permalink
Allow cat and stat functions of gcs_restapi.sh to be called without a…
Browse files Browse the repository at this point in the history
…uthentication

Signed-off-by: chandramerla <Chandra.Merla@ibm.com>
  • Loading branch information
chandramerla committed Feb 7, 2025
1 parent aade083 commit c89d9e8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ periodics:
CHECK_INTERVAL=30 &&
source /usr/local/bin/gcs_restapi.sh &&
while true; do
if stat_gcs_file kubevirt-prow "$GCS_FILE_PATH"; then
if stat_gcs_file kubevirt-prow "$GCS_FILE_PATH" "false"; then
echo "File $GCS_FILE_PATH is now available."
break
else
echo "File $GCS_FILE_PATH not found. Checking again in $CHECK_INTERVAL seconds."
sleep $CHECK_INTERVAL
fi
done
KUBEVIRTCI_TAG=$(cat_gcs_file kubevirt-prow "$GCS_FILE_PATH")
KUBEVIRTCI_TAG=$(cat_gcs_file kubevirt-prow "$GCS_FILE_PATH" "false")
if [ $? -ne 0 ]; then
echo "Failed to fetch KUBEVIRTCI_TAG"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ postsubmits:
source /usr/local/bin/gcs_restapi.sh &&
CHECK_INTERVAL=30 &&
while true; do
if stat_gcs_file kubevirt-prow "$GCS_FILE_PATH"; then
if stat_gcs_file kubevirt-prow "$GCS_FILE_PATH" "false"; then
echo "File $GCS_FILE_PATH is now available."
break
else
echo "File $GCS_FILE_PATH not found. Checking again in $CHECK_INTERVAL seconds."
sleep $CHECK_INTERVAL
fi
done &&
KUBEVIRTCI_TAG=$(cat_gcs_file kubevirt-prow "$GCS_FILE_PATH")
KUBEVIRTCI_TAG=$(cat_gcs_file kubevirt-prow "$GCS_FILE_PATH" "false")
if [ $? -ne 0 ]; then
echo "Failed to fetch KUBEVIRTCI_TAG"
exit 1
Expand Down
24 changes: 18 additions & 6 deletions images/bootstrap/gcs_restapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,17 @@ upload_to_gcs() {
stat_gcs_file() {
local bucket_name="$1"
local gcs_file_path=$(urlencode_path "$2")
local auth="$3"

get_access_token
if [ "$auth" == "false" ]; then
auth_header=""
else
get_access_token
auth_header="-H \"Authorization: Bearer $access_token\""
fi

stat_response=$(curl -s -X GET \
-H "Authorization: Bearer $access_token" \
$auth_header \
"${BASE_URL}/storage/v1/b/$bucket_name/o/$gcs_file_path")

if echo "$stat_response" | jq -e '.error' > /dev/null; then
Expand All @@ -99,12 +105,18 @@ stat_gcs_file() {
cat_gcs_file() {
local bucket_name="$1"
local gcs_file_path=$(urlencode_path "$2")
local auth="$3"

get_access_token
if [ "$auth" == "false" ]; then
auth_header=""
else
get_access_token
auth_header="-H \"Authorization: Bearer $access_token\""
fi

file_content=$(curl -s -X GET \
-H "Authorization: Bearer $access_token" \
"${BASE_URL}/storage/v1/b/$bucket_name/o/$gcs_file_path?alt=media")
file_content=$(curl --silent --fail -X GET \
$auth_header \
"${BASE_URL}/storage/v1/b/$bucket_name/o/$gcs_file_path?alt=media&ignoreCache=1")

if [ -z "$file_content" ]; then
echo "Error: No content received"
Expand Down

0 comments on commit c89d9e8

Please sign in to comment.