Skip to content

Commit f24ade3

Browse files
added check if team exist while uploading the team
1 parent d039550 commit f24ade3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

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)