feat(feature-flags): fixes #1592, introduces new flags DISABLE_SIGNUPS and DISABLE_EMAIL_AUTH, renamed STORAGE_SKIP_BUCKET_CHECK

This commit is contained in:
Amruth Pillai
2024-05-29 10:30:38 +02:00
parent 1191bbca67
commit d18ef2e1a5
23 changed files with 1697 additions and 1366 deletions

View File

@ -10,6 +10,7 @@ import { AuthModule } from "./auth/auth.module";
import { ConfigModule } from "./config/config.module";
import { ContributorsModule } from "./contributors/contributors.module";
import { DatabaseModule } from "./database/database.module";
import { FeatureModule } from "./feature/feature.module";
import { HealthModule } from "./health/health.module";
import { MailModule } from "./mail/mail.module";
import { PrinterModule } from "./printer/printer.module";
@ -33,6 +34,7 @@ import { UserModule } from "./user/user.module";
ResumeModule,
StorageModule,
PrinterModule,
FeatureModule,
TranslationModule,
ContributorsModule,

View File

@ -44,17 +44,21 @@ export const configSchema = z.object({
.string()
.default("false")
.transform((s) => s !== "false" && s !== "0"),
STORAGE_SKIP_BUCKET_CHECK: z
.string()
.default("false")
.transform((s) => s !== "false" && s !== "0"),
// Crowdin (Optional)
CROWDIN_PROJECT_ID: z.coerce.number().optional(),
CROWDIN_PERSONAL_TOKEN: z.string().optional(),
// Flags (Optional)
DISABLE_EMAIL_AUTH: z
// Feature Flags (Optional)
DISABLE_SIGNUPS: z
.string()
.default("false")
.transform((s) => s !== "false" && s !== "0"),
SKIP_STORAGE_BUCKET_CHECK: z
DISABLE_EMAIL_AUTH: z
.string()
.default("false")
.transform((s) => s !== "false" && s !== "0"),

View File

@ -6,6 +6,7 @@ import { ContributorDto } from "@reactive-resume/dto";
import { Config } from "../config/schema";
type GitHubResponse = { id: number; login: string; html_url: string; avatar_url: string }[];
type CrowdinContributorsResponse = {
data: { data: { id: number; username: string; avatarUrl: string } }[];
};

View File

@ -0,0 +1,13 @@
import { Controller, Get } from "@nestjs/common";
import { FeatureService } from "./feature.service";
@Controller("feature")
export class FeatureController {
constructor(private readonly featureService: FeatureService) {}
@Get("/flags")
getFeatureFlags() {
return this.featureService.getFeatures();
}
}

View File

@ -0,0 +1,11 @@
import { Module } from "@nestjs/common";
import { FeatureController } from "./feature.controller";
import { FeatureService } from "./feature.service";
@Module({
providers: [FeatureService],
controllers: [FeatureController],
exports: [FeatureService],
})
export class FeatureModule {}

View File

@ -0,0 +1,19 @@
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { Config } from "../config/schema";
@Injectable()
export class FeatureService {
constructor(private readonly configService: ConfigService<Config>) {}
getFeatures() {
const isSignupsDisabled = this.configService.getOrThrow<boolean>("DISABLE_SIGNUPS");
const isEmailAuthDisabled = this.configService.getOrThrow<boolean>("DISABLE_EMAIL_AUTH");
return {
isSignupsDisabled,
isEmailAuthDisabled,
};
}
}

View File

@ -49,14 +49,13 @@ export class StorageService implements OnModuleInit {
this.client = this.minioService.client;
this.bucketName = this.configService.getOrThrow<string>("STORAGE_BUCKET");
const skipBucketCheck = this.configService.getOrThrow<boolean>("SKIP_STORAGE_BUCKET_CHECK");
const skipBucketCheck = this.configService.getOrThrow<boolean>("STORAGE_SKIP_BUCKET_CHECK");
if (skipBucketCheck) {
this.logger.log("Skipping the verification of whether the storage bucket exists.");
this.logger.warn("Make sure that the following paths are publicly accessible: ");
this.logger.warn("- /pictures/*");
this.logger.warn("- /previews/*");
this.logger.warn("- /resumes/*");
this.logger.warn("Skipping the verification of whether the storage bucket exists.");
this.logger.warn(
"Make sure that the following paths are publicly accessible: `/{pictures,previews,resumes}/*`",
);
return;
}