Navigation Menu

Skip to content

Commit

Permalink
improved key generator
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillkultinov committed Dec 10, 2018
1 parent 92a5cde commit 50a6180
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions keyGenerator.py
@@ -1,20 +1,8 @@
import json, os
import random
import string
from elasticsearch import Elasticsearch

# key generator for 'api-keys' index

# mapping curl -X GET "localhost:9200/api-keys/_mapping/doc" | jq

'''data curl -X GET "localhost:9200/api-keys/_search" -H 'Content-Type: application/json' -d'
{
"size" : 10000,
"query": {
"match_all" : {}
}
}
' |jq'''
import hashlib
#from elasticsearch import Elasticsearch

def generate_key(length):
char_set = string.ascii_letters
Expand Down Expand Up @@ -42,11 +30,17 @@ def main():
limits = raw_input('Enter any limits of the requester: ')
# get other-info
other_info = raw_input('Enter any other info about the requester: ')

genKey = generate_key(40)

# get seed
seed = raw_input('Enter seed: ')
while not seed:
seed = input('Enter non empty seed: ')
seed = hashlib.md5(seed).hexdigest()

genKey = generate_key(20)
genKey = genKey.encode('base64')
genKey = genKey[:-3]
genKey = seed + '-' + genKey
print('Generated API key: ' + genKey)

#add the key and info to ES
body = {
"record": {
Expand All @@ -62,9 +56,6 @@ def main():
print("All information has been added to ES database")







if __name__ == '__main__':
Expand Down

0 comments on commit 50a6180

Please sign in to comment.