-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_label.py
38 lines (32 loc) · 1.41 KB
/
create_label.py
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
import os
import requests
from config import base_url
def create_label():
# List of supported label types
label_types = ["agents", "tests", "endpoint-agents", "endpoint-tests", "dashboards"]
print("Select the type of label you want to create:")
for i, label_type in enumerate(label_types, start=1):
print(f"{i}. {label_type}")
while True:
type_choice = input("Enter your choice (or 'b' to go back): ")
if type_choice.lower() == 'b':
return # Return to the previous menu
try:
label_type = label_types[int(type_choice) - 1]
break
except (IndexError, ValueError):
print("Invalid choice. Please enter a number between 1 and", len(label_types))
label_name = input("Enter a name for the label: ")
headers = {
'Authorization': 'Bearer ' + os.environ['OAUTH_TOKEN'],
'Content-Type': 'application/json',
}
data = {
'name': label_name,
}
response = requests.post(f"{base_url}/groups/{label_type}/new.json", headers=headers, json=data)
if response.status_code == 201: # 201 Created is standard response for successful HTTP POST requests
label = response.json()['groups'][0]
print(f"Label '{label['name']}' created successfully. ID: {label['groupId']}, Type: {label['type']}")
else:
print("Error creating label: received status code", response.status_code)