2021-04-22 10:07:10 +02:00
|
|
|
import { Request, Response } from 'express';
|
|
|
|
import { IUnleashServices } from '../../types/services';
|
2022-03-01 10:52:22 +01:00
|
|
|
import { IAuthType, IUnleashConfig } from '../../types/option';
|
2021-04-22 10:07:10 +02:00
|
|
|
import version from '../../util/version';
|
|
|
|
|
2021-10-29 10:25:42 +02:00
|
|
|
import Controller from '../controller';
|
|
|
|
import VersionService from '../../services/version-service';
|
|
|
|
import SettingService from '../../services/setting-service';
|
|
|
|
import {
|
|
|
|
simpleAuthKey,
|
|
|
|
SimpleAuthSettings,
|
|
|
|
} from '../../types/settings/simple-auth-settings';
|
2019-03-12 10:46:08 +01:00
|
|
|
|
|
|
|
class ConfigController extends Controller {
|
2021-10-29 10:25:42 +02:00
|
|
|
private versionService: VersionService;
|
|
|
|
|
|
|
|
private settingService: SettingService;
|
|
|
|
|
|
|
|
private uiConfig: any;
|
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
constructor(
|
|
|
|
config: IUnleashConfig,
|
2021-10-29 10:25:42 +02:00
|
|
|
{
|
|
|
|
versionService,
|
|
|
|
settingService,
|
|
|
|
}: Pick<IUnleashServices, 'versionService' | 'settingService'>,
|
2021-04-22 10:07:10 +02:00
|
|
|
) {
|
2019-03-12 10:46:08 +01:00
|
|
|
super(config);
|
2021-02-19 11:13:25 +01:00
|
|
|
this.versionService = versionService;
|
2021-10-29 10:25:42 +02:00
|
|
|
this.settingService = settingService;
|
2021-04-15 11:35:45 +02:00
|
|
|
const authenticationType =
|
|
|
|
config.authentication && config.authentication.type;
|
2021-02-19 11:13:25 +01:00
|
|
|
this.uiConfig = {
|
|
|
|
...config.ui,
|
2021-04-15 11:29:53 +02:00
|
|
|
authenticationType,
|
2021-04-22 10:07:10 +02:00
|
|
|
unleashUrl: config.server.unleashUrl,
|
|
|
|
baseUriPath: config.server.baseUriPath,
|
|
|
|
version,
|
2021-02-19 11:13:25 +01:00
|
|
|
};
|
2019-03-12 10:46:08 +01:00
|
|
|
this.get('/', this.getUIConfig);
|
|
|
|
}
|
|
|
|
|
2021-04-22 10:07:10 +02:00
|
|
|
async getUIConfig(req: Request, res: Response): Promise<void> {
|
2019-03-12 10:46:08 +01:00
|
|
|
const config = this.uiConfig;
|
2021-10-29 10:25:42 +02:00
|
|
|
const simpleAuthSettings =
|
|
|
|
await this.settingService.get<SimpleAuthSettings>(simpleAuthKey);
|
|
|
|
|
|
|
|
const versionInfo = this.versionService.getVersionInfo();
|
2022-03-01 10:52:22 +01:00
|
|
|
const disablePasswordAuth =
|
|
|
|
simpleAuthSettings?.disabled ||
|
|
|
|
this.config.authentication.type == IAuthType.NONE;
|
2021-10-29 10:25:42 +02:00
|
|
|
res.json({ ...config, versionInfo, disablePasswordAuth });
|
2019-03-12 10:46:08 +01:00
|
|
|
}
|
|
|
|
}
|
2021-04-22 10:07:10 +02:00
|
|
|
export default ConfigController;
|