Initial
This commit is contained in:
parent
9c556617e5
commit
d2da5894f1
1 changed files with 37 additions and 0 deletions
37
poll.py
Executable file
37
poll.py
Executable file
|
@ -0,0 +1,37 @@
|
||||||
|
#! /bin/env python3
|
||||||
|
from requests import get, post, patch
|
||||||
|
from os import getenv
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
fingerpass = getenv('FINGER_PW')
|
||||||
|
|
||||||
|
gitauth = (getenv('GIT_USER', getenv('GIT_PW'))
|
||||||
|
|
||||||
|
fingerurl = f'https://finger.stacken.kth.se/services/git/all'
|
||||||
|
|
||||||
|
response = get(fingerurl, auth=('git', fingerpass))
|
||||||
|
response.raise_for_status()
|
||||||
|
|
||||||
|
for (user, passwd) in response.json().items():
|
||||||
|
response = post('https://git.stacken.kth.se/api/v1/admin/users',
|
||||||
|
data={
|
||||||
|
"username": user,
|
||||||
|
"email": f"{user}@stacken.kth.se",
|
||||||
|
"password": passwd,
|
||||||
|
},
|
||||||
|
auth = ('fingerpoller', gitpass)
|
||||||
|
)
|
||||||
|
if response.status_code == 422:
|
||||||
|
patch(f'https://git.stacken.kth.se/api/v1/admin/users/{user}',
|
||||||
|
data = { "password": passwd },
|
||||||
|
auth = gitauth
|
||||||
|
).raise_for_status()
|
||||||
|
print(f"Updated password for {user}")
|
||||||
|
else:
|
||||||
|
response.raise_for_status()
|
||||||
|
print(f"Created user {user}")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue