Skip to content

Commit

Permalink
refactor: hard-code https, add common patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lpm0073 committed Jan 4, 2024
1 parent 40df3ca commit f0732cd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 134 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def load_about():
packages=find_namespace_packages(exclude=["tests*"]),
include_package_data=True,
python_requires=">=3.8",
install_requires=["tutor>=17.0.0"],
install_requires=["tutor>=16.0.0,<17.0.0"],
entry_points={"tutor.plugin.v1": ["k8s_deploy_tasks = tutork8s_deploy_tasks.plugin"]},
classifiers=[
"Development Status :: 3 - Alpha",
Expand Down
2 changes: 1 addition & 1 deletion tutork8s_deploy_tasks/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "17.0.1"
__version__ = "16.0.2"
94 changes: 4 additions & 90 deletions tutork8s_deploy_tasks/patches/openedx-cms-production-settings
Original file line number Diff line number Diff line change
Expand Up @@ -4,100 +4,14 @@
#
# date: jan-2023
#
# copied from: https://github.com/overhangio/tutor-mfe/blob/master/tutormfe/patches/openedx-lms-production-settings
# copied from: https://github.com/overhangio/tutor-mfe/blob/master/tutormfe/patches/openedx-cms-production-settings
#------------------------------------------------------------------------------
# Dynamic config API settings
# https://openedx.github.io/frontend-platform/module-Config.html
MFE_CONFIG = {
"BASE_URL": "{{ MFE_HOST }}",
"CSRF_TOKEN_API_PATH": "/csrf/api/v1/token",
"CREDENTIALS_BASE_URL": "",
"DISCOVERY_API_BASE_URL": "{% if DISCOVERY_HOST is defined %}{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ DISCOVERY_HOST }}{% endif %}",
"FAVICON_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/favicon.ico",
"INFO_EMAIL": "{{ CONTACT_EMAIL }}",
"LANGUAGE_PREFERENCE_COOKIE_NAME": "openedx-language-preference",
"LMS_BASE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}",
"LOGIN_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login",
"LOGO_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_WHITE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_TRADEMARK_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGOUT_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/logout",
"MARKETING_SITE_BASE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}",
"PASSWORD_RESET_SUPPORT_LINK": "mailto:{{ CONTACT_EMAIL }}",
"REFRESH_ACCESS_TOKEN_ENDPOINT": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login_refresh",
"SITE_NAME": "{{ PLATFORM_NAME }}",
"STUDIO_BASE_URL": "{{ "https" if ENABLE_HTTPS else "http" }}://{{ CMS_HOST }}",
"USER_INFO_COOKIE_NAME": "user-info",
"ACCESS_TOKEN_COOKIE_NAME": "edx-jwt-cookie-header-payload",
}

# MFE-specific settings

{% if get_mfe("authn") %}
AUTHN_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/authn"
AUTHN_MICROFRONTEND_DOMAIN = "{{ MFE_HOST }}/authn"
MFE_CONFIG["DISABLE_ENTERPRISE_LOGIN"] = True
{% endif %}

{% if get_mfe("account") %}
ACCOUNT_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/account/"
MFE_CONFIG["ACCOUNT_SETTINGS_URL"] = ACCOUNT_MICROFRONTEND_URL
{% endif %}

{% if get_mfe("course-authoring") %}
MFE_CONFIG["ENABLE_NEW_EDITOR_PAGES"] = True
MFE_CONFIG["ENABLE_PROGRESS_GRAPH_SETTINGS"] = True
{% endif %}

{% if get_mfe("discussions") %}
DISCUSSIONS_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/discussions"
MFE_CONFIG["DISCUSSIONS_MFE_BASE_URL"] = DISCUSSIONS_MICROFRONTEND_URL
DISCUSSIONS_MFE_FEEDBACK_URL = None
{% endif %}

{% if get_mfe("gradebook") %}
WRITABLE_GRADEBOOK_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/gradebook"
{% endif %}

{% if get_mfe("learner-dashboard") %}
LEARNER_HOME_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/learner-dashboard/"
{% endif %}

{% if get_mfe("learning") %}
LEARNING_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/learning"
MFE_CONFIG["LEARNING_BASE_URL"] = "{{ "https" if ENABLE_HTTPS else "http" }}://{{ MFE_HOST }}/learning"
{% endif %}

{% if get_mfe("ora-grading") %}
ORA_GRADING_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/ora-grading"
{% endif %}

{% if get_mfe("profile") %}
PROFILE_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/profile/u/"
MFE_CONFIG["ACCOUNT_PROFILE_URL"] = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/profile"
{% endif %}

{% if get_mfe("communications") %}
COMMUNICATIONS_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/communications"
MFE_CONFIG["SCHEDULE_EMAIL_SECTION"] = True
COURSE_AUTHORING_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/course-authoring"
{% endif %}

LOGIN_REDIRECT_WHITELIST.append("{{ MFE_HOST }}")
CORS_ORIGIN_WHITELIST.append("{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}")
CSRF_TRUSTED_ORIGINS.append("{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}")

# add missing CORS_ORIGIN_WHITELIST hosts
CORS_ORIGIN_WHITELIST.append("https://{{ LMS_HOST }}")
CORS_ORIGIN_WHITELIST.append("https://{{ CMS_HOST }}")
{% if DISCOVERY_HOST is defined %}
CORS_ORIGIN_WHITELIST.append("https://{{ DISCOVERY_HOST }}")
{% endif %}
{% if ECOMMERCE_HOST is defined %}
CORS_ORIGIN_WHITELIST.append("https://{{ ECOMMERCE_HOST }}")
{% endif %}
{% if CREDENTIALS_HOST is defined %}
CORS_ORIGIN_WHITELIST.append("https://{{ CREDENTIALS_HOST }}")
{% endif %}

{{ patch("mfe-lms-common-settings") }}
{{ patch("mfe-lms-production-settings") }}
CORS_ORIGIN_WHITELIST.append("https://{{ MFE_HOST }}")
CSRF_TRUSTED_ORIGINS.append("{{ MFE_HOST }}")
18 changes: 17 additions & 1 deletion tutork8s_deploy_tasks/patches/openedx-common-settings
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@
# usage: eduNEXT's scorm proxy solution for resolving storage challenges
# when running behind a proxy server
#------------------------------------------------------------------------------
# SCORM SETTINGS

# copied from: https://github.com/overhangio/tutor-mfe/blob/master/tutormfe/patches/openedx-common-settings
#
# MFE: enable API and set a low cache timeout for the settings. otherwise, weird
# configuration bugs occur. Also, the view is not costly at all, and it's also cached on
# the frontend. (5 minutes, hardcoded)
ENABLE_MFE_CONFIG_API = True
MFE_CONFIG_API_CACHE_TIMEOUT = 1

# MFE-specific settings
{% if get_mfe("authn") %}
FEATURES['ENABLE_AUTHN_MICROFRONTEND'] = True
{% endif %}
{% if get_mfe("communications") %}
FEATURES['ENABLE_NEW_BULK_EMAIL_EXPERIENCE'] = True
{% endif %}

# SCORM SETTINGS
def scorm_xblock_storage(xblock):
from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
Expand Down
64 changes: 23 additions & 41 deletions tutork8s_deploy_tasks/patches/openedx-lms-production-settings
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ MFE_CONFIG = {
"BASE_URL": "{{ MFE_HOST }}",
"CSRF_TOKEN_API_PATH": "/csrf/api/v1/token",
"CREDENTIALS_BASE_URL": "",
"DISCOVERY_API_BASE_URL": "{% if DISCOVERY_HOST is defined %}{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ DISCOVERY_HOST }}{% endif %}",
"FAVICON_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/favicon.ico",
"DISCOVERY_API_BASE_URL": "{% if DISCOVERY_HOST is defined %}https://{{ DISCOVERY_HOST }}{% endif %}",
"FAVICON_URL": "https://{{ LMS_HOST }}/favicon.ico",
"INFO_EMAIL": "{{ CONTACT_EMAIL }}",
"LANGUAGE_PREFERENCE_COOKIE_NAME": "openedx-language-preference",
"LMS_BASE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}",
"LOGIN_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login",
"LOGO_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_WHITE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_TRADEMARK_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGOUT_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/logout",
"MARKETING_SITE_BASE_URL": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}",
"LMS_BASE_URL": "https://{{ LMS_HOST }}",
"LOGIN_URL": "https://{{ LMS_HOST }}/login",
"LOGO_URL": "https://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_WHITE_URL": "https://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGO_TRADEMARK_URL": "https://{{ LMS_HOST }}/theming/asset/images/logo.png",
"LOGOUT_URL": "https://{{ LMS_HOST }}/logout",
"MARKETING_SITE_BASE_URL": "https://{{ LMS_HOST }}",
"PASSWORD_RESET_SUPPORT_LINK": "mailto:{{ CONTACT_EMAIL }}",
"REFRESH_ACCESS_TOKEN_ENDPOINT": "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}/login_refresh",
"REFRESH_ACCESS_TOKEN_ENDPOINT": "https://{{ LMS_HOST }}/login_refresh",
"SITE_NAME": "{{ PLATFORM_NAME }}",
"STUDIO_BASE_URL": "{{ "https" if ENABLE_HTTPS else "http" }}://{{ CMS_HOST }}",
"STUDIO_BASE_URL": "https://{{ CMS_HOST }}",
"USER_INFO_COOKIE_NAME": "user-info",
"ACCESS_TOKEN_COOKIE_NAME": "edx-jwt-cookie-header-payload",
}

