Skip to content

Commit 7a081cf

Browse files
Merge pull request #593 from microsoft/psl-bug-25477
fix: added check if team exist while uploading the team
2 parents d039550 + 1e83598 commit 7a081cf

File tree

3 files changed

+130
-32
lines changed

3 files changed

+130
-32
lines changed

azure.yaml

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,60 @@ hooks:
88
postdeploy:
99
windows:
1010
run: |
11-
Write-Host "To upload Team Configurations to Cosmos. Run the following command in PowerShell:"
12-
Write-Host "infra\scripts\Upload-Team-Config.ps1" -ForegroundColor Cyan
1311
Write-Host ""
14-
Write-Host "To index Sample Data into Azure Search. Run the following command in PowerShell:"
15-
Write-Host "infra\scripts\Process-Sample-Data.ps1" -ForegroundColor Cyan
12+
Write-Host "===============================================================" -ForegroundColor Yellow
13+
Write-Host " POST-DEPLOYMENT STEPS (PowerShell) " -ForegroundColor Green
14+
Write-Host "===============================================================" -ForegroundColor Yellow
1615
Write-Host ""
17-
Write-Host "To upload team configurations and index sample data both in one command, you can use the following command in PowerShell:"
18-
Write-Host "infra\scripts\Team-Config-And-Data.ps1" -ForegroundColor Cyan
16+
17+
Write-Host " STEP 1: Upload Team Configurations to Cosmos DB" -ForegroundColor White
18+
Write-Host " 👉 Run the following command in PowerShell:" -ForegroundColor White
19+
Write-Host " infra\scripts\Upload-Team-Config.ps1" -ForegroundColor Cyan
20+
Write-Host ""
21+
22+
Write-Host " STEP 2: Index Sample Data into Azure Search" -ForegroundColor White
23+
Write-Host " 👉 Run the following command in PowerShell:" -ForegroundColor White
24+
Write-Host " infra\scripts\Process-Sample-Data.ps1" -ForegroundColor Cyan
25+
Write-Host ""
26+
27+
Write-Host "💡 Alternatively, you can run above BOTH steps together using:" -ForegroundColor Yellow
28+
Write-Host " infra\scripts\Team-Config-And-Data.ps1" -ForegroundColor Cyan
29+
Write-Host ""
30+
31+
Write-Host "🌐 Access your deployed Frontend application at:" -ForegroundColor Green
32+
Write-Host " https://$env:webSiteDefaultHostname" -ForegroundColor Cyan
1933
Write-Host ""
20-
Write-Host "You can access the deployed Frontend application at the following URL:"
21-
Write-Host "https://$env:webSiteDefaultHostname" -ForegroundColor Cyan
2234
shell: pwsh
2335
interactive: true
2436
posix:
2537
run: |
2638
Blue='\033[0;34m'
39+
Green='\033[0;32m'
40+
Yellow='\033[1;33m'
2741
NC='\033[0m'
28-
echo "To upload Team Configurations to Cosmos. Run the following command in Bash:"
29-
echo "${Blue}bash infra/scripts/upload_team_config.sh"
42+
43+
echo ""
44+
echo "${Yellow}==============================================================="
45+
echo "${Green} POST-DEPLOYMENT STEPS (Bash) "
46+
echo "${Yellow}===============================================================${NC}"
47+
echo ""
48+
49+
echo " STEP 1: Upload Team Configurations to Cosmos DB"
50+
echo " 👉 Run the following command in Bash:"
51+
echo " ${Blue}bash infra/scripts/upload_team_config.sh${NC}"
52+
echo ""
53+
54+
echo " STEP 2: Index Sample Data into Azure Search"
55+
echo " 👉 Run the following command in Bash:"
56+
echo " ${Blue}bash infra/scripts/process_sample_data.sh${NC}"
3057
echo ""
31-
echo "${NC}To index Sample Data into Azure Search. Run the following command in Bash:"
32-
echo "${Blue}bash infra/scripts/process_sample_data.sh"
58+
59+
echo "💡 Alternatively, you can run above BOTH steps together using:"
60+
echo " ${Blue}bash infra/scripts/team_config_and_data.sh${NC}"
3361
echo ""
34-
echo "${NC}To upload team configurations and index sample data both in one command, you can use the following command in Bash:"
35-
echo "${Blue}bash infra/scripts/team_config_and_data.sh"
62+
63+
echo "🌐 Access your deployed Frontend application at:"
64+
echo " ${Blue}https://$webSiteDefaultHostname${NC}"
3665
echo ""
37-
echo "${NC}You can access the deployed Frontend application at the following URL:"
38-
echo "${Blue}https://$webSiteDefaultHostname"
3966
shell: sh
4067
interactive: true

