It's a duplicate of LICENSE env var **What this PR does**: Remove OSS_INSTALLATION env var in favour of LICENSE env var. Also, I refactored features tests a little. From my point of view it makes little sense to test if all features are disabled or enabled. Better to test specific use-case (e.g. oss installation). Also to test that all features are disabled it is needed to set LICENSE equals cloud license, which makes test confusing. **Checklist** - [x] Tests updated - [ ] Documentation added - [ ] `CHANGELOG.md` updated
37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
import logging
|
|
import sys
|
|
|
|
from django.apps import AppConfig, apps
|
|
from django.conf import settings
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
STARTUP_COMMANDS = ["runserver", "uwsgi"]
|
|
|
|
|
|
class GrafanaPluginConfig(AppConfig):
|
|
name = "apps.grafana_plugin"
|
|
|
|
def ready(self):
|
|
"""
|
|
For OSS installations, validate that GRAFANA_API_URL environment variable is specified, otherwise
|
|
abort app startup.
|
|
|
|
We only care to run this for OSS INSTALLATIONS. The STARTUP_COMMANDS check is to avoid running this check
|
|
for the django migrate command. For a fresh installation this would crash because user_management table would
|
|
[not exist](https://stackoverflow.com/a/63326719).
|
|
"""
|
|
# TODO: this logic should probably be moved out to a common utility
|
|
is_not_migration_script = any(startup_command in sys.argv for startup_command in STARTUP_COMMANDS)
|
|
if is_not_migration_script and settings.IS_OPEN_SOURCE:
|
|
Organization = apps.get_model("user_management", "Organization")
|
|
has_existing_org = Organization.objects.first() is not None
|
|
|
|
# only enforce the following for new setups - if no organization exists in the database
|
|
# and the GRAFANA_API_URL env var is not specified, exit the application
|
|
if has_existing_org is False and settings.SELF_HOSTED_SETTINGS["GRAFANA_API_URL"] is None:
|
|
logger.error(
|
|
f"For OSS installations, GRAFANA_API_URL is a required environment variable. Please set it and restart the application."
|
|
)
|
|
sys.exit()
|