chore: Centralize env parsing, validation, defaults, and deprecation notices (#3487)
* chore: Centralize env parsing, defaults, deprecation * wip * test * test * tsc * docs, more validation * fix: Allow empty REDIS_URL (defaults to localhost) * test * fix: SLACK_MESSAGE_ACTIONS not bool * fix: Add SMTP port validation
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import env from "@server/env";
|
||||
import TeamDomain from "@server/models/TeamDomain";
|
||||
import { buildTeam, buildUser } from "@server/test/factories";
|
||||
import { flushdb } from "@server/test/support";
|
||||
@@ -25,7 +26,7 @@ describe("teamCreator", () => {
|
||||
});
|
||||
|
||||
it("should not allow creating multiple teams in installation", async () => {
|
||||
delete process.env.DEPLOYMENT;
|
||||
env.DEPLOYMENT = undefined;
|
||||
await buildTeam();
|
||||
let error;
|
||||
|
||||
@@ -47,7 +48,7 @@ describe("teamCreator", () => {
|
||||
});
|
||||
|
||||
it("should return existing team when within allowed domains", async () => {
|
||||
delete process.env.DEPLOYMENT;
|
||||
env.DEPLOYMENT = undefined;
|
||||
const existing = await buildTeam();
|
||||
const user = await buildUser({
|
||||
teamId: existing.id,
|
||||
@@ -106,7 +107,7 @@ describe("teamCreator", () => {
|
||||
});
|
||||
|
||||
it("should return exising team", async () => {
|
||||
delete process.env.DEPLOYMENT;
|
||||
env.DEPLOYMENT = undefined;
|
||||
const authenticationProvider = {
|
||||
name: "google",
|
||||
providerId: "example.com",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import invariant from "invariant";
|
||||
import env from "@server/env";
|
||||
import { DomainNotAllowedError, MaximumTeamsError } from "@server/errors";
|
||||
import Logger from "@server/logging/logger";
|
||||
import { APM } from "@server/logging/tracing";
|
||||
@@ -53,7 +54,7 @@ async function teamCreator({
|
||||
// This team has never been seen before, if self hosted the logic is different
|
||||
// to the multi-tenant version, we want to restrict to a single team that MAY
|
||||
// have multiple authentication providers
|
||||
if (process.env.DEPLOYMENT !== "hosted") {
|
||||
if (env.DEPLOYMENT !== "hosted") {
|
||||
const teamCount = await Team.count();
|
||||
|
||||
// If the self-hosted installation has a single team and the domain for the
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Transaction } from "sequelize";
|
||||
import { sequelize } from "@server/database/sequelize";
|
||||
import env from "@server/env";
|
||||
import { Event, Team, TeamDomain, User } from "@server/models";
|
||||
|
||||
type TeamUpdaterProps = {
|
||||
@@ -27,7 +28,7 @@ const teamUpdater = async ({ params, user, team, ip }: TeamUpdaterProps) => {
|
||||
|
||||
const transaction: Transaction = await sequelize.transaction();
|
||||
|
||||
if (subdomain !== undefined && process.env.SUBDOMAINS_ENABLED === "true") {
|
||||
if (subdomain !== undefined && env.SUBDOMAINS_ENABLED) {
|
||||
team.subdomain = subdomain === "" ? null : subdomain;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import invariant from "invariant";
|
||||
import { uniqBy } from "lodash";
|
||||
import { Role } from "@shared/types";
|
||||
import InviteEmail from "@server/emails/templates/InviteEmail";
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/logger";
|
||||
import { User, Event, Team } from "@server/models";
|
||||
import { UserFlag } from "@server/models/User";
|
||||
@@ -89,11 +90,11 @@ export default async function userInviter({
|
||||
teamUrl: team.url,
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
if (env.ENVIRONMENT === "development") {
|
||||
Logger.info(
|
||||
"email",
|
||||
`Sign in immediately: ${
|
||||
process.env.URL
|
||||
env.URL
|
||||
}/auth/email.callback?token=${newUser.getEmailSigninToken()}`
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user