From 60e0dcf78acdbb969bd36b6ecc7a2737c42d0f12 Mon Sep 17 00:00:00 2001 From: Maxime Perrault Date: Wed, 11 Dec 2024 09:51:39 +0100 Subject: [PATCH] tech: add sentry auth token env variable --- .env.dev.defaults | 1 + .env.infra.example | 1 + .env.test.defaults | 3 +- docker-compose.yml | 1 + frontend/.env.frontend.example | 1 + frontend/src/env.d.ts | 1 + frontend/vite.config.ts | 62 +++++++++++++++++++--------------- 7 files changed, 41 insertions(+), 29 deletions(-) diff --git a/.env.dev.defaults b/.env.dev.defaults index 9f60d0866..325738818 100644 --- a/.env.dev.defaults +++ b/.env.dev.defaults @@ -88,6 +88,7 @@ FRONTEND_SHOM_KEY= FRONTEND_SENTRY_ENV=dev FRONTEND_SENTRY_DSN= FRONTEND_SENTRY_TRACING_ORIGIN=localhost +FRONTEND_SENTRY_AUTH_TOKEN=DUMMY_TOKEN ################################################################################ # Feature flags diff --git a/.env.infra.example b/.env.infra.example index 89148eab8..f63e5c2b2 100644 --- a/.env.infra.example +++ b/.env.infra.example @@ -87,6 +87,7 @@ FRONTEND_SHOM_KEY= FRONTEND_SENTRY_ENV= FRONTEND_SENTRY_DSN= FRONTEND_SENTRY_TRACING_ORIGIN= +FRONTEND_SENTRY_AUTH_TOKEN= ################################################################################ # Feature flags diff --git a/.env.test.defaults b/.env.test.defaults index f4391bb9c..c72c44756 100644 --- a/.env.test.defaults +++ b/.env.test.defaults @@ -81,6 +81,7 @@ FRONTEND_SHOM_KEY= FRONTEND_SENTRY_ENV=dev FRONTEND_SENTRY_DSN= FRONTEND_SENTRY_TRACING_ORIGIN=localhost +FRONTEND_SENTRY_AUTH_TOKEN=DUMMY_TOKEN ################################################################################ # Feature flags @@ -115,4 +116,4 @@ FRONTEND_OIDC_REDIRECT_URI=http://localhost:3000/login # MATOMO FRONTEND_MATOMO_URL= -FRONTEND_MATOMO_ID= \ No newline at end of file +FRONTEND_MATOMO_ID= diff --git a/docker-compose.yml b/docker-compose.yml index c043db6af..5971a0222 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: - FRONTEND_MONITORENV_VERSION=${MONITORENV_VERSION} - FRONTEND_SENTRY_DSN=${SENTRY_DSN} - FRONTEND_SENTRY_ENV=${ENVIRONMENT} + - FRONTEND_SENTRY_AUTH_TOKEN=${FRONTEND_SENTRY_AUTH_TOKEN} - FRONTEND_SENTRY_TRACING_ORIGIN=${FRONTEND_SENTRY_TRACING_ORIGIN} - FRONTEND_SHOM_KEY=${FRONTEND_SHOM_KEY} - FRONTEND_MISSION_FORM_AUTO_UPDATE=${FRONTEND_MISSION_FORM_AUTO_UPDATE} diff --git a/frontend/.env.frontend.example b/frontend/.env.frontend.example index d1907b358..d2193decf 100644 --- a/frontend/.env.frontend.example +++ b/frontend/.env.frontend.example @@ -27,6 +27,7 @@ FRONTEND_SHOM_KEY= FRONTEND_SENTRY_ENV= FRONTEND_SENTRY_DSN= FRONTEND_SENTRY_TRACING_ORIGIN= +FRONTEND_SENTRY_AUTH_TOKEN= ################################################################################ # Feature flags diff --git a/frontend/src/env.d.ts b/frontend/src/env.d.ts index 4dfa671e2..ecd5f3cb8 100644 --- a/frontend/src/env.d.ts +++ b/frontend/src/env.d.ts @@ -19,6 +19,7 @@ interface ImportMetaEnv { readonly FRONTEND_OIDC_REDIRECT_URI: string readonly FRONTEND_REPORTING_FORM_AUTO_SAVE_ENABLED: string readonly FRONTEND_REPORTING_FORM_AUTO_UPDATE: string + readonly FRONTEND_SENTRY_AUTH_TOKEN: string readonly FRONTEND_SENTRY_DSN: string readonly FRONTEND_SENTRY_ENV: string readonly FRONTEND_SENTRY_TRACING_ORIGIN: string diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 0a65a0f69..145721da6 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -2,41 +2,47 @@ import importMetaEnv from '@import-meta-env/unplugin' import { sentryVitePlugin } from '@sentry/vite-plugin' import react from '@vitejs/plugin-react' -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import svgr from 'vite-plugin-svgr' import viteTsconfigPaths from 'vite-tsconfig-paths' // https://vitejs.dev/config/ // eslint-disable-next-line import/no-default-export -export default defineConfig({ - build: { - outDir: './build', - sourcemap: true - }, +export default defineConfig(({ mode }) => { + // @see https://vite.dev/config/#using-environment-variables-in-config + const env = loadEnv(mode, process.cwd(), '') - plugins: [ - react(), - viteTsconfigPaths(), - svgr(), - importMetaEnv.vite({ - env: './.env', - example: './.env.frontend.example' - }), - sentryVitePlugin({ - org: 'betagouv', - project: 'monitorenv', - url: 'https://sentry.incubateur.net/' - }) - ], + return { + build: { + outDir: './build', + sourcemap: true + }, - server: { - port: 3000, - proxy: { - '/api': { - target: 'http://localhost:8880' - }, - '/bff': { - target: 'http://localhost:8880' + plugins: [ + react(), + viteTsconfigPaths(), + svgr(), + importMetaEnv.vite({ + env: './.env', + example: './.env.frontend.example' + }), + sentryVitePlugin({ + org: 'betagouv', + project: 'monitorenv', + url: 'https://sentry.incubateur.net/', + authToken: env.FRONTEND_SENTRY_AUTH_TOKEN + }) + ], + + server: { + port: 3000, + proxy: { + '/api': { + target: 'http://localhost:8880' + }, + '/bff': { + target: 'http://localhost:8880' + } } } }