This commit is contained in:
Tuan Dang
2022-12-10 17:00:10 -05:00
6 changed files with 132 additions and 79 deletions
+1
View File
@@ -40,6 +40,7 @@ SITE_URL=http://localhost:8080
# Required to send emails # Required to send emails
# By default, SMTP_HOST is set to smtp.gmail.com # By default, SMTP_HOST is set to smtp.gmail.com
SMTP_HOST=smtp.gmail.com SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_NAME=Team SMTP_NAME=Team
SMTP_USERNAME=[email protected] SMTP_USERNAME=[email protected]
SMTP_PASSWORD= SMTP_PASSWORD=
+37 -33
View File
@@ -13,12 +13,15 @@ const NODE_ENV = process.env.NODE_ENV! || 'production';
const OAUTH_CLIENT_SECRET_HEROKU = process.env.OAUTH_CLIENT_SECRET_HEROKU!; const OAUTH_CLIENT_SECRET_HEROKU = process.env.OAUTH_CLIENT_SECRET_HEROKU!;
const OAUTH_TOKEN_URL_HEROKU = process.env.OAUTH_TOKEN_URL_HEROKU!; const OAUTH_TOKEN_URL_HEROKU = process.env.OAUTH_TOKEN_URL_HEROKU!;
const POSTHOG_HOST = process.env.POSTHOG_HOST! || 'https://app.posthog.com'; const POSTHOG_HOST = process.env.POSTHOG_HOST! || 'https://app.posthog.com';
const POSTHOG_PROJECT_API_KEY = process.env.POSTHOG_PROJECT_API_KEY! || 'phc_nSin8j5q2zdhpFDI1ETmFNUIuTG4DwKVyIigrY10XiE'; const POSTHOG_PROJECT_API_KEY =
process.env.POSTHOG_PROJECT_API_KEY! ||
'phc_nSin8j5q2zdhpFDI1ETmFNUIuTG4DwKVyIigrY10XiE';
const PRIVATE_KEY = process.env.PRIVATE_KEY!; const PRIVATE_KEY = process.env.PRIVATE_KEY!;
const PUBLIC_KEY = process.env.PUBLIC_KEY!; const PUBLIC_KEY = process.env.PUBLIC_KEY!;
const SENTRY_DSN = process.env.SENTRY_DSN!; const SENTRY_DSN = process.env.SENTRY_DSN!;
const SITE_URL = process.env.SITE_URL!; const SITE_URL = process.env.SITE_URL!;
const SMTP_HOST = process.env.SMTP_HOST! || 'smtp.gmail.com'; const SMTP_HOST = process.env.SMTP_HOST! || 'smtp.gmail.com';
const SMTP_PORT = process.env.SMTP_PORT! || 587;
const SMTP_NAME = process.env.SMTP_NAME!; const SMTP_NAME = process.env.SMTP_NAME!;
const SMTP_USERNAME = process.env.SMTP_USERNAME!; const SMTP_USERNAME = process.env.SMTP_USERNAME!;
const SMTP_PASSWORD = process.env.SMTP_PASSWORD!; const SMTP_PASSWORD = process.env.SMTP_PASSWORD!;
@@ -28,38 +31,39 @@ const STRIPE_PRODUCT_STARTER = process.env.STRIPE_PRODUCT_STARTER!;
const STRIPE_PUBLISHABLE_KEY = process.env.STRIPE_PUBLISHABLE_KEY!; const STRIPE_PUBLISHABLE_KEY = process.env.STRIPE_PUBLISHABLE_KEY!;
const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY!; const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY!;
const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET!; const STRIPE_WEBHOOK_SECRET = process.env.STRIPE_WEBHOOK_SECRET!;
const TELEMETRY_ENABLED = (process.env.TELEMETRY_ENABLED! !== 'false') && true; const TELEMETRY_ENABLED = process.env.TELEMETRY_ENABLED! !== 'false' && true;
export { export {
PORT, PORT,
EMAIL_TOKEN_LIFETIME, EMAIL_TOKEN_LIFETIME,
ENCRYPTION_KEY, ENCRYPTION_KEY,
JWT_AUTH_LIFETIME, JWT_AUTH_LIFETIME,
JWT_AUTH_SECRET, JWT_AUTH_SECRET,
JWT_REFRESH_LIFETIME, JWT_REFRESH_LIFETIME,
JWT_REFRESH_SECRET, JWT_REFRESH_SECRET,
JWT_SERVICE_SECRET, JWT_SERVICE_SECRET,
JWT_SIGNUP_LIFETIME, JWT_SIGNUP_LIFETIME,
JWT_SIGNUP_SECRET, JWT_SIGNUP_SECRET,
MONGO_URL, MONGO_URL,
NODE_ENV, NODE_ENV,
OAUTH_CLIENT_SECRET_HEROKU, OAUTH_CLIENT_SECRET_HEROKU,
OAUTH_TOKEN_URL_HEROKU, OAUTH_TOKEN_URL_HEROKU,
POSTHOG_HOST, POSTHOG_HOST,
POSTHOG_PROJECT_API_KEY, POSTHOG_PROJECT_API_KEY,
PRIVATE_KEY, PRIVATE_KEY,
PUBLIC_KEY, PUBLIC_KEY,
SENTRY_DSN, SENTRY_DSN,
SITE_URL, SITE_URL,
SMTP_HOST, SMTP_HOST,
SMTP_NAME, SMTP_PORT,
SMTP_USERNAME, SMTP_NAME,
SMTP_PASSWORD, SMTP_USERNAME,
STRIPE_PRODUCT_CARD_AUTH, SMTP_PASSWORD,
STRIPE_PRODUCT_PRO, STRIPE_PRODUCT_CARD_AUTH,
STRIPE_PRODUCT_STARTER, STRIPE_PRODUCT_PRO,
STRIPE_PUBLISHABLE_KEY, STRIPE_PRODUCT_STARTER,
STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY,
STRIPE_WEBHOOK_SECRET, STRIPE_SECRET_KEY,
TELEMETRY_ENABLED STRIPE_WEBHOOK_SECRET,
TELEMETRY_ENABLED
}; };
+56 -36
View File
@@ -2,21 +2,40 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
import handlebars from 'handlebars'; import handlebars from 'handlebars';
import nodemailer from 'nodemailer'; import nodemailer from 'nodemailer';
import { SMTP_HOST, SMTP_NAME, SMTP_USERNAME, SMTP_PASSWORD } from '../config'; import {
SMTP_HOST,
SMTP_PORT,
SMTP_NAME,
SMTP_USERNAME,
SMTP_PASSWORD
} from '../config';
import SMTPConnection from 'nodemailer/lib/smtp-connection';
import * as Sentry from '@sentry/node';
const mailOpts: SMTPConnection.Options = {
host: SMTP_HOST,
port: SMTP_PORT as number
};
if (SMTP_USERNAME && SMTP_PASSWORD) {
mailOpts.auth = {
user: SMTP_USERNAME,
pass: SMTP_PASSWORD
};
}
// create nodemailer transporter // create nodemailer transporter
const transporter = nodemailer.createTransport({ const transporter = nodemailer.createTransport(mailOpts);
host: SMTP_HOST,
port: 587,
auth: {
user: SMTP_USERNAME,
pass: SMTP_PASSWORD
}
});
transporter transporter
.verify() .verify()
.then(() => console.log('SMTP - Successfully connected')) .then(() => {
.catch((err) => console.log('SMTP - Failed to connect')); Sentry.setUser(null);
Sentry.captureMessage('SMTP - Successfully connected');
})
.catch((err) => {
Sentry.setUser(null);
Sentry.captureException(
`SMTP - Failed to connect to ${SMTP_HOST}:${SMTP_PORT} \n\t${err}`
);
});
/** /**
* @param {Object} obj * @param {Object} obj
@@ -26,33 +45,34 @@ transporter
* @param {Object} obj.substitutions - object containing template substitutions * @param {Object} obj.substitutions - object containing template substitutions
*/ */
const sendMail = async ({ const sendMail = async ({
template, template,
subjectLine, subjectLine,
recipients, recipients,
substitutions substitutions
}: { }: {
template: string; template: string;
subjectLine: string; subjectLine: string;
recipients: string[]; recipients: string[];
substitutions: any; substitutions: any;
}) => { }) => {
try { try {
const html = fs.readFileSync( const html = fs.readFileSync(
path.resolve(__dirname, '../templates/' + template), path.resolve(__dirname, '../templates/' + template),
'utf8' 'utf8'
); );
const temp = handlebars.compile(html); const temp = handlebars.compile(html);
const htmlToSend = temp(substitutions); const htmlToSend = temp(substitutions);
await transporter.sendMail({ await transporter.sendMail({
from: `"${SMTP_NAME}" <${SMTP_USERNAME}>`, from: `"${SMTP_NAME}" <${SMTP_USERNAME}>`,
to: recipients.join(', '), to: recipients.join(', '),
subject: subjectLine, subject: subjectLine,
html: htmlToSend html: htmlToSend
}); });
} catch (err) { } catch (err) {
console.error(err); Sentry.setUser(null);
} Sentry.captureException(err);
}
}; };
export { sendMail }; export { sendMail };
+14 -1
View File
@@ -20,6 +20,7 @@ services:
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
- mongo - mongo
- smtp-server
build: build:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
@@ -33,7 +34,7 @@ services:
- NODE_ENV=development - NODE_ENV=development
networks: networks:
- infisical-dev - infisical-dev
frontend: frontend:
container_name: infisical-dev-frontend container_name: infisical-dev-frontend
restart: unless-stopped restart: unless-stopped
@@ -84,6 +85,18 @@ services:
networks: networks:
- infisical-dev - infisical-dev
smtp-server:
container_name: infisical-dev-smtp-server
image: mailhog/mailhog
restart: always
logging:
driver: 'none' # disable saving logs
ports:
- 1025:1025 # SMTP server
- 8025:8025 # Web UI
networks:
- infisical-dev
volumes: volumes:
mongo-data: mongo-data:
driver: local driver: local
+6 -4
View File
@@ -1,11 +1,13 @@
--- ---
title: "Frequently Asked Questions" title: 'Frequently Asked Questions'
description: "Have any questions? [Join our Slack community](https://join.slack.com/t/infisical-users/shared_invite/zt-1kdbk07ro-RtoyEt_9E~fyzGo_xQYP6g)." description: 'Have any questions? [Join our Slack community](https://join.slack.com/t/infisical-users/shared_invite/zt-1kdbk07ro-RtoyEt_9E~fyzGo_xQYP6g).'
--- ---
## Problem with SMTP ## Problem with SMTP
You can normally populate `SMTP_USERNAME` and `SMTP_PASSWORD` with your usual login and password (you could also create a 'burner' email). Sometimes, there still are problems. If you opt for actual SMTP server (not the local MailHog), you have to have the right environment variables set.
You can normally populate `SMTP_USERNAME` and `SMTP_PASSWORD` with your usual login and password (you could also create a 'burner' email). Sometimes, there still are problems.
You can go to your Gmail account settings > security and enable “less secure apps”. This would allow Infisical to use your Gmail to send emails. You can go to your Gmail account settings > security and enable “less secure apps”. This would allow Infisical to use your Gmail to send emails.
@@ -13,4 +15,4 @@ If it still doesn't work, [this](https://stackoverflow.com/questions/72547853/un
## `MONGO_URL` issues ## `MONGO_URL` issues
Your `MONGO_URL` should be something like `mongodb://root:example@mongo:27017/?authSource=admin`. If you want to change it (not recommended), you should make sure that you keep this URL in line with `MONGO_USERNAME=root` and `MONGO_PASSWORD=example`. Your `MONGO_URL` should be something like `mongodb://root:example@mongo:27017/?authSource=admin`. If you want to change it (not recommended), you should make sure that you keep this URL in line with `MONGO_USERNAME=root` and `MONGO_PASSWORD=example`.
+18 -5
View File
@@ -1,6 +1,6 @@
--- ---
title: "Developing" title: 'Developing'
description: "This guide will help you set up and run Infisical in development mode." description: 'This guide will help you set up and run Infisical in development mode.'
--- ---
## Clone the repo ## Clone the repo
@@ -48,14 +48,27 @@ Take into account that if you use your own `MONGO_USERNAME` and `MONGO_PASSWORD`
![image](https://user-images.githubusercontent.com/118568289/206792653-ba3211d1-1071-43f2-93a7-8b408bbd9e0e.png) ![image](https://user-images.githubusercontent.com/118568289/206792653-ba3211d1-1071-43f2-93a7-8b408bbd9e0e.png)
These variables are needed to use the Mail SMTP service that takes care of sending the verification code when you If you want to receive actual emails (e.g. you want to test how the email message will look like), take note of the following.
register in the app.
For the `SMTP_USERNAME` variable, you will need an email with 2-steps-verification. For the `SMTP_USERNAME` variable, you will need an email with 2-steps-verification.
For the `SMTP_PASSWORD` variable, you will need to [generate an app password](https://support.google.com/mail/answer/185833?hl=en) with the email you used in the `SMTP_USERNAME` variable. For the `SMTP_PASSWORD` variable, you will need to [generate an app password](https://support.google.com/mail/answer/185833?hl=en) with the email you used in the `SMTP_USERNAME` variable.
With this environment variables, you will be ready to run the docker-compose. Otherwise, a local SMTP server (MailHog) is available for testing purposes. Set the following values to use this:
```
SMTP_HOST=smtp-server
SMTP_PORT=1025
SMTP_NAME=<whatever you like>
[email protected]
SMTP_PASSWORD=
```
Make sure to leave the `SMTP_PASSWORD` blank so the backend will be able to connect to MailHog
You can browse `http://localhost:8025/` to browse email messages sent by the backend.
With these environment variables, you will be ready to run the docker-compose.
## Docker for development ## Docker for development