-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_user.py
More file actions
29 lines (22 loc) · 879 Bytes
/
add_user.py
File metadata and controls
29 lines (22 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import argparse
from sqlmodel import Session, create_engine
from murfey.server.api.auth import hash_password
from murfey.server.murfey_db import url
from murfey.util.config import get_global_config
from murfey.util.db import MurfeyUser as User
def run():
parser = argparse.ArgumentParser(
description="Generate the necessary tables for the Murfey database"
)
parser.add_argument("-u", "--username", type=str, help="User name for new user")
parser.add_argument("-p", "--password", type=str, help="Password for new user")
args = parser.parse_args()
new_user = User(
username=args.username, hashed_password=hash_password(args.password)
)
_url = url(get_global_config())
engine = create_engine(_url)
with Session(engine) as murfey_db:
murfey_db.add(new_user)
murfey_db.commit()
murfey_db.close()