flask_key.py
1 |
#!/usr/bin/env python
|
---|---|
2 |
# -*- coding :utf-8 -*-
|
3 |
|
4 |
from json import dumps, loads |
5 |
from hashlib import sha256 |
6 |
from os import urandom |
7 |
|
8 |
|
9 |
#def _find_container(app_name):
|
10 |
# from os.path import join
|
11 |
# from creole import eosfunc
|
12 |
# cont = eosfunc.load_container_var()
|
13 |
# if cont.has_key('container_path_fichier'):
|
14 |
# filepath = join("/", cont['container_path_fichier'].lstrip("/"),
|
15 |
# 'etc/controlevnc/.secret')
|
16 |
# return filepath
|
17 |
# return None
|
18 |
|
19 |
SECRET_KEYS = {} |
20 |
|
21 |
def _save_dict(): |
22 |
""" Save the secret keys dict """
|
23 |
|
24 |
def _get_dict(): |
25 |
""" Get the secret keys dict """
|
26 |
|
27 |
def _generate_key(app_name=None): |
28 |
""" Generate or update the key for app_name """
|
29 |
secret = sha256(urandom(24)).hexdigest()
|
30 |
return secret
|
31 |
|
32 |
def get_key(app_name=None): |
33 |
""" Get the key for app_name """
|
34 |
|
35 |
if app_name is None: |
36 |
return None |
37 |
if SECRET_KEYS.has_key(app_name):
|
38 |
return SECRET_KEYS[app_name]
|
39 |
else:
|
40 |
SECRET_KEYS[app_name]=_generate_key(app_name) |
41 |
return get_key(app_name)
|
42 |
|