# GoogleApi Provider Internal microservice that handles Google Ads API operations. Called by the Gateway via HTTP. ## Architecture ``` ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │ Client │ ──────► │ Gateway │ ──────► │ GoogleApi │ │ │ │ (external) │ │ (internal) │ └──────────────┘ └──────────────┘ └──────────────────┘ │ │ │ X-Internal-Key │ │ header auth │ ▼ ▼ POST /api/execute POST /internal/execute ``` ## Local Development ```bash # Run locally cd GoogleApi dotnet run # Test health curl http://localhost:5180/internal/health # Test execute (with auth header) curl -X POST http://localhost:5180/internal/execute \ -H "Content-Type: application/json" \ -H "X-Internal-Key: dev-test-key-12345" \ -d '{"operation": "Ping", "requestId": "test-123"}' # Test create campaign curl -X POST http://localhost:5180/internal/execute \ -H "Content-Type: application/json" \ -H "X-Internal-Key: dev-test-key-12345" \ -d '{ "operation": "CreateCampaign", "tenantId": "1234567890", "requestId": "test-456", "payload": { "name": "Test Campaign", "budgetMicros": 10000000, "type": "Search" } }' ``` ## Supported Operations | Operation | Description | Payload | |-----------|-------------|---------| | `Ping` | Health check | none | | `CreateCampaign` | Create a campaign | `name`, `budgetMicros`, `type`, `biddingStrategy` | | `GetCampaign` | Get campaign details | `campaignId` | | `UpdateCampaign` | Update campaign | `campaignId`, `name?`, `budgetMicros?`, `status?` | | `ListCampaigns` | List all campaigns | `statusFilter?`, `pageSize?`, `pageToken?` | | `GetCampaignStats` | Get campaign metrics | `campaignId`, `startDate?`, `endDate?` | | `GetAccountStats` | Get account metrics | `startDate?`, `endDate?` | ## Azure Deployment ### First-time setup ```bash # Create the container app (internal ingress) az containerapp create \ --name usim-adp-googleapi \ --resource-group RG-GraeJones \ --environment AdPlatform-env-20260114160411 \ --image mcr.microsoft.com/dotnet/samples:aspnetapp \ --target-port 8080 \ --ingress internal \ --min-replicas 1 \ --max-replicas 3 # Set up managed identity for ACR (do this once) az role assignment create \ --assignee $(az containerapp show -n usim-adp-googleapi -g RG-GraeJones --query identity.principalId -o tsv) \ --role AcrPull \ --scope /subscriptions/ad4c8963-6467-4ccf-bdf6-208a73b0a2af/resourceGroups/RG-GraeJones/providers/Microsoft.ContainerRegistry/registries/adplatform20260114160834 # Configure registry with managed identity az containerapp registry set \ --name usim-adp-googleapi \ --resource-group RG-GraeJones \ --server adplatform20260114160834.azurecr.io \ --identity system # Set the internal key secret az containerapp secret set \ --name usim-adp-googleapi \ --resource-group RG-GraeJones \ --secrets google-internal-key="your-secret-key-here" # Set environment variables az containerapp update \ --name usim-adp-googleapi \ --resource-group RG-GraeJones \ --set-env-vars "GOOGLE_INTERNAL_KEY=secretref:google-internal-key" ``` ### Publish from Visual Studio 1. Right-click project → Publish 2. Select the `usim-adp-googleapi` profile 3. Click Publish ### Publish from CLI ```bash # Build and push to ACR dotnet publish -c Release # Or manually az acr build --registry adplatform20260114160834 --image googleapi:$(date +%Y%m%d%H%M%S) . # Update container app az containerapp update \ --name usim-adp-googleapi \ --resource-group RG-GraeJones \ --image adplatform20260114160834.azurecr.io/googleapi: ``` ### Verify deployment ```bash # Check revision status az containerapp revision list -n usim-adp-googleapi -g RG-GraeJones -o table # Check logs az containerapp logs show -n usim-adp-googleapi -g RG-GraeJones --type console az containerapp logs show -n usim-adp-googleapi -g RG-GraeJones --type system # Check env vars az containerapp show -n usim-adp-googleapi -g RG-GraeJones --query "properties.template.containers[0].env" ``` ## Gateway Configuration Update Gateway's environment variables to point to GoogleApi: ```bash az containerapp update \ --name usim-adp-gateway \ --resource-group RG-GraeJones \ --set-env-vars "GOOGLE_PROVIDER_URL=https://usim-adp-googleapi.internal.lemonbeach-1e8e273b.westus.azurecontainerapps.io" ``` ## Environment Variables | Variable | Description | Required | |----------|-------------|----------| | `PORT` | HTTP listen port | No (default: 8080) | | `GOOGLE_INTERNAL_KEY` | Shared secret for Gateway auth | Yes | | `ASPNETCORE_ENVIRONMENT` | Runtime environment | No | ## Troubleshooting ### Container stuck in "Activating" 1. Check system logs for image pull errors 2. Verify ACR credentials/managed identity 3. Verify image exists: `az acr repository show-tags --name adplatform20260114160834 --repository googleapi` ### No console output Check that `Program.cs` has explicit port binding: ```csharp var port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; builder.WebHost.UseUrls($"http://0.0.0.0:{port}"); ``` ### Auth failures 1. Verify `GOOGLE_INTERNAL_KEY` is set in both Gateway and GoogleApi 2. Check the secret reference is correct: `secretref:google-internal-key` 3. Test with curl using the `-H "X-Internal-Key: ..."` header