Skip to content

Commit

Permalink
Address feedback from Pierre
Browse files Browse the repository at this point in the history
- Remove unnecessary ServerConfigType
- Remove unnecessary uiCapabilities
- Move registerTelemetryRoute / SavedObjectsServiceStart workaround
- Remove unnecessary license optional chaining
  • Loading branch information
cee-chen committed Jul 8, 2020
1 parent 15a8b15 commit 9c6acdd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 42 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/enterprise_search/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const configSchema = schema.object({
accessCheckTimeoutWarning: schema.number({ defaultValue: 300 }),
});

type ConfigType = TypeOf<typeof configSchema>;
export type ConfigType = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<ConfigType> = {
schema: configSchema,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/enterprise_search/server/lib/check_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import { KibanaRequest, Logger } from 'src/core/server';
import { SecurityPluginSetup } from '../../../security/server';
import { ServerConfigType } from '../plugin';
import { ConfigType } from '../';

import { callEnterpriseSearchConfigAPI } from './enterprise_search_config_api';

interface ICheckAccess {
request: KibanaRequest;
security?: SecurityPluginSetup;
config: ServerConfigType;
config: ConfigType;
log: Logger;
}
export interface IAccess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import AbortController from 'abort-controller';
import fetch from 'node-fetch';

import { KibanaRequest, Logger } from 'src/core/server';
import { ServerConfigType } from '../plugin';
import { ConfigType } from '../';
import { IAccess } from './check_access';

interface IParams {
request: KibanaRequest;
config: ServerConfigType;
config: ConfigType;
log: Logger;
}
interface IReturn {
Expand Down
62 changes: 25 additions & 37 deletions x-pack/plugins/enterprise_search/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
KibanaRequest,
} from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { UICapabilities } from 'ui/capabilities';
import { SecurityPluginSetup } from '../../security/server';
import { PluginSetupContract as FeaturesPluginSetup } from '../../features/server';

import { ConfigType } from './';
import { checkAccess } from './lib/check_access';
import { registerPublicUrlRoute } from './routes/enterprise_search/public_url';
import { registerEnginesRoute } from './routes/app_search/engines';
Expand All @@ -33,26 +33,19 @@ export interface PluginsSetup {
features: FeaturesPluginSetup;
}

export interface ServerConfigType {
host?: string;
enabled: boolean;
accessCheckTimeout: number;
accessCheckTimeoutWarning: number;
}

export interface IRouteDependencies {
router: IRouter;
config: ServerConfigType;
config: ConfigType;
log: Logger;
getSavedObjectsService?(): SavedObjectsServiceStart;
}

export class EnterpriseSearchPlugin implements Plugin {
private config: Observable<ServerConfigType>;
private config: Observable<ConfigType>;
private logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.config = initializerContext.config.create<ServerConfigType>();
this.config = initializerContext.config.create<ConfigType>();
this.logger = initializerContext.logger.get();
}

Expand All @@ -79,26 +72,21 @@ export class EnterpriseSearchPlugin implements Plugin {
/**
* Register user access to the Enterprise Search plugins
*/
capabilities.registerSwitcher(
async (request: KibanaRequest, uiCapabilities: UICapabilities) => {
const dependencies = { config, security, request, log: this.logger };

const { hasAppSearchAccess } = await checkAccess(dependencies);
// TODO: hasWorkplaceSearchAccess

return {
...uiCapabilities,
navLinks: {
...uiCapabilities.navLinks,
appSearch: hasAppSearchAccess,
},
catalogue: {
...uiCapabilities.catalogue,
appSearch: hasAppSearchAccess,
},
};
}
);
capabilities.registerSwitcher(async (request: KibanaRequest) => {
const dependencies = { config, security, request, log: this.logger };

const { hasAppSearchAccess } = await checkAccess(dependencies);
// TODO: hasWorkplaceSearchAccess

return {
navLinks: {
appSearch: hasAppSearchAccess,
},
catalogue: {
appSearch: hasAppSearchAccess,
},
};
});

/**
* Register routes
Expand All @@ -113,18 +101,18 @@ export class EnterpriseSearchPlugin implements Plugin {
* Bootstrap the routes, saved objects, and collector for telemetry
*/
savedObjects.registerType(appSearchTelemetryType);
let savedObjectsStarted: SavedObjectsServiceStart;

getStartServices().then(([coreStart]) => {
const savedObjectsStarted = coreStart.savedObjects as SavedObjectsServiceStart;

registerTelemetryRoute({
...dependencies,
getSavedObjectsService: () => savedObjectsStarted,
});
savedObjectsStarted = coreStart.savedObjects;
if (usageCollection) {
registerTelemetryUsageCollector(usageCollection, savedObjectsStarted, this.logger);
}
});
registerTelemetryRoute({
...dependencies,
getSavedObjectsService: () => savedObjectsStarted,
});
}

public start() {}
Expand Down

0 comments on commit 9c6acdd

Please sign in to comment.