mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-31 13:47:02 +02:00
chore: expose instanceId so it can be used from addons (#5231)
## About the changes A bit of boy scouting trying to expose the instanceId
This commit is contained in:
parent
406b2383da
commit
b1ea2c3b88
@ -14,7 +14,6 @@ export default class SettingStore implements ISettingStore {
|
|||||||
this.logger = getLogger('settings-store.ts');
|
this.logger = getLogger('settings-store.ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
||||||
async updateRow(name: string, content: any): Promise<void> {
|
async updateRow(name: string, content: any): Promise<void> {
|
||||||
return this.db(TABLE)
|
return this.db(TABLE)
|
||||||
.where('name', name)
|
.where('name', name)
|
||||||
@ -23,7 +22,6 @@ export default class SettingStore implements ISettingStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
||||||
async insertNewRow(name: string, content: any) {
|
async insertNewRow(name: string, content: any) {
|
||||||
return this.db(TABLE).insert({ name, content });
|
return this.db(TABLE).insert({ name, content });
|
||||||
}
|
}
|
||||||
@ -37,8 +35,12 @@ export default class SettingStore implements ISettingStore {
|
|||||||
return present;
|
return present;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(name: string): Promise<any> {
|
async get<T>(name: string): Promise<T | undefined> {
|
||||||
const result = await this.db.select().from(TABLE).where('name', name);
|
const result = await this.db
|
||||||
|
.select()
|
||||||
|
.from(TABLE)
|
||||||
|
.where('name', name)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
return result[0].content;
|
return result[0].content;
|
||||||
@ -46,7 +48,6 @@ export default class SettingStore implements ISettingStore {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
||||||
async insert(name: string, content: any): Promise<void> {
|
async insert(name: string, content: any): Promise<void> {
|
||||||
const exists = await this.exists(name);
|
const exists = await this.exists(name);
|
||||||
if (exists) {
|
if (exists) {
|
||||||
|
@ -171,7 +171,7 @@ export class InstanceStatsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async hasOIDC(): Promise<boolean> {
|
async hasOIDC(): Promise<boolean> {
|
||||||
const settings = await this.settingStore.get(
|
const settings = await this.settingStore.get<{ enabled: boolean }>(
|
||||||
'unleash.enterprise.auth.oidc',
|
'unleash.enterprise.auth.oidc',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ export class InstanceStatsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async hasSAML(): Promise<boolean> {
|
async hasSAML(): Promise<boolean> {
|
||||||
const settings = await this.settingStore.get(
|
const settings = await this.settingStore.get<{ enabled: boolean }>(
|
||||||
'unleash.enterprise.auth.saml',
|
'unleash.enterprise.auth.saml',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -63,9 +63,8 @@ async function createApp(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!config.server.secret) {
|
if (!config.server.secret) {
|
||||||
const secret = await stores.settingStore.get('unleash.secret');
|
const secret = await stores.settingStore.get<string>('unleash.secret');
|
||||||
// eslint-disable-next-line no-param-reassign
|
config.server.secret = secret!;
|
||||||
config.server.secret = secret;
|
|
||||||
}
|
}
|
||||||
const app = await getApp(config, stores, services, unleashSession, db);
|
const app = await getApp(config, stores, services, unleashSession, db);
|
||||||
|
|
||||||
|
@ -29,8 +29,16 @@ export default class SettingService {
|
|||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get<T>(id: string, defaultValue?: T): Promise<T> {
|
/**
|
||||||
const value = await this.settingStore.get(id);
|
* @deprecated use getWithDefault instead
|
||||||
|
*/
|
||||||
|
async get<T>(id: string, defaultValue?: T): Promise<T | undefined> {
|
||||||
|
const value = await this.settingStore.get<T>(id);
|
||||||
|
return value || defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getWithDefault<T>(id: string, defaultValue: T): Promise<T> {
|
||||||
|
const value = await this.settingStore.get<T>(id);
|
||||||
return value || defaultValue;
|
return value || defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,19 +188,25 @@ export default class VersionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async setup(): Promise<void> {
|
async setup(): Promise<void> {
|
||||||
await this.setInstanceId();
|
await this.readInstanceId();
|
||||||
await this.checkLatestVersion();
|
await this.checkLatestVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setInstanceId(): Promise<void> {
|
private async readInstanceId(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const { id } = await this.settingStore.get('instanceInfo');
|
const { id } = (await this.settingStore.get<{ id: string }>(
|
||||||
|
'instanceInfo',
|
||||||
|
)) ?? { id: undefined };
|
||||||
this.instanceId = id;
|
this.instanceId = id;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.warn('Could not find instanceInfo');
|
this.logger.warn('Could not find instanceInfo');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInstanceId() {
|
||||||
|
return this.instanceId;
|
||||||
|
}
|
||||||
|
|
||||||
async checkLatestVersion(): Promise<void> {
|
async checkLatestVersion(): Promise<void> {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
try {
|
try {
|
||||||
@ -336,7 +342,7 @@ export default class VersionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async hasOIDC(): Promise<boolean> {
|
async hasOIDC(): Promise<boolean> {
|
||||||
const settings = await this.settingStore.get(
|
const settings = await this.settingStore.get<{ enabled: boolean }>(
|
||||||
'unleash.enterprise.auth.oidc',
|
'unleash.enterprise.auth.oidc',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -344,7 +350,7 @@ export default class VersionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async hasSAML(): Promise<boolean> {
|
async hasSAML(): Promise<boolean> {
|
||||||
const settings = await this.settingStore.get(
|
const settings = await this.settingStore.get<{ enabled: boolean }>(
|
||||||
'unleash.enterprise.auth.saml',
|
'unleash.enterprise.auth.saml',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -356,6 +362,7 @@ export default class VersionService {
|
|||||||
current: this.current,
|
current: this.current,
|
||||||
latest: this.latest || {},
|
latest: this.latest || {},
|
||||||
isLatest: this.isLatest,
|
isLatest: this.isLatest,
|
||||||
|
// @ts-ignore instance id can be undefined but not on the version. What should we do is still unclear.
|
||||||
instanceId: this.instanceId,
|
instanceId: this.instanceId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,6 @@ export enum PermissionType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum RoleName {
|
export enum RoleName {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
||||||
ADMIN = 'Admin',
|
ADMIN = 'Admin',
|
||||||
EDITOR = 'Editor',
|
EDITOR = 'Editor',
|
||||||
VIEWER = 'Viewer',
|
VIEWER = 'Viewer',
|
||||||
|
@ -8,4 +8,5 @@ export interface ISettingInsert {
|
|||||||
export interface ISettingStore extends Store<any, string> {
|
export interface ISettingStore extends Store<any, string> {
|
||||||
insert<T>(name: string, content: T): Promise<void>;
|
insert<T>(name: string, content: T): Promise<void>;
|
||||||
updateRow(name: string, content: any): Promise<void>;
|
updateRow(name: string, content: any): Promise<void>;
|
||||||
|
get<T>(name: string): Promise<T | undefined>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user