reuse of the env variable in the base settings
This commit is contained in:
parent
5e2e906f48
commit
69ec7d2b46
3 changed files with 17 additions and 23 deletions
|
@ -1,9 +1,8 @@
|
|||
import logging
|
||||
import os
|
||||
import pyotp
|
||||
import requests
|
||||
import dotenv
|
||||
from django.contrib.sites.models import Site
|
||||
from django.conf import settings
|
||||
|
||||
from datacenterlight.tasks import create_vm_task
|
||||
from hosting.models import HostingOrder, HostingBill, OrderDetail
|
||||
|
@ -15,18 +14,6 @@ from .models import VMPricing, VMTemplate
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PROJECT_DIR = os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__)),
|
||||
)
|
||||
|
||||
# load .env file
|
||||
dotenv.read_dotenv("{0}/.env".format(PROJECT_DIR))
|
||||
|
||||
|
||||
def env(env_name):
|
||||
return os.environ.get(env_name)
|
||||
|
||||
|
||||
def get_cms_integration(name):
|
||||
current_site = Site.objects.get_current()
|
||||
try:
|
||||
|
@ -119,17 +106,17 @@ def clear_all_session_vars(request):
|
|||
|
||||
def check_otp(name, realm, token):
|
||||
data = {
|
||||
"auth_name": env('AUTH_NAME'),
|
||||
"auth_token": pyotp.TOTP(env('AUTH_SEED')).now(),
|
||||
"auth_realm": env('AUTH_REALM'),
|
||||
"auth_name": settings.AUTH_NAME,
|
||||
"auth_token": pyotp.TOTP(settings.AUTH_SEED).now(),
|
||||
"auth_realm": settings.AUTH_REALM,
|
||||
"name": name,
|
||||
"realm": realm,
|
||||
"token": token
|
||||
}
|
||||
response = requests.post(
|
||||
"https://{OTP_SERVER}{OTP_VERIFY_ENDPOINT}".format(
|
||||
OTP_SERVER=env('OTP_SERVER'),
|
||||
OTP_VERIFY_ENDPOINT=env('OTP_VERIFY_ENDPOINT')
|
||||
OTP_SERVER=settings.OTP_SERVER,
|
||||
OTP_VERIFY_ENDPOINT=settings.OTP_VERIFY_ENDPOINT
|
||||
),
|
||||
data=data
|
||||
)
|
||||
|
|
|
@ -721,6 +721,14 @@ X_FRAME_OPTIONS = ('SAMEORIGIN' if X_FRAME_OPTIONS_ALLOW_FROM_URI is None else
|
|||
|
||||
DEBUG = bool_env('DEBUG')
|
||||
|
||||
ACCOUNT_NAME = env('ACCOUNT_NAME')
|
||||
AUTH_NAME = env('AUTH_NAME')
|
||||
AUTH_SEED = env('AUTH_SEED')
|
||||
AUTH_REALM = env('AUTH_REALM')
|
||||
OTP_SERVER = env('OTP_SERVER')
|
||||
OTP_VERIFY_ENDPOINT = env('OTP_VERIFY_ENDPOINT')
|
||||
|
||||
|
||||
if DEBUG:
|
||||
from .local import * # flake8: noqa
|
||||
else:
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import logging
|
||||
import uuid
|
||||
import os
|
||||
import dotenv
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
|
||||
|
@ -39,7 +37,7 @@ from stored_messages.settings import stored_messages_settings
|
|||
|
||||
from datacenterlight.cms_models import DCLCalculatorPluginModel
|
||||
from datacenterlight.models import VMTemplate, VMPricing
|
||||
from datacenterlight.utils import create_vm, get_cms_integration, check_otp, env
|
||||
from datacenterlight.utils import create_vm, get_cms_integration, check_otp
|
||||
from hosting.models import UserCardDetail
|
||||
from membership.models import CustomUser, StripeCustomer
|
||||
from opennebula_api.models import OpenNebulaManager
|
||||
|
@ -1775,7 +1773,8 @@ class CheckUserVM(APIView):
|
|||
user = request.data['user']
|
||||
realm = request.data['realm']
|
||||
token = request.data['token']
|
||||
if user != env('ACCOUNT_NAME'):
|
||||
print(settings.ACCOUNT_NAME)
|
||||
if user != settings.ACCOUNT_NAME:
|
||||
return Response("User not allowed", 403)
|
||||
response = check_otp(user, realm, token)
|
||||
if response != 200:
|
||||
|
|
Loading…
Reference in a new issue