|
|
|
@ -2,7 +2,7 @@ import binascii
|
|
|
|
|
import json |
|
|
|
|
|
|
|
|
|
import requests |
|
|
|
|
from decouple import config, Csv |
|
|
|
|
from decouple import config, Csv, UndefinedValueError |
|
|
|
|
from datetime import datetime |
|
|
|
|
from flask import Flask, request |
|
|
|
|
from flask_restful import Resource, Api |
|
|
|
@ -16,13 +16,26 @@ import time
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
api = Api(app) |
|
|
|
|
|
|
|
|
|
# load configs |
|
|
|
|
AUTH_NAME = config("AUTH_NAME", "") |
|
|
|
|
AUTH_TOKEN = TOTP(config("AUTH_SEED", "")).now() |
|
|
|
|
AUTH_REALM = config("AUTH_REALM", "") |
|
|
|
|
OTP_SERVER = config("OTP_SERVER", "") |
|
|
|
|
OTP_VERIFY_ENDPOINT = config("OTP_VERIFY_ENDPOINT", "verify/") |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
INIT_ORDER_ID = config("INIT_ORDER_ID") |
|
|
|
|
REALM_ALLOWED = config("REALM_ALLOWED", cast=Csv(str)) |
|
|
|
|
except UndefinedValueError as uve: |
|
|
|
|
print(str(uve)) |
|
|
|
|
exit(1) |
|
|
|
|
|
|
|
|
|
def check_otp(name, realm, token): |
|
|
|
|
try: |
|
|
|
|
data = { |
|
|
|
|
"auth_name": config("AUTH_NAME", ""), |
|
|
|
|
"auth_token": TOTP(config("AUTH_SEED", "")).now(), |
|
|
|
|
"auth_realm": config("AUTH_REALM", ""), |
|
|
|
|
"auth_name": AUTH_NAME, |
|
|
|
|
"auth_token": AUTH_TOKEN, |
|
|
|
|
"auth_realm": AUTH_REALM, |
|
|
|
|
"name": name, |
|
|
|
|
"realm": realm, |
|
|
|
|
"token": token, |
|
|
|
@ -32,8 +45,8 @@ def check_otp(name, realm, token):
|
|
|
|
|
|
|
|
|
|
response = requests.post( |
|
|
|
|
"{OTP_SERVER}{OTP_VERIFY_ENDPOINT}".format( |
|
|
|
|
OTP_SERVER=config("OTP_SERVER", ""), |
|
|
|
|
OTP_VERIFY_ENDPOINT=config("OTP_VERIFY_ENDPOINT", "verify/"), |
|
|
|
|
OTP_SERVER=OTP_SERVER, |
|
|
|
|
OTP_VERIFY_ENDPOINT=OTP_VERIFY_ENDPOINT, |
|
|
|
|
), |
|
|
|
|
data=data, |
|
|
|
|
) |
|
|
|
@ -50,7 +63,7 @@ def get_order_id():
|
|
|
|
|
if order_id_kv is not None: |
|
|
|
|
order_id = int(order_id_kv.value) + 1 |
|
|
|
|
else: |
|
|
|
|
order_id = config("INIT_ORDER_ID") |
|
|
|
|
order_id = INIT_ORDER_ID |
|
|
|
|
client.put("/v1/last_order_id", str(order_id)) |
|
|
|
|
return "OR-{}".format(order_id) |
|
|
|
|
|
|
|
|
@ -97,7 +110,6 @@ class AddProduct(Resource):
|
|
|
|
|
def post(): |
|
|
|
|
data = request.json |
|
|
|
|
logging.debug("Got data: {}".format(str(data))) |
|
|
|
|
REALM_ALLOWED = config("REALM_ALLOWED", cast=Csv(str)) |
|
|
|
|
logging.debug("REALM_ALLOWED = {}".format(REALM_ALLOWED)) |
|
|
|
|
if data["realm"] not in REALM_ALLOWED: |
|
|
|
|
logging.error( |
|
|
|
|