dashboardwireguard-vpnwireguard-tunnelwireguard-dashboardwireguardwg-managervpnsite-to-siteobfuscationwireguard-vpn-setup
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
573 B
28 lines
573 B
5 years ago
|
from sqlalchemy.orm import Session
|
||
|
|
||
|
import models
|
||
|
|
||
|
|
||
|
def add_initial_api_key_for_admin(sess: Session, api_key):
|
||
|
|
||
|
db_user = sess.query(models.User)\
|
||
|
.filter_by(username="admin")\
|
||
|
.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
|