2022-05-13 20:13:58 -05:00

129 lines
4.9 KiB
Python

from glob import glob
import os
import pkg_resources
from tutor import hooks as tutor_hooks
from .__about__ import __version__
################# Configuration
config = {
# Add here your new settings
"defaults": {
"VERSION": __version__,
"SECRET_KEY": "CHANGE-ME",
"DOCKER_IMAGE": "{{ DOCKER_REGISTRY }}lpm0073/openedx-credentials:{{ CREDENTIALS_VERSION }}",
"EXTRA_PIP_REQUIREMENTS": [],
"HOST": "credentials.{{ LMS_HOST }}",
"MYSQL_DATABASE": "credentials",
"MYSQL_USERNAME": "credentials",
"MYSQL_PASSWORD": "{{ 8|random_string }}",
"LOGO_TRADEMARK_URL": "https://edx-cdn.org/v3/default/logo-trademark.svg",
"LOGO_TRADEMARK_URL_PNG": "https://edx-cdn.org/v3/default/logo-trademark.png",
"LOGO_TRADEMARK_URL_SVG": "https://edx-cdn.org/v3/default/logo-trademark.svg",
"LOGO_URL": "https://edx-cdn.org/v3/default/logo.svg",
"LOGO_URL_PNG": "https://edx-cdn.org/v3/default/logo.png",
"LOGO_URL_SVG": "https://edx-cdn.org/v3/default/logo.svg",
"LOGO_WHITE_URL": "https://edx-cdn.org/v3/default/logo-white.svg",
"LOGO_WHITE_URL_PNG": "https://edx-cdn.org/v3/default/logo-white.png",
"LOGO_WHITE_URL_SVG": "https://edx-cdn.org/v3/default/logo-white.svg",
"FAVICON_URL": "https://edx-cdn.org/v3/default/favicon.ico",
"OAUTH2_KEY": "credentials-backend-service-key",
"OAUTH2_SECRET": "CHANGE-ME",
"SOCIAL_AUTH_REDIRECT_IS_HTTPS": False,
"SOCIAL_AUTH_EDX_OAUTH2_ISSUER": "https://{{ LMS_HOST }}",
"SOCIAL_AUTH_EDX_OAUTH2_URL_ROOT": "http://lms:8000",
"SOCIAL_AUTH_EDX_OAUTH2_KEY": "credentials-sso-key",
"SOCIAL_AUTH_EDX_OAUTH2_SECRET": "credentials-sso-secret",
"SOCIAL_AUTH_EDX_OAUTH2_LOGOUT_URL": "{{ LMS_HOST }}/logout",
"BACKEND_SERVICE_EDX_OAUTH2_KEY": "{{ CREDENTIALS_OAUTH2_KEY }}",
"BACKEND_SERVICE_EDX_OAUTH2_SECRET": "{{ CREDENTIALS_OAUTH2_SECRET }}",
"BACKEND_SERVICE_EDX_OAUTH2_PROVIDER_URL": "http://lms:8000/oauth2"
},
# Add here settings that don't have a reasonable default for all users. For
# instance: passwords, secret keys, etc.
"unique": {
# "SECRET_KEY": "\{\{ 24|random_string \}\}",
},
# Danger zone! Add here values to override settings from Tutor core or other plugins.
"overrides": {
# "PLATFORM_NAME": "My platform",
},
}
################# Initialization tasks
tutor_hooks.Filters.COMMANDS_INIT.add_item(
(
"lms",
("credentials", "tasks", "lms", "init"),
)
)
tutor_hooks.Filters.IMAGES_BUILD.add_item(
(
"credentials",
("plugins", "credentials", "build", "credentials"),
"{{ CREDENTIALS_DOCKER_IMAGE }}",
(),
)
)
@tutor_hooks.Filters.IMAGES_PULL.add()
@tutor_hooks.Filters.IMAGES_PUSH.add()
def _add_remote_credentials_image_iff_customized(images, user_config):
"""
Register CREDENTIALS image for pushing & pulling if and only if it has
been set to something other than the default.
This is work-around to an upstream issue with CREDENTIALS config. Briefly:
User config is baked into CREDENTIALS builds, so Tutor cannot host a generic
pre-built CREDENTIALS image. Howevever, individual Tutor users may want/need to
build and host their own CREDENTIALS image. So, as a compromise, we tell Tutor
to push/pull the CREDENTIALS image if the user has customized it to anything
other than the default image URL.
"""
image_tag = user_config["CREDENTIALS_DOCKER_IMAGE"]
if not image_tag.startswith("docker.io/lpm0073/openedx-credentials:"):
# Image has been customized. Add to list for pulling/pushing.
images.append(("credentials", image_tag))
return images
################# You don't really have to bother about what's below this line,
################# except maybe for educational purposes :)
# Plugin templates
tutor_hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutorcredentials", "templates")
)
tutor_hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
[
("credentials/build", "plugins"),
("credentials/apps", "plugins"),
],
)
# Load all patches from the "patches" folder
for path in glob(
os.path.join(
pkg_resources.resource_filename("tutorcredentials", "patches"),
"*",
)
):
with open(path, encoding="utf-8") as patch_file:
tutor_hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))
# Load all configuration entries
tutor_hooks.Filters.CONFIG_DEFAULTS.add_items(
[
(f"CREDENTIALS_{key}", value)
for key, value in config["defaults"].items()
]
)
tutor_hooks.Filters.CONFIG_UNIQUE.add_items(
[
(f"CREDENTIALS_{key}", value)
for key, value in config["unique"].items()
]
)
tutor_hooks.Filters.CONFIG_OVERRIDES.add_items(list(config["overrides"].items()))