# MFE-specific settings

{% if get_mfe("authn") %}
AUTHN_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/authn"
AUTHN_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/authn"
AUTHN_MICROFRONTEND_DOMAIN = "{{ MFE_HOST }}/authn"
MFE_CONFIG["DISABLE_ENTERPRISE_LOGIN"] = True
{% endif %}

{% if get_mfe("account") %}
ACCOUNT_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/account/"
ACCOUNT_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/account"
MFE_CONFIG["ACCOUNT_SETTINGS_URL"] = ACCOUNT_MICROFRONTEND_URL
{% endif %}

Expand All @@ -50,54 +50,36 @@ MFE_CONFIG["ENABLE_PROGRESS_GRAPH_SETTINGS"] = True
{% endif %}

{% if get_mfe("discussions") %}
DISCUSSIONS_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/discussions"
MFE_CONFIG["DISCUSSIONS_MFE_BASE_URL"] = DISCUSSIONS_MICROFRONTEND_URL
DISCUSSIONS_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/discussions"
DISCUSSIONS_MFE_FEEDBACK_URL = None
{% endif %}

{% if get_mfe("gradebook") %}
WRITABLE_GRADEBOOK_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/gradebook"
{% endif %}

{% if get_mfe("learner-dashboard") %}
LEARNER_HOME_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/learner-dashboard/"
WRITABLE_GRADEBOOK_URL = "https://{{ MFE_HOST }}/gradebook"
{% endif %}