azure_custom.yaml

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,60 @@ hooks:
4545
postdeploy:
4646
windows:
4747
run: |
48-
Write-Host "To upload Team Configurations to Cosmos. Run the following command in PowerShell:"
49-
Write-Host "infra\scripts\Upload-Team-Config.ps1" -ForegroundColor Cyan
5048
Write-Host ""
51-
Write-Host "To index Sample Data into Azure Search. Run the following command in PowerShell:"
52-
Write-Host "infra\scripts\Process-Sample-Data.ps1" -ForegroundColor Cyan
49+
Write-Host "===============================================================" -ForegroundColor Yellow
50+
Write-Host " POST-DEPLOYMENT STEPS (PowerShell) " -ForegroundColor Green
51+
Write-Host "===============================================================" -ForegroundColor Yellow
5352
Write-Host ""
54-
Write-Host "If you want to run both scripts as single command, you can use the following command in PowerShell:"
55-
Write-Host "infra\scripts\Team-Config-And-Data.ps1" -ForegroundColor Cyan
53+
54+
Write-Host " STEP 1: Upload Team Configurations to Cosmos DB" -ForegroundColor White
55+
Write-Host " 👉 Run the following command in PowerShell:" -ForegroundColor White
56+
Write-Host " infra\scripts\Upload-Team-Config.ps1" -ForegroundColor Cyan
57+
Write-Host ""
58+
59+
Write-Host " STEP 2: Index Sample Data into Azure Search" -ForegroundColor White
60+
Write-Host " 👉 Run the following command in PowerShell:" -ForegroundColor White
61+
Write-Host " infra\scripts\Process-Sample-Data.ps1" -ForegroundColor Cyan
62+
Write-Host ""
63+
64+
Write-Host "💡 Alternatively, you can run above BOTH steps together using:" -ForegroundColor Yellow
65+
Write-Host " infra\scripts\Team-Config-And-Data.ps1" -ForegroundColor Cyan
66+
Write-Host ""
67+
68+
Write-Host "🌐 Access your deployed Frontend application at:" -ForegroundColor Green
69+
Write-Host " https://$env:webSiteDefaultHostname" -ForegroundColor Cyan
5670
Write-Host ""
57-
Write-Host "You can access the deployed Frontend application at the following URL:"
58-
Write-Host "https://$env:webSiteDefaultHostname" -ForegroundColor Cyan
5971
shell: pwsh
6072
interactive: true
6173
posix:
6274
run: |
6375
Blue='\033[0;34m'
76+
Green='\033[0;32m'
77+
Yellow='\033[1;33m'
6478
NC='\033[0m'
65-
echo "To upload Team Configurations to Cosmos. Run the following command in Bash:"
66-
echo "${Blue}bash infra/scripts/upload_team_config.sh"
79+
6780
echo ""
68-
echo "${NC}To index Sample Data into Azure Search. Run the following command in Bash:"
69-
echo "${Blue}bash infra/scripts/process_sample_data.sh"
81+
echo "${Yellow}==============================================================="
82+
echo "${Green} POST-DEPLOYMENT STEPS (Bash) "
83+
echo "${Yellow}===============================================================${NC}"
7084
echo ""
71-
echo "${NC}If you want to run both scripts as single command, you can use the following command in Bash:"
72-
echo "${Blue}bash infra/scripts/team_config_and_data.sh"
85+
86+
echo " STEP 1: Upload Team Configurations to Cosmos DB"
87+
echo " 👉 Run the following command in Bash:"
88+
echo " ${Blue}bash infra/scripts/upload_team_config.sh${NC}"
89+
echo ""
90+
91+
echo " STEP 2: Index Sample Data into Azure Search"
92+
echo " 👉 Run the following command in Bash:"
93+
echo " ${Blue}bash infra/scripts/process_sample_data.sh${NC}"
94+
echo ""
95+
96+
echo "💡 Alternatively, you can run above BOTH steps together using:"
97+
echo " ${Blue}bash infra/scripts/team_config_and_data.sh${NC}"
98+
echo ""
99+
100+
echo "🌐 Access your deployed Frontend application at:"
101+
echo " ${Blue}https://$webSiteDefaultHostname${NC}"
73102
echo ""
74-
echo "${NC}You can access the deployed Frontend application at the following URL:"
75-
echo "${Blue}https://$webSiteDefaultHostname"
76103
shell: sh
77104
interactive: true

infra/scripts/upload_team_config.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
import sys
22
import os
33
import requests
4+
import json
5+
6+
def check_team_exists(backend_url, team_id, user_principal_id):
7+
"""
8+
Check if a team already exists in the database.
9+
10+
Args:
11+
backend_url: The backend endpoint URL
12+
team_id: The team ID to check
13+
user_principal_id: User principal ID for authentication
14+
15+
Returns:
16+
exists: bool
17+
"""
18+
check_endpoint = backend_url.rstrip('/') + f'/api/v3/team_configs/{team_id}'
19+
headers = {
20+
'x-ms-client-principal-id': user_principal_id
21+
}
22+
23+
try:
24+
response = requests.get(check_endpoint, headers=headers)
25+
if response.status_code == 200:
26+
return True
27+
elif response.status_code == 404:
28+
return False
29+
else:
30+
print(f"Error checking team {team_id}: Status {response.status_code}, Response: {response.text}")
31+
return False
32+
except Exception as e:
33+
print(f"Exception checking team {team_id}: {str(e)}")
34+
return False
435

536
if len(sys.argv) < 2:
637
print("Usage: python upload_team_config.py <backend_endpoint> <directory_path> [<user_principal_id>]")
@@ -28,6 +59,19 @@
2859
file_path = os.path.join(directory_path, filename)
2960
if os.path.isfile(file_path):
3061
print(f"Uploading file: {filename}")
62+
# Check if team already exists
63+
team_exists = check_team_exists(backend_url, team_id, user_principal_id)
64+
if team_exists:
65+
try:
66+
with open(file_path, 'r', encoding='utf-8') as f:
67+
team_data = json.load(f)
68+
team_name = team_data.get('name', 'Unknown')
69+
print(f"Team '{team_name}' (ID: {team_id}) already exists!")
70+
continue
71+
except Exception as e:
72+
print(f"Error reading {filename}: {str(e)}")
73+
continue
74+
3175
try:
3276
with open(file_path, 'rb') as file_data:
3377
files = {

0 commit comments

Comments
 (0)