Develop and Secure APIs with Apigee X

Solution for Develop and Secure APIs with Apigee X. 1 lab: GSP363. Fast copy-paste commands for Google Cloud.

GSP363 — Develop and Secure APIs with Apigee X: Challenge Lab

Estimated time: 25 minutes

# 🚀 Develop and Secure APIs with Apigee X: Challenge Lab > ⚠️ **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 Apigee X, API management, IAM configuration, API proxies, API products, and developer account setup through practical exercises. Always attempt the lab yourself first and follow Google Cloud Skills Boost / Qwiklabs Terms

#!/bin/bash
# ==============================================================================
# ORBIT OF OPS - COMMAND 1 OF 1: FULL APIGEE AUTOMATION
# ==============================================================================
GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
BLUE='\e[1;34m'
MAGENTA='\e[1;35m'
WHITE='\e[1;37m'
RED='\e[1;31m'
RESET='\e[0m'
BOLD='\e[1m'

clear
echo -e "${CYAN}${BOLD}"
cat << "EOF"
  ____       _     _ _            __    ___            
 / __ \     | |   (_) |          / _|  / _ \           
| |  | |_ __| |__  _| |_   ___  | |_  | | | |_ __  ___ 
| |  | | '__| '_ \| | __| / _ \ |  _| | | | | '_ \/ __|
| |__| | |  | |_) | | |_ | (_) || |   | |_| | |_) \__ \
 \____/|_|  |_.__/|_|\__| \___/ |_|    \___/| .__/|___/
                                            | |        
                                            |_|        
EOF
echo -e "${RESET}"
echo -e "${BLUE}${BOLD}╔════════════════════════════════════════════════════════════╗${RESET}"
echo -e "${BLUE}${BOLD}║   🚀 COMMAND 1 OF 1: FULL APIGEE API & PROXY DEPLOYMENT    ║${RESET}"
echo -e "${BLUE}${BOLD}║   🌐 BROUGHT TO YOU BY ORBIT OF OPS                        ║${RESET}"
echo -e "${BLUE}${BOLD}╚════════════════════════════════════════════════════════════╝${RESET}\n"

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

echo -e "${BLUE}${BOLD}[Orbit of Ops] Task 1: Enabling Translation API & IAM Setup...${RESET}"
gcloud services enable translate.googleapis.com
gcloud iam service-accounts create apigee-proxy --display-name "Apigee Proxy Service Access" --quiet 2>/dev/null || true
gcloud projects add-iam-policy-binding $PROJECT_ID \
  --member="serviceAccount:apigee-proxy@$PROJECT_ID.iam.gserviceaccount.com" \
  --role="roles/logging.logWriter" --quiet

echo -e "\n${YELLOW}${BOLD}[Orbit of Ops] Waiting for Apigee Runtime to Provision... (This will take 15-20 minutes!)${RESET}"
export INSTANCE_NAME=eval-instance
export ENV_NAME=eval
export PREV_INSTANCE_STATE=

while : ; do
    export INSTANCE_STATE=$(curl -s -H "Authorization: Bearer $(gcloud auth print-access-token)" -X GET "https://apigee.googleapis.com/v1/organizations/${PROJECT_ID}/instances/${INSTANCE_NAME}" | jq "select(.state != null) | .state" --raw-output)
    [[ "${INSTANCE_STATE}" == "${PREV_INSTANCE_STATE}" ]] || (echo -e "\n${CYAN}INSTANCE_STATE=${INSTANCE_STATE}${RESET}")
    export PREV_INSTANCE_STATE=${INSTANCE_STATE}
    [[ "${INSTANCE_STATE}" != "ACTIVE" ]] || break
    echo -n "."
    sleep 15
done
echo -e "\n${GREEN}Instance is ACTIVE! Waiting for environment attachment...${RESET}"

while : ; do
    export ATTACHMENT_DONE=$(curl -s -H "Authorization: Bearer $(gcloud auth print-access-token)" -X GET "https://apigee.googleapis.com/v1/organizations/${PROJECT_ID}/instances/${INSTANCE_NAME}/attachments" | jq "select(.attachments != null) | .attachments[] | select(.environment == \"${ENV_NAME}\") | .environment" --join-output)
    [[ "${ATTACHMENT_DONE}" != "${ENV_NAME}" ]] || break
    echo -n "."
    sleep 15
done
echo -e "\n${GREEN}${BOLD}*** APIGEE ORG IS READY TO USE ***${RESET}"

