homeassistant: Convert auth command to python

This commit is contained in:
Timo Makinen 2024-12-22 18:22:19 +00:00
parent cfcdb4e935
commit 81252de145
3 changed files with 27 additions and 20 deletions

View file

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import os
import re
import sys
import requests
username = os.environ.get("username")
password = os.environ.get("password")
if username is None or password is None:
sys.exit(2)
if not re.search(r"^[a-z]+$", username):
sys.exit(2)
resp = requests.post(
"https://id.foo.sh/authcheck",
json={"username": username, "password": password, "group": "foosh"},
)
if resp.status_code != 200:
sys.exit(2)
print("name = {}".format(resp.json()["name"]))
print("group = system-users")
print("local_only = false")