mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: add util/adduser.py database tooling script
We'll need to add tests for these things at some point. However, I'd like to include this script in here immediately for ease of testing or administration in general. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
aee1390e2c
commit
7e58986356
1 changed files with 67 additions and 0 deletions
67
util/adduser.py
Normal file
67
util/adduser.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
import argparse
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
from aurweb import db
|
||||
from aurweb.models.account_type import AccountType
|
||||
from aurweb.models.ssh_pub_key import SSHPubKey, get_fingerprint
|
||||
from aurweb.models.user import User
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="aurweb-adduser options")
|
||||
|
||||
parser.add_argument("-u", "--username", help="Username", required=True)
|
||||
parser.add_argument("-e", "--email", help="Email", required=True)
|
||||
parser.add_argument("-p", "--password", help="Password", required=True)
|
||||
parser.add_argument("-r", "--realname", help="Real Name")
|
||||
parser.add_argument("-i", "--ircnick", help="IRC Nick")
|
||||
parser.add_argument("--pgp-key", help="PGP Key Fingerprint")
|
||||
parser.add_argument("--ssh-pubkey", help="SSH PubKey")
|
||||
|
||||
parser.add_argument("-t", "--type", help="Account Type",
|
||||
choices=[
|
||||
"User",
|
||||
"Trusted User",
|
||||
"Developer",
|
||||
"Trusted User & Developer"
|
||||
], default="User")
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
|
||||
type = db.query(AccountType,
|
||||
AccountType.AccountType == args.type).first()
|
||||
with db.begin():
|
||||
user = db.create(User, Username=args.username,
|
||||
Email=args.email, Passwd=args.password,
|
||||
RealName=args.realname, IRCNick=args.ircnick,
|
||||
PGPKey=args.pgp_key, AccountType=type)
|
||||
|
||||
if args.ssh_pubkey:
|
||||
pubkey = args.ssh_pubkey.strip()
|
||||
|
||||
# Remove host from the pubkey if it's there.
|
||||
pubkey = ' '.join(pubkey.split(' ')[:2])
|
||||
|
||||
with db.begin():
|
||||
db.create(SSHPubKey,
|
||||
User=user,
|
||||
PubKey=pubkey,
|
||||
Fingerprint=get_fingerprint(pubkey))
|
||||
|
||||
print(user.json())
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
e = 1
|
||||
try:
|
||||
e = main()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
e = 1
|
||||
sys.exit(e)
|
Loading…
Add table
Reference in a new issue