echo -e "\n${BLUE}${BOLD}[Orbit of Ops] Tasks 2-5: Downloading Pre-configured API Proxy Bundle...${RESET}"
curl -L "https://drive.google.com/uc?export=download&id=1IxJMjqAJ-FVKWOdg2HnJ79wY7BBlbjbJ" -o translate-v1.zip

echo -e "\n${BLUE}${BOLD}[Orbit of Ops] Importing API Proxy to Apigee...${RESET}"
curl -s -X POST "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/apis?action=import&name=translate-v1" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/octet-stream" \
  --data-binary @translate-v1.zip

echo -e "\n${BLUE}${BOLD}[Orbit of Ops] Deploying API Proxy to Eval Environment...${RESET}"
curl -s -X POST "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/environments/eval/apis/translate-v1/revisions/1/deployments?serviceAccount=apigee-proxy@$PROJECT_ID.iam.gserviceaccount.com" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)"

echo -e "\n${BLUE}${BOLD}[Orbit of Ops] Creating API Product (translate-product)...${RESET}"
cat > translate-product.json <<EOF_END
{
  "name": "translate-product",
  "displayName": "translate-product",
  "approvalType": "auto",
  "attributes": [
    {"name": "access", "value": "public"}
  ],
  "environments": ["eval"],
  "operationGroup": {
    "operationConfigs": [
      {
        "apiSource": "translate-v1",
        "operations": [
          {
            "resource": "/",
            "methods": ["GET", "POST"]
          }
        ],
        "quota": {
          "limit": "10",
          "interval": "1",
          "timeUnit": "minute"
        }
      }
    ],
    "operationConfigType": "proxy"
  }
}
EOF_END

curl -s -X POST "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/apiproducts" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d @translate-product.json

echo -e "\n${BLUE}${BOLD}[Orbit of Ops] Creating Developer Account...${RESET}"
curl -s -X POST "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/developers" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "firstName": "Joe",
    "lastName": "Developer",
    "userName": "joe"
  }'

echo -e "\n${BLUE}${BOLD}[Orbit of Ops] Creating Developer App (translate-app)...${RESET}"
curl -s -X POST "https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/developers/[email protected]/apps" \
  -H "Authorization: Bearer $(gcloud auth print-access-token)" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "translate-app",
    "apiProducts": ["translate-product"]
  }'

echo -e "\n${MAGENTA}${BOLD}╔════════════════════════════════════════════════════════════╗${RESET}"
echo -e "${MAGENTA}${BOLD}║           🎉 AUTOMATION COMPLETED SUCCESSFULLY 🎉          ║${RESET}"
echo -e "${MAGENTA}${BOLD}╚════════════════════════════════════════════════════════════╝${RESET}"
echo -e "${WHITE}${BOLD}You can now check all your progress in the lab manual!${RESET}"
#!/bin/bash
# ==============================================================================
# ORBIT OF OPS - TARGETED FIX: APIGEE PROXY SERVICE ACCOUNT
# ==============================================================================
GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
RESET='\e[0m'
BOLD='\e[1m'

echo -e "${CYAN}${BOLD}╔════════════════════════════════════════════════════════════╗${RESET}"
echo -e "${CYAN}${BOLD}║   🛠️ TARGETED FIX: SERVICE ACCOUNT & IAM PROPAGATION       ║${RESET}"
echo -e "${CYAN}${BOLD}╚════════════════════════════════════════════════════════════╝${RESET}\n"

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

echo -e "${YELLOW}${BOLD}[Orbit of Ops] Creating 'apigee-proxy' service account...${RESET}"
gcloud iam service-accounts create apigee-proxy \
    --display-name="apigee-proxy" \
    --quiet 2>/dev/null || echo -e "${CYAN}Service account already exists, proceeding to IAM binding...${RESET}"

echo -e "\n${YELLOW}${BOLD}[Orbit of Ops] Assigning 'Logs Writer' role...${RESET}"
gcloud projects add-iam-policy-binding $PROJECT_ID \
    --member="serviceAccount:apigee-proxy@${PROJECT_ID}.iam.gserviceaccount.com" \
    --role="roles/logging.logWriter" \
    --quiet

echo -e "\n${YELLOW}${BOLD}[Orbit of Ops] Forcing a 30-second wait for IAM propagation...${RESET}"
for i in {30..1}; do
    echo -ne "\rWaiting: $i seconds remaining...   "
    sleep 1
done

echo -e "\n\n${GREEN}${BOLD}✅ Fix applied successfully!${RESET}"