2024-01-17 14:33:03 +01:00
|
|
|
import { Db, IUnleashConfig } from '../../server-impl';
|
2023-02-21 10:15:57 +01:00
|
|
|
import GroupStore from '../../db/group-store';
|
|
|
|
import { AccountStore } from '../../db/account-store';
|
|
|
|
import RoleStore from '../../db/role-store';
|
2023-12-01 12:41:46 +01:00
|
|
|
import EnvironmentStore from '../project-environments/environment-store';
|
2023-02-21 10:15:57 +01:00
|
|
|
import { AccessStore } from '../../db/access-store';
|
2023-09-27 15:23:05 +02:00
|
|
|
import { AccessService, EventService, GroupService } from '../../services';
|
2023-02-21 10:15:57 +01:00
|
|
|
import FakeGroupStore from '../../../test/fixtures/fake-group-store';
|
|
|
|
import FakeEventStore from '../../../test/fixtures/fake-event-store';
|
|
|
|
import { FakeAccountStore } from '../../../test/fixtures/fake-account-store';
|
|
|
|
import FakeRoleStore from '../../../test/fixtures/fake-role-store';
|
2023-12-01 12:41:46 +01:00
|
|
|
import FakeEnvironmentStore from '../project-environments/fake-environment-store';
|
2023-02-21 10:15:57 +01:00
|
|
|
import FakeAccessStore from '../../../test/fixtures/fake-access-store';
|
2023-09-27 15:23:05 +02:00
|
|
|
import FakeFeatureTagStore from '../../../test/fixtures/fake-feature-tag-store';
|
2023-11-24 14:22:31 +01:00
|
|
|
import { IEventStore } from '../../types';
|
2024-01-16 13:11:28 +01:00
|
|
|
import { createEventsService } from '../events/createEventsService';
|
2023-02-16 08:08:51 +01:00
|
|
|
|
|
|
|
export const createAccessService = (
|
|
|
|
db: Db,
|
|
|
|
config: IUnleashConfig,
|
|
|
|
): AccessService => {
|
2023-06-14 15:40:40 +02:00
|
|
|
const { eventBus, getLogger, flagResolver } = config;
|
2023-02-16 08:08:51 +01:00
|
|
|
const groupStore = new GroupStore(db);
|
|
|
|
const accountStore = new AccountStore(db, getLogger);
|
|
|
|
const roleStore = new RoleStore(db, eventBus, getLogger);
|
|
|
|
const environmentStore = new EnvironmentStore(db, eventBus, getLogger);
|
|
|
|
const accessStore = new AccessStore(db, eventBus, getLogger);
|
2024-01-16 13:11:28 +01:00
|
|
|
const eventService = createEventsService(db, config);
|
2023-02-16 08:08:51 +01:00
|
|
|
const groupService = new GroupService(
|
2023-09-27 15:23:05 +02:00
|
|
|
{ groupStore, accountStore },
|
2023-02-16 08:08:51 +01:00
|
|
|
{ getLogger },
|
2023-09-27 15:23:05 +02:00
|
|
|
eventService,
|
2023-02-16 08:08:51 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return new AccessService(
|
2023-11-24 14:22:31 +01:00
|
|
|
{ accessStore, accountStore, roleStore, environmentStore },
|
2023-06-14 15:40:40 +02:00
|
|
|
{ getLogger, flagResolver },
|
2023-02-16 08:08:51 +01:00
|
|
|
groupService,
|
2023-11-24 14:22:31 +01:00
|
|
|
eventService,
|
2023-02-16 08:08:51 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createFakeAccessService = (
|
|
|
|
config: IUnleashConfig,
|
2023-11-24 14:22:31 +01:00
|
|
|
): { accessService: AccessService; eventStore: IEventStore } => {
|
2023-06-14 15:40:40 +02:00
|
|
|
const { getLogger, flagResolver } = config;
|
2023-02-16 08:08:51 +01:00
|
|
|
const eventStore = new FakeEventStore();
|
|
|
|
const groupStore = new FakeGroupStore();
|
|
|
|
const accountStore = new FakeAccountStore();
|
|
|
|
const roleStore = new FakeRoleStore();
|
|
|
|
const environmentStore = new FakeEnvironmentStore();
|
2023-06-22 16:42:01 +02:00
|
|
|
const accessStore = new FakeAccessStore(roleStore);
|
2023-09-27 15:23:05 +02:00
|
|
|
const featureTagStore = new FakeFeatureTagStore();
|
|
|
|
const eventService = new EventService(
|
|
|
|
{ eventStore, featureTagStore },
|
|
|
|
config,
|
|
|
|
);
|
2023-02-16 08:08:51 +01:00
|
|
|
const groupService = new GroupService(
|
2023-09-27 15:23:05 +02:00
|
|
|
{ groupStore, accountStore },
|
2023-02-16 08:08:51 +01:00
|
|
|
{ getLogger },
|
2023-09-27 15:23:05 +02:00
|
|
|
eventService,
|
2023-02-16 08:08:51 +01:00
|
|
|
);
|
|
|
|
|
2023-11-24 14:22:31 +01:00
|
|
|
const accessService = new AccessService(
|
2023-08-08 13:45:19 +02:00
|
|
|
{ accessStore, accountStore, roleStore, environmentStore, groupStore },
|
2023-06-14 15:40:40 +02:00
|
|
|
{ getLogger, flagResolver },
|
2023-02-16 08:08:51 +01:00
|
|
|
groupService,
|
2023-11-24 14:22:31 +01:00
|
|
|
eventService,
|
2023-02-16 08:08:51 +01:00
|
|
|
);
|
2023-11-24 14:22:31 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
accessService,
|
|
|
|
eventStore,
|
|
|
|
};
|
2023-02-16 08:08:51 +01:00
|
|
|
};
|