dashboardwireguard-tunnelwireguard-dashboardwireguardwg-managervpnsite-to-siteobfuscationwireguard-vpn-setupwireguard-vpn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
610 B
28 lines
610 B
5 years ago
|
from sqlalchemy.orm import Session
|
||
|
|
||
4 years ago
|
from database import models
|
||
5 years ago
|
|
||
|
|
||
5 years ago
|
def add_initial_api_key_for_admin(sess: Session, api_key, ADMIN_USERNAME):
|
||
5 years ago
|
|
||
|
db_user = sess.query(models.User)\
|
||
5 years ago
|
.filter_by(username=ADMIN_USERNAME)\
|
||
5 years ago
|
.one()
|
||
|
|
||
|
exists_api_key = sess.query(models.UserAPIKey)\
|
||
|
.filter_by(
|
||
|
user_id=db_user.id,
|
||
|
key=api_key
|
||
|
)\
|
||
|
.count()
|
||
|
|
||
|
if exists_api_key == 0:
|
||
|
db_api_key = models.UserAPIKey()
|
||
|
db_api_key.key = api_key
|
||
|
db_api_key.user_id = db_user.id
|
||
|
|
||
|
sess.add(db_api_key)
|
||
|
sess.commit()
|
||
|
|
||
|
return True
|