mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: add aurweb-adduser console script
Originally left at util/adduser.py, this script allows administrators to simply add a user to the configured aurweb database. See --help for options. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
9e7ae5904f
commit
6f6f067597
3 changed files with 69 additions and 6 deletions
|
@ -1,68 +0,0 @@
|
|||
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()
|
||||
|
||||
db.get_engine()
|
||||
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
Add a link
Reference in a new issue