Commit c298438b authored by CAMPION Sebastien's avatar CAMPION Sebastien

move config environment variable to django setting

parent 8a17e7bb
......@@ -17,11 +17,7 @@ from django.shortcuts import redirect
from django.shortcuts import render, get_object_or_404
from django.urls import reverse, reverse_lazy
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import (
ListView,
DetailView,
UpdateView,
)
from django.views.generic import ListView, DetailView, UpdateView
from .forms import UserForm, HomeSignupForm
from .models import User
......@@ -64,7 +60,7 @@ def check_token_and_jobid(func): # Check token decorator
@check_token_and_jobid
@csrf_exempt
def runner_dw(request, jobid, filename):
datastore = os.environ.get("ALLGO_DATASTORE")
datastore = getattr(settings, "ALLGO_DATASTORE")
filepath = os.path.join(datastore, jobid, filename)
assert ".." not in filepath, "filepath unsecure"
return FileResponse(open(filepath, 'rb'))
......@@ -73,7 +69,7 @@ def runner_dw(request, jobid, filename):
@check_token_and_jobid
@csrf_exempt
def runner_up(request, jobid, digest, nbofchunk, chunkid):
datastore = os.environ.get("ALLGO_DATASTORE")
datastore = getattr(settings, "ALLGO_DATASTORE")
outputdir = os.path.join(datastore, jobid, ".%s" % digest)
if not os.path.exists(outputdir):
os.mkdir(outputdir)
......@@ -161,7 +157,7 @@ def runner_jobs(runner):
job = Job.objects.filter(state=0, runner=runner.id).first()
if job:
log.debug("Send job %s to runner %s", job.id, runner.token)
datastore = os.environ.get("ALLGO_DATASTORE")
datastore = getattr(settings, "ALLGO_DATASTORE")
jdir = os.path.join(datastore, str(job.id))
files = {f: sha1file(os.path.join(jdir, f)) for f in os.listdir(jdir) if os.path.isfile(os.path.join(jdir, f))}
job.state = 1
......@@ -206,7 +202,10 @@ def notify_controler():
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((os.environ.get('ALLGO_CONTROLLER_HOST'), int(os.environ.get('ALLGO_CONTROLLER_PORT'))))
controller_host = getattr(settings, "ALLGO_CONTROLLER_HOST")
controller_port = getattr(settings, "ALLGO_CONTROLLER_PORT")
sock.connect((controller_host), int(controller_port))
sock.settimeout(None)
sock.makefile('rb', 0)
sock.shutdown(socket.SHUT_RDWR)
......@@ -250,7 +249,8 @@ def jupyter(request):
token.claim['upn'] = user
encoded_token = token.encode_token()
next = "/user/%s/git-pull?repo=%s" % (user, request.GET.get("repo"))
return redirect(os.environ.get('ALLGO_JUPYTER_URL') + "?bearer=" + encoded_token + "&next=" + next)
jupyter_url = getattr(settings, "ALLGO_JUPYTER_URL")
return redirect(jupyter_url + "?bearer=" + encoded_token + "&next=" + next)
def tokens(request):
......
......@@ -28,6 +28,10 @@ USE_TZ = True
ALLGO_DJANGO_REGISTRY = os.environ.get("ALLGO_DJANGO_REGISTRY")
ALLGO_DJANGO_MAXUPLOADSIZE = os.environ.get("ALLGO_DJANGO_MAXUPLOADSIZE")
ALLGO_DJANGO_REDIS_HOST = os.environ.get("ALLGO_DJANGO_REDIS_HOST")
ALLGO_DATASTORE = os.environ.get("ALLGO_DATASTORE")
ALLGO_CONTROLLER_HOST = os.environ.get("ALLGO_CONTROLLER_HOST")
ALLGO_CONTROLLER_PORT = os.environ.get("ALLGO_CONTROLLER_PORT")
# DATABASES
# ------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment