From 4007b8008dfef56284e922b3374fc078d3a1a4f3 Mon Sep 17 00:00:00 2001 From: chandramerla Date: Fri, 7 Feb 2025 11:00:59 +0530 Subject: [PATCH] Allow cat and stat functions of gcs_restapi.sh to be called without authentication Signed-off-by: chandramerla --- .../kubevirtci/kubevirtci-periodics.yaml | 4 +-- .../kubevirtci/kubevirtci-postsubmits.yaml | 4 +-- images/bootstrap/gcs_restapi.sh | 25 ++++++++++++++----- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-periodics.yaml b/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-periodics.yaml index fb3c925449..0c412b7dcd 100644 --- a/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-periodics.yaml +++ b/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-periodics.yaml @@ -176,7 +176,7 @@ 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 @@ -184,7 +184,7 @@ periodics: 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 diff --git a/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-postsubmits.yaml b/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-postsubmits.yaml index 52187edd11..db805b9f9f 100644 --- a/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-postsubmits.yaml +++ b/github/ci/prow-deploy/files/jobs/kubevirt/kubevirtci/kubevirtci-postsubmits.yaml @@ -104,7 +104,7 @@ 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 @@ -112,7 +112,7 @@ postsubmits: 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 diff --git a/images/bootstrap/gcs_restapi.sh b/images/bootstrap/gcs_restapi.sh index bf7d32f069..c1fd309b78 100755 --- a/images/bootstrap/gcs_restapi.sh +++ b/images/bootstrap/gcs_restapi.sh @@ -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 @@ -99,12 +105,19 @@ 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 \ + -H "Cache-Control: no-cache" \ + "${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"