homeassistant: Convert auth command to python
This commit is contained in:
parent
cfcdb4e935
commit
81252de145
3 changed files with 27 additions and 20 deletions
25
roles/homeassistant/files/auth-command.py
Executable file
25
roles/homeassistant/files/auth-command.py
Executable 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")
|
Loading…
Add table
Add a link
Reference in a new issue