Skip to content

Commit 9e80003

Browse files
committed
Add example script to print auth header required in Playground at /api/graphql
1 parent ad09fc5 commit 9e80003

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

examples/get_tenant_token.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
import sys
3+
from getpass import getpass
4+
from iot_inspector_client import Client
5+
6+
API_URL = "https://demo.iot-inspector.com/api"
7+
EMAIL = sys.argv[1]
8+
PASSWORD = getpass()
9+
10+
11+
print("Login to IoT Inspector", EMAIL, "@", API_URL)
12+
client = Client(API_URL)
13+
client.login(EMAIL, PASSWORD)
14+
tenants = client.get_all_tenants()
15+
16+
print("Tenants:", ", ".join([tenant.name for tenant in tenants]))
17+
18+
if len(sys.argv) > 2:
19+
# Filter tenants that matches the provided pattern
20+
tenants = filter(lambda tenant: sys.argv[2] in tenant.name, tenants)
21+
22+
# Pick the first one
23+
tenant = tenants[0]
24+
25+
print("Using tenant:", tenant.name)
26+
client.use_tenant(tenant)
27+
28+
print(json.dumps(client.get_auth_headers()))

0 commit comments

Comments
 (0)