2024-05-28 16:45:34 +00:00
|
|
|
import * as plugins from './plugins.js';
|
|
|
|
import * as paths from './paths.js';
|
2024-05-30 20:49:39 +00:00
|
|
|
import { logger } from './logger.js';
|
2024-05-28 16:45:34 +00:00
|
|
|
import type { Cloudly } from './classes.cloudly.js';
|
2024-04-20 10:21:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the main cloudly config
|
|
|
|
*/
|
|
|
|
export class CloudlyConfig {
|
|
|
|
public cloudlyRef: Cloudly;
|
|
|
|
public appData: plugins.npmextra.AppData<plugins.servezoneInterfaces.data.ICloudlyConfig>;
|
2024-10-27 18:50:39 +00:00
|
|
|
public data: plugins.servezoneInterfaces.data.ICloudlyConfig;
|
2024-04-20 10:21:41 +00:00
|
|
|
|
|
|
|
constructor(cloudlyRefArg: Cloudly) {
|
|
|
|
this.cloudlyRef = cloudlyRefArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async init() {
|
2024-10-27 18:50:39 +00:00
|
|
|
this.appData =
|
|
|
|
await plugins.npmextra.AppData.createAndInit<plugins.servezoneInterfaces.data.ICloudlyConfig>(
|
|
|
|
{
|
|
|
|
envMapping: {
|
|
|
|
cfToken: 'CF_TOKEN',
|
|
|
|
environment: 'SERVEZONE_ENVIRONMENT' as 'production' | 'integration',
|
|
|
|
letsEncryptEmail: 'hard:domains@lossless.org',
|
|
|
|
hetznerToken: 'HETZNER_API_TOKEN',
|
|
|
|
letsEncryptPrivateKey: null,
|
|
|
|
publicUrl: 'SERVEZONE_URL',
|
|
|
|
publicPort: 'SERVEZONE_PORT',
|
|
|
|
mongoDescriptor: {
|
|
|
|
mongoDbUrl: 'MONGODB_URL',
|
|
|
|
mongoDbName: 'MONGODB_DATABASE',
|
|
|
|
mongoDbUser: 'MONGODB_USER',
|
|
|
|
mongoDbPass: 'MONGODB_PASSWORD',
|
|
|
|
},
|
|
|
|
s3Descriptor: {
|
|
|
|
endpoint: 'S3_ENDPOINT',
|
|
|
|
accessKey: 'S3_ACCESSKEY',
|
|
|
|
accessSecret: 'S3_SECRETKEY',
|
|
|
|
port: 'S3_PORT', // Note: This will remain as a string. Ensure to parse it to an integer where it's used.
|
|
|
|
useSsl: true,
|
|
|
|
},
|
|
|
|
sslMode:
|
|
|
|
'SERVEZONE_SSLMODE' as plugins.servezoneInterfaces.data.ICloudlyConfig['sslMode'],
|
|
|
|
servezoneAdminaccount: 'SERVEZONE_ADMINACCOUNT',
|
|
|
|
},
|
|
|
|
requiredKeys: [
|
|
|
|
'cfToken',
|
|
|
|
'hetznerToken',
|
|
|
|
'letsEncryptEmail',
|
|
|
|
'publicUrl',
|
|
|
|
'publicPort',
|
|
|
|
'sslMode',
|
|
|
|
'environment',
|
|
|
|
'mongoDescriptor',
|
|
|
|
],
|
2024-04-20 10:21:41 +00:00
|
|
|
},
|
2024-10-27 18:50:39 +00:00
|
|
|
);
|
2024-04-20 10:21:41 +00:00
|
|
|
|
|
|
|
const kvStore = await this.appData.getKvStore();
|
|
|
|
|
|
|
|
this.data = await kvStore.readAll();
|
|
|
|
const missingKeys = await this.appData.logMissingKeys();
|
|
|
|
if (missingKeys.length > 0) {
|
|
|
|
logger.log('error', `missing keys: ${missingKeys.join(', ')}`);
|
|
|
|
throw new Error('missing keys');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|