From f54543347a4ed7ece6738b14ac42cbd9d6f828cc Mon Sep 17 00:00:00 2001 From: Maxime Golfier <25312957+maxgfr@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:43:11 +0200 Subject: [PATCH] fix(env): set default credentials when `.env` is not set (#1041) --- targets/frontend/src/config.ts | 8 +++----- targets/frontend/src/lib/azure.js | 4 ++-- targets/frontend/src/lib/emails/sendmail.js | 6 +++--- targets/frontend/src/pages/api/login.js | 4 +--- targets/frontend/src/pages/api/storage/[path].js | 2 +- targets/frontend/src/pages/api/storage/index.js | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/targets/frontend/src/config.ts b/targets/frontend/src/config.ts index e26dffe0d..c29a5f4ef 100644 --- a/targets/frontend/src/config.ts +++ b/targets/frontend/src/config.ts @@ -2,9 +2,7 @@ export const ACCOUNT_MAIL_SENDER = "contact@fabrique.social.gouv.fr"; export const JWT_TOKEN_EXPIRES = 15; // 15 min export const REFRESH_TOKEN_EXPIRES = 43200; // 30 days in minutes export const ACTIVATION_TOKEN_EXPIRES = 10080; // 7 days in minutes -export const HASURA_GRAPHQL_JWT_SECRET = process.env - .HASURA_GRAPHQL_JWT_SECRET ?? { - type: "HS256", - key: "a_pretty_long_secret_key_that_should_be_at_least_32_char", -}; +export const HASURA_GRAPHQL_JWT_SECRET = + process.env.HASURA_GRAPHQL_JWT_SECRET ?? + '{"type":"HS256","key":"a_pretty_long_secret_key_that_should_be_at_least_32_char"}'; export const BASE_URL = process.env.FRONTEND_HOST || `http://localhost:3000`; diff --git a/targets/frontend/src/lib/azure.js b/targets/frontend/src/lib/azure.js index df5b6b9cc..0535c68bd 100644 --- a/targets/frontend/src/lib/azure.js +++ b/targets/frontend/src/lib/azure.js @@ -5,8 +5,8 @@ import { } from "@azure/storage-blob"; const AZURE_STORAGE_ACCOUNT = { - key: process.env.AZURE_STORAGE_ACCOUNT_KEY || "", - name: process.env.AZURE_STORAGE_ACCOUNT_NAME || "", + key: process.env.AZURE_STORAGE_ACCOUNT_KEY || "accountKey", + name: process.env.AZURE_STORAGE_ACCOUNT_NAME || "cdtnadmindev", }; export const getBlobContainer = (containerName) => { diff --git a/targets/frontend/src/lib/emails/sendmail.js b/targets/frontend/src/lib/emails/sendmail.js index 98a5be423..c8b0278eb 100644 --- a/targets/frontend/src/lib/emails/sendmail.js +++ b/targets/frontend/src/lib/emails/sendmail.js @@ -3,10 +3,10 @@ import nodemailer from "nodemailer"; export default function sendmail(mailOptions) { const transport = nodemailer.createTransport({ auth: { - pass: process.env.SMTP_EMAIL_PASSWORD, - user: process.env.SMTP_EMAIL_USER, + pass: process.env.SMTP_EMAIL_PASSWORD ?? "pass", + user: process.env.SMTP_EMAIL_USER ?? "email", }, - host: process.env.SMTP_URL, + host: process.env.SMTP_URL ?? "smtp.url", port: 587, }); return transport.sendMail(mailOptions).finally(() => transport.close()); diff --git a/targets/frontend/src/pages/api/login.js b/targets/frontend/src/pages/api/login.js index c30d8982a..5a2bfed2b 100644 --- a/targets/frontend/src/pages/api/login.js +++ b/targets/frontend/src/pages/api/login.js @@ -9,9 +9,7 @@ import { getExpiryDate } from "src/lib/duration"; import { loginQuery, refreshTokenMutation } from "./login.gql"; -const { REFRESH_TOKEN_EXPIRES = "" } = process.env; - -import { JWT_TOKEN_EXPIRES } from "../../config"; +import { JWT_TOKEN_EXPIRES, REFRESH_TOKEN_EXPIRES } from "../../config"; export default async function login(req, res) { const apiError = createErrorFor(res); diff --git a/targets/frontend/src/pages/api/storage/[path].js b/targets/frontend/src/pages/api/storage/[path].js index 5bfd18c83..20fef9633 100644 --- a/targets/frontend/src/pages/api/storage/[path].js +++ b/targets/frontend/src/pages/api/storage/[path].js @@ -4,7 +4,7 @@ import { createErrorFor } from "src/lib/apiError"; import { deleteBlob } from "src/lib/azure"; import { HASURA_GRAPHQL_JWT_SECRET } from "../../../config"; -const container = process.env.STORAGE_CONTAINER; +const container = process.env.STORAGE_CONTAINER ?? "cdtn-dev"; const jwtSecret = JSON.parse(HASURA_GRAPHQL_JWT_SECRET); export default async function deleteFiles(req, res) { diff --git a/targets/frontend/src/pages/api/storage/index.js b/targets/frontend/src/pages/api/storage/index.js index 9d114442b..c4533567b 100644 --- a/targets/frontend/src/pages/api/storage/index.js +++ b/targets/frontend/src/pages/api/storage/index.js @@ -7,7 +7,7 @@ import { isUploadFileSafe } from "src/lib/secu"; import * as stream from "stream"; import { HASURA_GRAPHQL_JWT_SECRET } from "../../../config"; -const container = process.env.STORAGE_CONTAINER; +const container = process.env.STORAGE_CONTAINER ?? "cdtn-dev"; const jwtSecret = JSON.parse(HASURA_GRAPHQL_JWT_SECRET); async function endPoint(req, res) {