How to retrieve the full LMS URL (including port) in a tutor plugin environment?

Hello!

I’m working on my first Tutor plugin, feat: adds superset docker services and open edx integrations by pomegranited · Pull Request #1 · open-craft/tutor-contrib-superset · GitHub, which sets up Apache Superset and allows users to use Open edX SSO to authenticate to the app.

To set up SSO, I need to know the full root LMS URL: e.g.

The variable I’m trying to set is here: SUPERSET_OAUTH2_BASE_URL

I can get the base domain configured from LMS_HOST, and I can figure out whether it’s http or https from ENABLE_HTTPS. But I can’t seem to find the variable that tells me whether there’s a port that needs to be added to the hostname.

I’ve tried several things, but nothing has worked with the plugin.py script so far.

  • The variable JWT_COMMON_ISSUER is available when my plugin.py is running, but it only contains the correct value when running tutor local; it doesn’t get the :8000 port appended for tutor dev.
  • Variables like LMS_ROOT_URL or COMPOSE_PROJECT_NAME are not available when my plugin.py is running.
  • I’m adding patches to ENV_PATCHES["local-docker-compose-services"], so I thought maybe there was an ENV_PATCHES["dev-docker-compose-services"] equivalent for dev – doesn’t seem to be?
  • I looked at other plugins like tutor-discovery and tutor-ecommerce, and they hardcode the LMS provider URL in their django dev/prod settings file templates. I can’t really do that with my plugin, because Superset doesn’t have a notion of running in dev vs prod environments.

How do other people solve this issue?

Yes, this is exactly how other plugins handle the situation. The :8000 part is just hard-coded in dev settings.

I understand that you cannot do this here in your plugin. So instead I would suggest that you pass the full LMS url to your superset container via an environment variable. This variable will be different in production and development.

Pretty close :slight_smile: It’s actually “local-docker-compose-dev-services”. I can understand why this would not be a very intuitive name…

To sum it up, you need to add this value to the “local-docker-compose-services” production patch:

environment:
    - LMS_FULL_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}"

And this one to the “local-docker-compose-dev-services” patch:

environment:
    - LMS_FULL_URL = "http://{{ LMS_HOST }}:8000"
2 Likes

Ah perfect @regis ! That was the piece of information I needed.
I still had to wrestle with some escaping because I was doing (probably too) fancy things with the docker-compose config, but it’s working now!

Thank you!

1 Like