Use APIs to Work with Cloud Storage

Solution for Use APIs to Work with Cloud Storage. 1 lab: ARC125. Fast copy-paste commands for Google Cloud.

ARC125 — Use APIs to Work with Cloud Storage: Challenge Lab

Estimated time: 10 minutes

# Cloud Storage API Challenge Lab Follow the execution sequence below exactly as shown to successfully complete all tasks. ## 🚀 Step-by-Step Instructions ### 🔹 Step 1 — Execute Command (1 of 2) 1. Open **Google Cloud Shell**. 2. Copy and paste **Command (1 of 2)** into the terminal. 3. Press **Enter**. This command will automatically: - ✅ Create the required JSON request files. - ✅ Create the required Cloud Storage buckets. - ✅ Download the required image. - ✅ Upload the image to **Bucke

GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
BLUE='\e[1;34m'
MAGENTA='\e[1;35m'
RED='\e[1;31m'
RESET='\e[0m'
BOLD='\e[1m'

clear
echo -e "${CYAN}${BOLD}"
cat << "EOF"
  ____       _     _ _            __    ___            
 / __ \     | |   (_) |          / _|  / _ \           
| |  | |_ __| |__  _| |_   ___  | |_  | | | |_ __  ___ 
| |  | | '__| '_ \| | __| / _ \ |  _| | | | | '_ \/ __|
| |__| | |  | |_) | | |_ | (_) || |   | |_| | |_) \__ \
 \____/|_|  |_.__/|_|\__| \___/ |_|    \___/| .__/|___/
                                            | |        
                                            |_|        
EOF
echo -e "${RESET}"
echo -e "${MAGENTA}${BOLD}>>> ORBIT OF OPS: ARC125 (TASKS 1-4) INITIALIZED <<<${RESET}\n"

export PROJECT_ID=$(gcloud config get-value project 2>/dev/null)
echo -e "${YELLOW}${BOLD}[*] Project ID: ${PROJECT_ID}${RESET}\n"

echo -e "${BLUE}${BOLD}[Orbit of Ops] Step 1: Creating Bucket 1...${RESET}"
cat > bucket1.json <<EOF
{
   "name": "$PROJECT_ID-bucket-1",
   "location": "us",
   "storageClass": "multi_regional"
}
EOF
curl -s -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" --data-binary @bucket1.json "https://storage.googleapis.com/storage/v1/b?project=$PROJECT_ID" > /dev/null

echo -e "${BLUE}${BOLD}[Orbit of Ops] Step 2: Creating Bucket 2...${RESET}"
cat > bucket2.json <<EOF
{
   "name": "$PROJECT_ID-bucket-2",
   "location": "us",
   "storageClass": "multi_regional"
}
EOF
curl -s -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" --data-binary @bucket2.json "https://storage.googleapis.com/storage/v1/b?project=$PROJECT_ID" > /dev/null

echo -e "${MAGENTA}${BOLD}[Orbit of Ops] Step 3: Downloading & Uploading Image...${RESET}"
curl -s -LO https://raw.githubusercontent.com/Orbit-of-Ops/Labs-Solutions/refs/heads/main/Use%20APIs%20to%20Work%20with%20Cloud%20Storage%20Challenge%20Lab/world.jpeg
curl -s -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: image/jpeg" --data-binary @world.jpeg "https://storage.googleapis.com/upload/storage/v1/b/$PROJECT_ID-bucket-1/o?uploadType=media&name=world.jpeg" > /dev/null

echo -e "${YELLOW}${BOLD}[Orbit of Ops] Step 4: Copying Image to Bucket 2...${RESET}"
curl -s -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" --data "{\"destination\": \"$PROJECT_ID-bucket-2\"}" "https://storage.googleapis.com/storage/v1/b/$PROJECT_ID-bucket-1/o/world.jpeg/copyTo/b/$PROJECT_ID-bucket-2/o/world.jpeg" > /dev/null

echo -e "${CYAN}${BOLD}[Orbit of Ops] Step 5: Setting Public Access...${RESET}"
cat > public_access.json <<EOF
{
  "entity": "allUsers",
  "role": "READER"
}
EOF
curl -s -X POST --data-binary @public_access.json -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" "https://storage.googleapis.com/storage/v1/b/$PROJECT_ID-bucket-1/o/world.jpeg/acl" > /dev/null

echo -e "\n${GREEN}${BOLD}>>> PAUSE! Go to Qwiklabs and check your progress for Tasks 1, 2, 3, and 4. <<<${RESET}"
echo -e "${RED}${BOLD}>>> DO NOT run Command 2 until you have secured the points for the first 4 tasks! <<<${RESET}"
GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
BOLD='\e[1m'
RESET='\e[0m'

export PROJECT_ID=$(gcloud config get-value project 2>/dev/null)

echo -e "${CYAN}${BOLD}[Orbit of Ops] Step 6: Deleting Image from Bucket 1...${RESET}"
curl -s -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage.googleapis.com/storage/v1/b/$PROJECT_ID-bucket-1/o/world.jpeg"

echo -e "${YELLOW}${BOLD}[Orbit of Ops] Step 7: Deleting Bucket 1...${RESET}"
curl -s -X DELETE -H "Authorization: Bearer $(gcloud auth print-access-token)" "https://storage.googleapis.com/storage/v1/b/$PROJECT_ID-bucket-1"

rm bucket1.json bucket2.json world.jpeg public_access.json 2>/dev/null

echo -e "\n${GREEN}${BOLD}>>> MISSION COMPLETE! Check your progress for Task 5 to finish the lab. <<<${RESET}"