3 Commits

Author SHA1 Message Date
35d78dc617 use environment when fetching infisical tokens 2023-11-20 15:15:07 +00:00
43bdcfe9e1 rename infisical token env var 2023-11-20 15:14:19 +00:00
fef36b8210 add player model 2023-11-20 15:14:01 +00:00
4 changed files with 61 additions and 5 deletions

View File

@ -1 +1 @@
INFISCAL_TOKEN=set me
INFISICAL_TOKEN=set me

View File

@ -0,0 +1,41 @@
import mongoose, { Model } from "mongoose";
const { Schema } = mongoose;
const schema = new Schema({
/**
* The ID of the player
*/
_id: String,
scoresaber: {
name: String,
profilePicture: String,
country: String,
pp: Number,
rank: Number,
countryRank: Number,
role: String,
badges: [
{
image: String,
description: String,
},
],
histories: String,
scoreStats: {
totalScore: Number,
totalRankedScore: Number,
averageRankedAccuracy: Number,
totalPlayCount: Number,
rankedPlayCount: Number,
replaysWatched: Number,
},
permissions: Number,
banned: Boolean,
inactive: Boolean,
},
});
export const PlayerSchema =
(mongoose.models.Player as Model<typeof schema>) ||
mongoose.model("Player", schema);

View File

@ -8,15 +8,21 @@ import { createInfisicalClient } from "./util/secrets";
// Load the environment variables
dotenv.config();
const isValid = checkEnvironmentVariables("INFISCAL_TOKEN");
const isValid = checkEnvironmentVariables("INFISICAL_TOKEN");
if (!isValid) {
process.exit(1);
}
export const InfisicalClient = createInfisicalClient(
process.env.INFISCAL_TOKEN!
process.env.INFISICAL_TOKEN!
);
console.log("---");
console.log(
"NOTE: If the infisical secret is invalid, it will say secrets are missing."
);
console.log("If this happens please check the env variable and/or the secret");
console.log("---");
// Load the secrets first so we ensure they are valid before starting the server
initSecrets().then(async () => {
await connectMongo();

View File

@ -1,3 +1,4 @@
import { GetOptions } from "infisical-node/src/types/InfisicalClient";
import { InfisicalClient } from "..";
let MONGO_URI: string;
@ -6,10 +7,18 @@ let MONGO_URI: string;
* Initialize the secrets
*/
export async function initSecrets() {
const mongoUri = (await InfisicalClient.getSecret("MONGO_URI")).secretValue;
const options: GetOptions = {
environment: process.env.NODE_ENV === "production" ? "main" : "dev",
path: "/",
type: "shared",
};
const mongoUri = (await InfisicalClient.getSecret("MONGO_URI", options))
.secretValue;
if (!mongoUri) {
throw new Error("MONGO_URI not set in secrets");
console.log("MONGO_URI not set in secrets");
process.exit(1);
}
MONGO_URI = mongoUri;