{% if get_mfe("learning") %}
LEARNING_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/learning"
MFE_CONFIG["LEARNING_BASE_URL"] = "{{ "https" if ENABLE_HTTPS else "http" }}://{{ MFE_HOST }}/learning"
LEARNING_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/learning"
MFE_CONFIG["LEARNING_BASE_URL"] = "https://{{ MFE_HOST }}/learning"
{% endif %}

{% if get_mfe("ora-grading") %}
ORA_GRADING_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/ora-grading"
ORA_GRADING_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/ora-grading"
{% endif %}

{% if get_mfe("profile") %}
PROFILE_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/profile/u/"
MFE_CONFIG["ACCOUNT_PROFILE_URL"] = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/profile"
PROFILE_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/profile/u/"
MFE_CONFIG["ACCOUNT_PROFILE_URL"] = "https://{{ MFE_HOST }}/profile"
{% endif %}

{% if get_mfe("communications") %}
COMMUNICATIONS_MICROFRONTEND_URL = "{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}/communications"
COMMUNICATIONS_MICROFRONTEND_URL = "https://{{ MFE_HOST }}/communications"
MFE_CONFIG["SCHEDULE_EMAIL_SECTION"] = True
{% endif %}

LOGIN_REDIRECT_WHITELIST.append("{{ MFE_HOST }}")
CORS_ORIGIN_WHITELIST.append("{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}")
CSRF_TRUSTED_ORIGINS.append("{% if ENABLE_HTTPS %}https://{% else %}http://{% endif %}{{ MFE_HOST }}")

# add missing CORS_ORIGIN_WHITELIST hosts
CORS_ORIGIN_WHITELIST.append("https://{{ LMS_HOST }}")
CORS_ORIGIN_WHITELIST.append("https://{{ CMS_HOST }}")
{% if DISCOVERY_HOST is defined %}
CORS_ORIGIN_WHITELIST.append("https://{{ DISCOVERY_HOST }}")
{% endif %}
{% if ECOMMERCE_HOST is defined %}
CORS_ORIGIN_WHITELIST.append("https://{{ ECOMMERCE_HOST }}")
{% endif %}
{% if CREDENTIALS_HOST is defined %}
CORS_ORIGIN_WHITELIST.append("https://{{ CREDENTIALS_HOST }}")
{% endif %}
CORS_ORIGIN_WHITELIST.append("https://{{ MFE_HOST }}")
CSRF_TRUSTED_ORIGINS.append("{{ MFE_HOST }}")

{{ patch("mfe-lms-common-settings") }}
{{ patch("mfe-lms-production-settings") }}

0 comments on commit f0732cd

Please sign in to comment.