forked from Gig-o-Matic/GO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_db.py
More file actions
45 lines (35 loc) · 891 Bytes
/
crypto_db.py
File metadata and controls
45 lines (35 loc) · 891 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
crypto class for Gig-o-Matic 2
Aaron Oppenheimer
4 March 2016
"""
from google.appengine.ext import ndb
#
# class for cryptokey
#
class CryptoKey(ndb.Model):
""" Models a crypto key """
value = ndb.TextProperty()
def set_cryptokey(value):
""" sets the crypto key """
the_cryptokey = get_cryptokey_object()
if the_cryptokey:
the_cryptokey.value=value
the_cryptokey.put()
else:
the_cryptokey = CryptoKey(value=value)
the_cryptokey.put()
def get_cryptokey_object():
""" Return the cryptokey if there is one """
cryptokey_query = CryptoKey.query()
cryptokey = cryptokey_query.fetch(1)
if len(cryptokey) == 0:
return None
else:
return cryptokey[0]
def get_cryptokey():
m = get_cryptokey_object()
if m:
return m.value
else:
return None