Skip to content

Commit

Permalink
Revert "Revert "Fix wrong impor (#52994)""
Browse files Browse the repository at this point in the history
This reverts commit c220d77.
  • Loading branch information
spalger committed Dec 13, 2019
1 parent c220d77 commit 1ea9d79
Show file tree
Hide file tree
Showing 40 changed files with 719 additions and 770 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ module.exports = {
'Server modules cannot be imported into client modules or shared modules.',
},
{
target: ['src/core/**/*'],
target: ['src/**/*'],
from: ['x-pack/**/*'],
errorMessage: 'OSS cannot import x-pack files.',
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/legacy/common/poller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export declare class Poller {
constructor(options: any);

public start(): void;
public stop(): void;
public isRunning(): boolean;
public getPollFrequency(): number;
}
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/graph/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_regis
import { npSetup, npStart } from 'ui/new_platform';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { start as navigation } from '../../../../../src/legacy/core_plugins/navigation/public/legacy';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { GraphPlugin } from './plugin';

// @ts-ignore
Expand All @@ -39,13 +40,17 @@ async function getAngularInjectedDependencies(): Promise<LegacyAngularInjectedDe
};
}

type XpackNpSetupDeps = typeof npSetup.plugins & {
licensing: LicensingPluginSetup;
};

(async () => {
const instance = new GraphPlugin();
instance.setup(npSetup.core, {
__LEGACY: {
Storage,
},
...npSetup.plugins,
...(npSetup.plugins as XpackNpSetupDeps),
});
instance.start(npStart.core, {
npData: npStart.plugins.data,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/graph/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CoreSetup, CoreStart, Plugin, SavedObjectsClientContract } from 'src/co
import { Plugin as DataPlugin } from 'src/plugins/data/public';
import { LegacyAngularInjectedDependencies } from './render_app';
import { NavigationStart } from '../../../../../src/legacy/core_plugins/navigation/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/common/types';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';

export interface GraphPluginStartDependencies {
npData: ReturnType<DataPlugin['start']>;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/graph/public/render_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
IndexPatternsContract,
} from '../../../../../src/plugins/data/public';
import { NavigationStart } from '../../../../../src/legacy/core_plugins/navigation/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/common/types';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';
import { checkLicense } from '../../../../plugins/graph/common/check_license';

/**
Expand Down
7 changes: 3 additions & 4 deletions x-pack/legacy/plugins/xpack_main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import { resolve } from 'path';
import dedent from 'dedent';
import {
XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS
} from '../../server/lib/constants';
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
import { replaceInjectedVars } from './server/lib/replace_injected_vars';
import { setupXPackMain } from './server/lib/setup_xpack_main';
Expand All @@ -34,7 +31,6 @@ export const xpackMain = (kibana) => {
enabled: Joi.boolean().default(),
url: Joi.string().default(),
}).default(), // deprecated
xpack_api_polling_frequency_millis: Joi.number().default(XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS),
}).default();
},

Expand All @@ -47,6 +43,9 @@ export const xpackMain = (kibana) => {
},

uiExports: {
hacks: [
'plugins/xpack_main/hacks/check_xpack_info_change',
],
replaceInjectedVars,
injectDefaultVars(server) {
const config = server.config();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.
*/

import { identity } from 'lodash';
import { uiModules } from 'ui/modules';
import { Path } from 'plugins/xpack_main/services/path';
import { xpackInfo } from 'plugins/xpack_main/services/xpack_info';
import { xpackInfoSignature } from 'plugins/xpack_main/services/xpack_info_signature';

const module = uiModules.get('xpack_main', []);

module.factory('checkXPackInfoChange', ($q, Private, $injector) => {
/**
* Intercept each network response to look for the kbn-xpack-sig header.
* When that header is detected, compare its value with the value cached
* in the browser storage. When the value is new, call `xpackInfo.refresh()`
* so that it will pull down the latest x-pack info
*
* @param {object} response - the angular $http response object
* @param {function} handleResponse - callback, expects to receive the response
* @return
*/
function interceptor(response, handleResponse) {
if (Path.isUnauthenticated()) {
return handleResponse(response);
}

const currentSignature = response.headers('kbn-xpack-sig');
const cachedSignature = xpackInfoSignature.get();

if (currentSignature && cachedSignature !== currentSignature) {
// Signature from the server differ from the signature of our
// cached info, so we need to refresh it.
// Intentionally swallowing this error
// because nothing catches it and it's an ugly console error.
xpackInfo.refresh($injector).catch(() => {});
}

return handleResponse(response);
}

return {
response: (response) => interceptor(response, identity),
responseError: (response) => interceptor(response, $q.reject)
};
});

module.config(($httpProvider) => {
$httpProvider.interceptors.push('checkXPackInfoChange');
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { BehaviorSubject } from 'rxjs';
import sinon from 'sinon';
import { XPackInfo } from '../xpack_info';
import { setupXPackMain } from '../setup_xpack_main';
import * as InjectXPackInfoSignatureNS from '../inject_xpack_info_signature';


describe('setupXPackMain()', () => {
const sandbox = sinon.createSandbox();

Expand Down Expand Up @@ -39,17 +41,16 @@ describe('setupXPackMain()', () => {
elasticsearch: mockElasticsearchPlugin,
xpack_main: mockXPackMainPlugin
},
newPlatform: { setup: { plugins: { features: {} } } },
newPlatform: { setup: { plugins: { features: {}, licensing: { license$: new BehaviorSubject() } } } },
events: { on() {} },
log() {},
config() {},
expose() {},
ext() {}
});

// Make sure we don't misspell config key.
// Make sure plugins doesn't consume config
const configGetStub = sinon.stub().throws(new Error('`config.get` is called with unexpected key.'));
configGetStub.withArgs('xpack.xpack_main.xpack_api_polling_frequency_millis').returns(1234);
mockServer.config.returns({ get: configGetStub });
});

Expand Down
Loading

0 comments on commit 1ea9d79

Please sign in to comment.