Coverage for webapp / config.py: 93%

29 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2025-12-29 22:06 +0000

1import os 

2from canonicalwebteam.flask_base.env import load_plain_env_variables 

3 

4 

5class ConfigurationError(Exception): 

6 pass 

7 

8 

9# Load the prefixed FLASK_* env vars into env vars without the prefix. We have 

10# to do this explicitly here because otherwise the config module is imported 

11# by other files before the FlaskBase app gets initialized and does this by 

12# itself, meaning that the variables below are not set correctly 

13load_plain_env_variables() 

14 

15SECRET_KEY = os.getenv("SECRET_KEY") 

16LOGIN_URL = os.getenv("LOGIN_URL", "https://login.ubuntu.com") 

17BSI_URL = os.getenv("BSI_URL", "https://build.snapcraft.io") 

18ENVIRONMENT = os.getenv("ENVIRONMENT", "devel") 

19IS_DEVELOPMENT = ENVIRONMENT == "devel" 

20COMMIT_ID = os.getenv("COMMIT_ID", "commit_id") 

21SENTRY_DSN = os.getenv("SENTRY_DSN", "").strip() 

22SENTRY_CONFIG = {"release": COMMIT_ID, "environment": ENVIRONMENT} 

23DNS_VERIFICATION_SALT = os.getenv("DNS_VERIFICATION_SALT") 

24 

25# Vite integration config values 

26VITE_MODE = "development" if IS_DEVELOPMENT else "production" 

27VITE_PORT = os.getenv("VITE_PORT", 5173) 

28VITE_OUTDIR = os.getenv("VITE_OUTDIR", "static/js/dist/vite") 

29# VITE_REACT controls whether React hot module reload scripts are injected when 

30# running in dev mode; the setting has no effect in prod mode 

31VITE_REACT = True 

32 

33if ENVIRONMENT != "devel": 

34 SESSION_COOKIE_SAMESITE = "None" 

35 SESSION_COOKIE_SECURE = True 

36 

37WEBAPP_CONFIG = {"LAYOUT": "_layout.html", "STORE_NAME": "Snap store"} 

38 

39WEBAPP_EXTRA_HEADERS = {} 

40 

41# Ten years default cache time on static files 

42SEND_FILE_MAX_AGE_DEFAULT = 10 * 365 * 24 * 60 * 60 

43 

44CONTENT_DIRECTORY = {"PUBLISHER_PAGES": "store/content/publishers/"} 

45 

46# Docs search 

47SEARCH_API_KEY = os.getenv("SEARCH_API_KEY") 

48SEARCH_API_URL = "https://www.googleapis.com/customsearch/v1" 

49SEARCH_CUSTOM_ID = "009048213575199080868:i3zoqdwqk8o" 

50 

51APP_NAME = "snapcraft"