def secret_key(): """ Get secret key from datastore. Read Secret Key from db. If one does not exist, create one and the event gets logged since this is an important security event """ secret_check = ndb.gql("SELECT key_string FROM Secret") key = secret_check.get() if key: # if key is present return it return key.key_string else: # if not make one and return/store it new_key = binascii.b2a_hqx(os.urandom(64)) # 64-bits of ASCII k = Secret(key_string=new_key) k.put() logging.critical("A NEW SECRET KEY HAS BEEN CREATED FOR HMAC") return new_key
def create_secret(id, value='secret'): secret = Secret(id=id, value=value) secret.put() return secret