-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglobals.ts
119 lines (100 loc) · 3.92 KB
/
globals.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { Express } from "express";
import dotenv from "dotenv";
import { Collection, ObjectId } from "mongodb";
import { AzureLogLevel } from "@azure/logger";
import { MongoHandle } from "./handles";
import { MongoImage } from "./images";
import { MongoScene } from "./scenes";
import { MongoEvent } from "./events";
import { MongoTessellation } from "./tessellation";
import { MongoSceneFeature, MongoSceneFeatureQueue } from "./features";
import { Job } from "node-schedule";
export class Config {
// The port number on which the server will listen.
port: number;
// The base URL of the Keycloak server. This should end in a slash.
kcBaseUrl: string;
// The Keycloak realm in which we operate.
kcRealm: string;
// The connection string for the MongoDB storage server.
mongoConnectionString: string;
// The MongoDB database name in which we operate.
mongoDbName: string;
// Preview base URL
previewBaseUrl: string;
// Secrets used to hash session cookies. The first item in the list is the
// active secret used for new sessions; other items are older secrets that are
// used for checking. So, as we rotate secrets, we move them backwards in the
// list and eventually drop them when we're comfortable with resetting their
// corresponding sessions.
sessionSecrets: string[];
//
// Previewer server URL
previewerUrl: string;
// The Keycloak ID of the "superuser" user. This account can access a few
// highly privileged operations that set up administration of the website
// through more regular IAM channels. If this is set to some kind of dummy
// value, then no one is superuser.
superuserAccountId: string;
// The logging level to use through the application.
logLevel: AzureLogLevel;
constructor() {
dotenv.config();
const portstr = process.env.PORT ?? "7000"; // Azure might tell us which port to listen on
this.port = parseInt(portstr, 10);
this.kcBaseUrl = process.env.KEYCLOAK_URL ?? "http://localhost:8080/";
if (!this.kcBaseUrl.endsWith("/")) {
this.kcBaseUrl += "/";
}
this.kcRealm = "constellations";
const connstr = process.env.AZURE_COSMOS_CONNECTIONSTRING ?? process.env.MONGO_CONNECTION_STRING;
if (connstr === undefined) {
throw new Error("must define $AZURE_COSMOS_CONNECTIONSTRING or $MONGO_CONNECTION_STRING");
}
this.mongoConnectionString = connstr;
this.mongoDbName = "constellations";
this.previewBaseUrl = process.env.CX_PREVIEW_BASE_URL ?? "";
this.sessionSecrets = (process.env.CX_SESSION_SECRETS ?? "dev-secret").split(" ");
const previewerUrl = process.env.CX_PREVIEW_SERVICE_URL;
if (previewerUrl === undefined) {
throw new Error("must define $CX_PREVIEW_SERVICE_URL");
}
this.previewerUrl = previewerUrl;
this.superuserAccountId = process.env.CX_SUPERUSER_ACCOUNT_ID ?? "nosuperuser";
this.logLevel = process.env.CX_LOG_LEVEL as AzureLogLevel ?? "info";
}
}
export class State {
config: Config;
app: Express;
scenes: Collection<MongoScene>;
images: Collection<MongoImage>;
handles: Collection<MongoHandle>;
events: Collection<MongoEvent>;
features: Collection<MongoSceneFeature>;
featureQueue: Collection<MongoSceneFeatureQueue>;
tessellations: Collection<MongoTessellation>;
scheduledFeatureJobs: Map<ObjectId, Job>;
constructor(
config: Config,
app: Express,
scenes: Collection<MongoScene>,
images: Collection<MongoImage>,
handles: Collection<MongoHandle>,
events: Collection<MongoEvent>,
features: Collection<MongoSceneFeature>,
featureQueue: Collection<MongoSceneFeatureQueue>,
tessellations: Collection<MongoTessellation>,
) {
this.config = config;
this.app = app;
this.scenes = scenes;
this.images = images;
this.handles = handles;
this.events = events;
this.features = features;
this.featureQueue = featureQueue;
this.tessellations = tessellations;
this.scheduledFeatureJobs = new Map();
}
}