-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-UpSnap-Keys.py
More file actions
66 lines (54 loc) · 1.94 KB
/
Copy pathGet-UpSnap-Keys.py
File metadata and controls
66 lines (54 loc) · 1.94 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
import requests
import argparse
import json
import sys
# Setup command line arguments
def parse_arguments():
parser = argparse.ArgumentParser(description="UpSnap Device Debugger")
parser.add_argument("--url", required=True, help="UpSnap URL (e.g., http://localhost:8090)")
parser.add_argument("--username", required=True, help="UpSnap Username")
parser.add_argument("--password", required=True, help="UpSnap Password")
return parser.parse_args()
def main():
args = parse_arguments()
# 1. Authenticate
print(f"Authenticating with {args.url}...")
auth_url = f"{args.url}/api/collections/users/auth-with-password"
try:
auth_resp = requests.post(auth_url, json={"identity": args.username, "password": args.password})
auth_resp.raise_for_status()
token = auth_resp.json().get("token")
print("Authentication successful.\n")
except Exception as e:
print(f"Authentication Failed: {e}")
sys.exit(1)
# 2. Get Devices
print("Fetching device list...")
devices_url = f"{args.url}/api/collections/devices/records"
headers = {'Authorization': f'Bearer {token}'}
try:
dev_resp = requests.get(devices_url, headers=headers)
dev_resp.raise_for_status()
data = dev_resp.json()
except Exception as e:
print(f"Failed to fetch devices: {e}")
sys.exit(1)
items = data.get("items", [])
if not items:
print("No devices found in UpSnap.")
sys.exit(0)
# 3. Print Results
first_device = items[0]
print("-" * 40)
print(f"Found {len(items)} devices.")
print(f"Here is the raw data for the first device found:")
print("-" * 40)
# Pretty print the JSON
print(json.dumps(first_device, indent=4))
print("-" * 40)
print("AVAILABLE VARIABLES (Keys):")
print("-" * 40)
for key in first_device.keys():
print(f"- {key}")
if __name__ == "__main__":
main()