1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00
unleash.unleash/src/lib/routes/admin-api/config.ts

56 lines
1.8 KiB
TypeScript
Raw Normal View History

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