-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_admin_session
33 lines (29 loc) · 957 Bytes
/
start_admin_session
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
30
31
32
33
#!/usr/bin/env python
import datetime
from sqlalchemy.exc import NoResultFound
from hw_diag.database import get_db_session
from hw_diag.database.models.auth import AuthKeyValue
def main():
db = get_db_session()
now = datetime.datetime.utcnow()
two_mins = now + datetime.timedelta(minutes=2)
try:
admin_session_expires_row = db.query(AuthKeyValue). \
filter(AuthKeyValue.key == 'admin_session_expires'). \
one()
admin_session_expires_row.value = two_mins.isoformat()
db.commit()
db.close_all()
except NoResultFound:
admin_session_expires_row = AuthKeyValue(
key='admin_session_expires',
value=two_mins.isoformat()
)
db.add(admin_session_expires_row)
db.commit()
db.close_all()
finally:
db.close_all()
print("You may now spawn an admin session on the device.")
if __name__ == '__main__':
main()