-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup-http-functions.sh
More file actions
executable file
·95 lines (78 loc) · 3.01 KB
/
cleanup-http-functions.sh
File metadata and controls
executable file
·95 lines (78 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Cleanup HTTP Functions Script
# Moves HTTP functions from production index.js to index-emulator.js for security
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$SCRIPT_DIR/../esg_microservices_platform"
echo "🧹 Cleaning up HTTP functions from production services..."
echo "=================================================="
# Function to backup and move HTTP functions
move_http_functions() {
local service_name="$1"
local service_dir="$PROJECT_DIR/services/$service_name"
if [ ! -d "$service_dir" ]; then
echo "❌ Service directory not found: $service_name"
return 1
fi
local index_file="$service_dir/index.js"
local emulator_file="$service_dir/index-emulator.js"
if [ ! -f "$index_file" ]; then
echo "❌ index.js not found: $index_file"
return 1
fi
echo "🔍 Processing $service_name..."
# Create emulator file if it doesn't exist
if [ ! -f "$emulator_file" ]; then
echo " 📝 Creating $emulator_file"
cat > "$emulator_file" << 'EOF'
// Emulator-only functions for $service_name
// These are ADDITIONAL functions not needed in production
const { onRequest } = require('firebase-functions/v2/https');
console.log('🔧 $service_name: Emulator-only functions loaded');
EOF
fi
# Find HTTP functions in index.js
local http_functions=$(grep -n "exports\.[a-zA-Z_][a-zA-Z0-9_]* = onRequest" "$index_file" | head -10)
if [ -n "$http_functions" ]; then
echo " 🚨 Found HTTP functions in production:"
echo "$http_functions" | sed 's/^/ /'
# Backup the original file
cp "$index_file" "$index_file.backup-$(date +%Y%m%d_%H%M%S)"
echo " 💾 Backed up to $index_file.backup-$(date +%Y%m%d_%H%M%S)"
# TODO: Implement function extraction logic
echo " ⚠️ Manual cleanup required for $service_name"
else
echo " ✅ No HTTP functions found in production"
fi
}
# List of services to process
services=(
"orchestrator-service"
"vector-search-service"
"score-calculation-service"
"category-extraction-service"
"products-extraction-service"
"sustainability-enrichment-service"
"eprel-enrichment-service"
"legal-compliance-service"
"product-image-service"
"ai-logging-service"
"embedding-service"
"compliance-enrichment-service"
"vector-category-comparison-service"
"circular-economy-service"
"supply-chain-transparency-service"
"social-impact-service"
"yaml-correction-service"
)
# Process each service
for service in "${services[@]}"; do
move_http_functions "$service"
echo ""
done
echo "🎯 Next steps:"
echo "1. Review each service's HTTP functions"
echo "2. Move them to index-emulator.js"
echo "3. Keep only PubSub functions in production index.js"
echo "4. Test deployment to ensure no HTTP functions remain"
echo ""
echo "⚠️ IMPORTANT: Only public-api-service should have HTTP functions in production!"