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

**URL:** <https://discuss.openedx.org/t/how-to-retrieve-the-full-lms-url-including-port-in-a-tutor-plugin-environment/9132>\
**Category:** Development\
**Tags:** tutor, tutor-plugin\
**Created:** [January 16, 2023, 9:34am UTC](https://discuss.openedx.org/t/how-to-retrieve-the-full-lms-url-including-port-in-a-tutor-plugin-environment/9132 "2023-01-16T09:34:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jill](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/jill/32/3188_2.png) [@jill](https://discuss.openedx.org/u/jill)\
**Post date:** [January 16, 2023, 9:34am UTC](https://discuss.openedx.org/t/how-to-retrieve-the-full-lms-url-including-port-in-a-tutor-plugin-environment/9132/1 "2023-01-16T09:34:24Z")

</div>

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](https://github.com/open-craft/tutor-contrib-superset/pull/1), 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.

- [http://local.overhang.io:8000](http://local.overhang.io:8000) in `tutor dev`, or
- [http://local.overhang.io](http://local.overhang.io) in `tutor local`.

The variable I’m trying to set is here: [`SUPERSET_OAUTH2_BASE_URL`](https://github.com/open-craft/tutor-contrib-superset/pull/1/files#diff-34becf7bb60402c8556a9bc64d435f02a3c47ba1eb7c52606239bcc021c5dae6R28)

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?

---

<div class="post-metadata">

**Author:** ![regis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/regis/32/2640_2.png) [@regis](https://discuss.openedx.org/u/regis)\
**Post date:** [January 16, 2023, 10:48am UTC](https://discuss.openedx.org/t/how-to-retrieve-the-full-lms-url-including-port-in-a-tutor-plugin-environment/9132/2 "2023-01-16T10:48:59Z")

</div>

> [@jill](#):
>
> 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.

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.

> [@jill](#):
>
> 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?

Pretty close 🙂 It’s actually “[local-docker-compose-dev-services](https://docs.tutor.overhang.io/reference/patches.html#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:

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

```

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

```auto
environment:
    - LMS_FULL_URL = "http://{{ LMS_HOST }}:8000"

```

---

<div class="post-metadata">

**Author:** ![jill](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/jill/32/3188_2.png) [@jill](https://discuss.openedx.org/u/jill)\
**Post date:** [January 17, 2023, 10:59am UTC](https://discuss.openedx.org/t/how-to-retrieve-the-full-lms-url-including-port-in-a-tutor-plugin-environment/9132/3 "2023-01-17T10:59:24Z")

</div>

> [@regis](#):
>
> Pretty close 🙂 It’s actually “[local-docker-compose-dev-services](https://docs.tutor.overhang.io/reference/patches.html#local-docker-compose-dev-services)”.

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](https://github.com/open-craft/tutor-contrib-superset/pull/1/files#diff-34becf7bb60402c8556a9bc64d435f02a3c47ba1eb7c52606239bcc021c5dae6R184-R203)!

Thank you!
