Coverage for webapp/config.py: 94%

34 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-20 22:09 +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") 

18# Max pages of Launchpad completed builds to scan when resolving snap 

19# provenance (page size is 75). 

20LP_MAX_BUILD_PAGES = int(os.getenv("LP_MAX_BUILD_PAGES", "5")) 

21# Max Launchpad recipes to scan per store name: one name can match dozens 

22# (firefox has 62), so the right one is rarely the first. 

23LP_MAX_RECIPES = int(os.getenv("LP_MAX_RECIPES", "5")) 

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

25IS_DEVELOPMENT = ENVIRONMENT == "devel" 

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

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

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

29DNS_VERIFICATION_SALT = os.getenv("DNS_VERIFICATION_SALT") 

30 

31# Vite integration config values 

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

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

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

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

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

37VITE_REACT = True 

38 

39if ENVIRONMENT != "devel": 

40 SESSION_COOKIE_SAMESITE = "None" 

41 SESSION_COOKIE_SECURE = True 

42 

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

44 

45WEBAPP_EXTRA_HEADERS = {} 

46 

47# Ten years default cache time on static files 

48SEND_FILE_MAX_AGE_DEFAULT = 10 * 365 * 24 * 60 * 60 

49 

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

51 

52APP_NAME = "snapcraft" 

53 

54# Fallback icon shown when a snap has no icon of its own 

55DEFAULT_ICON_URL = ( 

56 "https://assets.ubuntu.com/v1/be6eb412-snapcraft-missing-icon.svg" 

57) 

58 

59STATUS_BANNER = os.getenv("STATUS_BANNER", "").strip() 

60 

61REPORT_SHEET_URL = os.getenv("REPORT_SHEET_URL", "").strip() 

62TURNSTILE_SITE_KEY = os.getenv("TURNSTILE_SITE_KEY", "").strip() 

63TURNSTILE_SECRET_KEY = os.getenv("TURNSTILE_SECRET_KEY", "").strip() 

64TURNSTILE_VERIFY_URL = os.getenv( 

65 "TURNSTILE_VERIFY_URL", 

66 "https://challenges.cloudflare.com/turnstile/v0/siteverify", 

67).strip()