use etcd3 instead of python-etcd. use uuid instead of increasing number.

This commit is contained in:
ahmadbilalkhalid 2019-06-24 22:14:45 +05:00
commit 7781a1b68b
3 changed files with 10 additions and 34 deletions

View file

@ -3,7 +3,6 @@ import requests
from decouple import config
from pyotp import TOTP
from etcd import EtcdKeyNotFound
def check_otp(name, realm, seed):
@ -27,23 +26,3 @@ def check_otp(name, realm, seed):
data=data
)
return response.status_code
def get_next_id(client, path):
try:
r = client.read(path)
except EtcdKeyNotFound:
return 0
max_key_result = max(r.children, key=lambda x: int(strip_nondigit(x.key)))
if max_key_result is None:
# No key found
return 0
max_key = strip_nondigit(max_key_result.key.split("/")[-1]) # Get the last portion of key
return int(max_key) + 1
def strip_nondigit(s):
return "".join([char for char in s if char.isdigit()])