Arcade Trail: Data Engineering and Security

Solution for Arcade Trail: Data Engineering and Security. 1 lab: GSP294. Fast copy-paste commands for Google Cloud.

GSP294 — Introduction to APIs in Google Cloud

Estimated time: 15 minutes

# 🚀 APIs Explorer: Qwik Start > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created for educational purposes, hands-on practice, and Google Cloud certification preparation. This guide is designed to help learners understand Google Cloud APIs, authentication, Cloud Storage, and REST API operations through practical exercises. Always attempt the lab yourself first and follow Google Cloud Skills Boost / Qwiklabs Terms of Service. This walkthrough is not affiliated with o

clear
CYAN=$(tput setaf 6)
BOLD=$(tput bold)
RESET=$(tput sgr0)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)

echo "${CYAN}${BOLD}"
echo "   ____       _     _ _            __   ___             "
echo "  / __ \     | |   (_) |          / _| / _ \            "
echo " | |  | |_ __| |__  _| |_   ___  | |_ | | | |_ __  ___  "
echo " | |  | | '__| '_ \| | __| / _ \ |  _|| | | | '_ \/ __| "
echo " | |__| | |  | |_) | | |_ | (_) || |  | |_| | |_) \__ \ "
echo "  \____/|_|  |_.__/|_|\__| \___/ |_|   \___/| .__/|___/ "
echo "                                            | |         "
echo "                                            |_|         "
echo "${RESET}"
echo "${CYAN}====================================================${RESET}"
echo "${GREEN}${BOLD}Command 1 of 2: REST API Bucket Creation${RESET}"
echo "${CYAN}====================================================${RESET}"
echo ""

export PROJECT_ID=$(gcloud config get-value project)
echo "${YELLOW}Auto-detected Project ID: ${PROJECT_ID}${RESET}"

export REGION=$(gcloud compute project-info describe --format="value(commonInstanceMetadata.items[google-compute-default-region])" 2>/dev/null)
if [[ -z "$REGION" ]]; then
    read -p "Enter Region (e.g., us-central1): " REGION
fi
gcloud config set compute/region $REGION --quiet

echo "${YELLOW}Generating values.json payload...${RESET}"
cat <<EOF > values.json
{
  "name": "${PROJECT_ID}-bucket",
  "location": "us",
  "storageClass": "multi_regional"
}
EOF

echo "${YELLOW}Generating OAuth2 Access Token natively...${RESET}"
export OAUTH2_TOKEN=$(gcloud auth print-access-token)

echo "${YELLOW}Executing POST request to Cloud Storage REST API...${RESET}"
curl -s -X POST --data-binary @values.json -H "Authorization: Bearer $OAUTH2_TOKEN" -H "Content-Type: application/json" "https://www.googleapis.com/storage/v1/b?project=$PROJECT_ID"

echo ""
echo "${GREEN}${BOLD}Command 1 Complete. You can now click 'Check my progress' for Task 4.${RESET}"
CYAN=$(tput setaf 6)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BOLD=$(tput bold)
RESET=$(tput sgr0)

echo "${CYAN}====================================================${RESET}"
echo "${GREEN}${BOLD}Command 2 of 2: REST API Object Upload${RESET}"
echo "${CYAN}====================================================${RESET}"

export PROJECT_ID=$(gcloud config get-value project)
export BUCKET_NAME="${PROJECT_ID}-bucket"
export OAUTH2_TOKEN=$(gcloud auth print-access-token)

echo "${YELLOW}Downloading sample demo-image.png...${RESET}"
wget -q -O demo-image.png https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png
export OBJECT=$(realpath demo-image.png)

echo "${YELLOW}Executing POST request to upload image to $BUCKET_NAME...${RESET}"
curl -s -X POST --data-binary @$OBJECT -H "Authorization: Bearer $OAUTH2_TOKEN" -H "Content-Type: image/png" "https://www.googleapis.com/upload/storage/v1/b/$BUCKET_NAME/o?uploadType=media&name=demo-image"

echo ""
echo "${GREEN}${BOLD}🎉 AUTOMATION COMPLETED SUCCESSFULLY 🎉${RESET}"
echo "${CYAN}You can now click 'Check my progress' for Task 5 and conclude the lab.${RESET}"