Skip to content

Commit

Permalink
Adds custom saved object repository
Browse files Browse the repository at this point in the history
Signed-off-by: Bandini Bhopi <bandinib@amazon.com>
  • Loading branch information
bandinib-amzn committed Apr 17, 2023
1 parent 89213eb commit dac35f0
Show file tree
Hide file tree
Showing 3 changed files with 1,190 additions and 15 deletions.
20 changes: 5 additions & 15 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,47 +12,37 @@ import {
} from '../../../src/core/server';
import { MetadataPluginSetup, MetadataPluginStart } from './types';
import { defineRoutes } from './routes';
import { PostgresClientWrapper } from './saved_object_wrapper';
import { MetaStorageConfigType } from '.';
import { PostgresRepository, repositoryFactoryProvider } from './postgres_repository';

export class MetadataPlugin implements Plugin<MetadataPluginSetup, MetadataPluginStart> {
private readonly logger: Logger;
private savedObjectClientWrapper: PostgresClientWrapper;
private readonly config$;
private config: MetaStorageConfigType;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
this.savedObjectClientWrapper = new PostgresClientWrapper();
this.config$ = initializerContext.config.create<MetaStorageConfigType>();
}

public async setup(core: CoreSetup) {
this.logger.info('metadata-plugin: Setup');

this.config = await this.config$.pipe(first()).toPromise();
const config = await this.config$.pipe(first()).toPromise();

const router = core.http.createRouter();

// Register server side APIs
defineRoutes(router);

core.savedObjects.addClientWrapper(
0,
'postgres-saved-object-client-wrapper',
this.savedObjectClientWrapper.wrapperFactory
);
PostgresRepository.metaSrorageConfig = config;

core.savedObjects.registerRepositoryFactoryProvider(repositoryFactoryProvider);

return {};
}

public async start(core: CoreStart) {
this.logger.info('metadata-plugin: Started');

this.savedObjectClientWrapper.typeRegistry = core.savedObjects.getTypeRegistry();
console.log(`this.savedObjectClientWrapper.typeRegistry : ${this.savedObjectClientWrapper.typeRegistry}`);
this.savedObjectClientWrapper.metaSrorageConfig = this.config;
this.savedObjectClientWrapper.setup();
return {};
}

Expand Down
Loading

0 comments on commit dac35f0

Please sign in to comment.