Fixed: CORS Error by providing user server with necessary policies, also removed dead code
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
from dockerspawner import DockerSpawner
|
||||
from jupyterhub.utils import random_port
|
||||
from nativeauthenticator import NativeAuthenticator
|
||||
import subprocess
|
||||
|
||||
# from nbgrader.auth import JupyterHubAuthPlugin
|
||||
from traitlets import Unicode, Bool, Int, Float
|
||||
|
||||
import secrets
|
||||
import string
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@@ -40,21 +33,6 @@ def generate_api_token(
|
||||
return token
|
||||
|
||||
|
||||
def is_service_available_cmd(host, port):
|
||||
"""Check service using system commands"""
|
||||
try:
|
||||
subprocess.run(
|
||||
["nc", "-z", host, str(port)],
|
||||
check=True,
|
||||
timeout=3,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
return True
|
||||
except (subprocess.TimeoutExpired, subprocess.CalledProcessError):
|
||||
return False
|
||||
|
||||
|
||||
# Configuration file for JupyterHub
|
||||
c = get_config()
|
||||
|
||||
@@ -139,60 +117,18 @@ c.Spawner.ip = "0.0.0.0"
|
||||
c.DockerSpawner.mem_limit = os.environ.get("NOTEBOOK_MEMORY_LIMIT", "500M")
|
||||
c.DockerSpawner.cpu_limit = float(os.environ.get("NOTEBOOK_CPU_LIMIT", "1.0"))
|
||||
|
||||
|
||||
"""
|
||||
# Services configuration for NBGrader
|
||||
c.JupyterHub.services = [
|
||||
{
|
||||
'name': 'nbgrader-formgrader',
|
||||
'url': 'http://127.0.0.1:9999',
|
||||
'command': [
|
||||
'jupyter-nbgrader',
|
||||
'--port=9999',
|
||||
'--no-browser',
|
||||
'--log-level=INFO'
|
||||
],
|
||||
'cwd': '/srv/jupyterhub/courses',
|
||||
'user': 'root',
|
||||
'environment': {
|
||||
'PYTHONPATH': '/srv/nbgrader',
|
||||
'NBGRADER_CONFIG_FILE': '/srv/jupyterhub/nbgrader/nbgrader_config.py'
|
||||
}
|
||||
}
|
||||
# Fixing CORS because Nginx
|
||||
# this isn't a security risk because the container is served behind nginx
|
||||
# this only affects the traffic within the docker network itself
|
||||
c.Spawner.args = [
|
||||
"--ServerApp.allow_origin=*",
|
||||
"--ServerApp.allow_credentials=True",
|
||||
"--ServerApp.disable_check_xsrf=True",
|
||||
"--NotebookApp.allow_origin=*",
|
||||
"--NotebookApp.allow_credentials=True",
|
||||
"--NotebookApp.disable_check_xsrf=True",
|
||||
'--ServerApp.tornado_settings={"headers": {"Access-Control-Allow-Origin": "*"}}',
|
||||
]
|
||||
"""
|
||||
"""
|
||||
# NBGrader configuration
|
||||
c.JupyterHub.load_groups = {
|
||||
'nbgrader-instructors': ['instructor'],
|
||||
'nbgrader-students': []
|
||||
}
|
||||
"""
|
||||
"""
|
||||
# NBGrader Config
|
||||
c.JupyterHub.services = [
|
||||
{
|
||||
'name': 'nbgrader-formgrader',
|
||||
'url': 'http://127.0.0.1:9999',
|
||||
'api_token': generate_api_token(prefix='nbgrader'),
|
||||
'command': [
|
||||
'python', '-m', 'nbgrader', 'formgrader',
|
||||
#'--port=9999',
|
||||
#'--no-browser',
|
||||
'--log-level=INFO',
|
||||
#'--base_url=/jupyter/services/nbgrader-formgrader',
|
||||
'--debug'
|
||||
],
|
||||
'environment': {
|
||||
'JUPYTERHUB_SERVICE_URL': 'http://127.0.0.1:8081/jupyter/hub/api',
|
||||
'NBGRADER_CONFIG_FILE': '/srv/nbgrader/nbgrader_config.py',
|
||||
'PYTHONPATH': '/srv/nbgrader'
|
||||
},
|
||||
'cwd': '/srv/nbgrader/courses',
|
||||
'user': 'root'
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
# Security settings
|
||||
c.JupyterHub.cookie_secret_file = "/srv/jupyterhub/cookie_secret"
|
||||
|
Reference in New Issue
Block a user