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
Christopher Kolstad fc4d95ff5b
fix: configure user endpoint when AuthType is NONE (#1403)
Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
2022-03-01 10:52:22 +01:00

56 lines
1.8 KiB
TypeScript

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';
class ConfigController extends Controller {
private versionService: VersionService;
private settingService: SettingService;
private uiConfig: any;
constructor(
config: IUnleashConfig,
{
versionService,
settingService,
}: Pick<IUnleashServices, 'versionService' | 'settingService'>,
) {
super(config);
this.versionService = versionService;
this.settingService = settingService;
const authenticationType =
config.authentication && config.authentication.type;
this.uiConfig = {
...config.ui,
authenticationType,
unleashUrl: config.server.unleashUrl,
baseUriPath: config.server.baseUriPath,
version,
};
this.get('/', this.getUIConfig);
}
async getUIConfig(req: Request, res: Response): Promise<void> {
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 });
}
}
export default ConfigController;