Skip to content

Commit

Permalink
add graph sample data (elastic#54558)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Jan 14, 2020
1 parent dec9c21 commit cf47312
Show file tree
Hide file tree
Showing 8 changed files with 2,573 additions and 4 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugins/graph/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const APP_ICON = 'graphApp';

export function createWorkspacePath(id: string) {
return `/app/graph/#/workspace/${id}`;
}
13 changes: 10 additions & 3 deletions x-pack/plugins/graph/server/lib/license_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
*/

import Boom from 'boom';
import { map } from 'rxjs/operators';
import { Observable, Subscription } from 'rxjs';
import { ILicense } from '../../../licensing/common/types';
import { checkLicense, GraphLicenseInformation } from '../../common/check_license';

export class LicenseState {
private licenseInformation: GraphLicenseInformation = checkLicense(undefined);
private subscription: Subscription | null = null;
private observable: Observable<GraphLicenseInformation> | null = null;

private updateInformation(license: ILicense | undefined) {
this.licenseInformation = checkLicense(license);
private updateInformation(licenseInformation: GraphLicenseInformation) {
this.licenseInformation = licenseInformation;
}

public start(license$: Observable<ILicense>) {
this.subscription = license$.subscribe(this.updateInformation.bind(this));
this.observable = license$.pipe(map(checkLicense));
this.subscription = this.observable.subscribe(this.updateInformation.bind(this));
}

public stop() {
Expand All @@ -30,6 +33,10 @@ export class LicenseState {
public getLicenseInformation() {
return this.licenseInformation;
}

public getLicenseInformation$() {
return this.observable;
}
}

export function verifyApiAccess(licenseState: LicenseState) {
Expand Down
11 changes: 10 additions & 1 deletion x-pack/plugins/graph/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ import { LicensingPluginSetup } from '../../licensing/server';
import { LicenseState } from './lib/license_state';
import { registerSearchRoute } from './routes/search';
import { registerExploreRoute } from './routes/explore';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
import { registerSampleData } from './sample_data';

export class GraphPlugin implements Plugin {
private licenseState: LicenseState | null = null;

public async setup(core: CoreSetup, { licensing }: { licensing: LicensingPluginSetup }) {
public async setup(
core: CoreSetup,
{ licensing, home }: { licensing: LicensingPluginSetup; home?: HomeServerPluginSetup }
) {
const licenseState = new LicenseState();
licenseState.start(licensing.license$);
this.licenseState = licenseState;

if (home) {
registerSampleData(home.sampleData, licenseState);
}

const router = core.http.createRouter();
registerSearchRoute({ licenseState, router });
registerExploreRoute({ licenseState, router });
Expand Down
Loading

0 comments on commit cf47312

Please sign in to comment.