-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Licensing plugin and XPackInfo uses the same license data #52507
Changes from 12 commits
3d4f707
b13aac8
4d25ee4
bf36ad3
2ec4399
9d14efb
170e600
cc82db6
c915f12
d2f5e03
354a152
889e459
2f88139
d3a899b
d1f9936
b8d4dbc
9b3e582
33c4b7c
ad130b4
211844e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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(); | ||
|
||
|
@@ -39,7 +41,7 @@ describe('setupXPackMain()', () => { | |
elasticsearch: mockElasticsearchPlugin, | ||
xpack_main: mockXPackMainPlugin | ||
}, | ||
newPlatform: { setup: { plugins: { features: {} } } }, | ||
newPlatform: { setup: { plugins: { features: {}, licensing: { license$: new BehaviorSubject() } } } }, | ||
Comment on lines
-42
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
events: { on() {} }, | ||
log() {}, | ||
config() {}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was removed in #51818 by mistake.
Xpack cannot detect license update without it. I also noticed that it doesn't work well with different fetching mechanism. Some plugins use NP
fetch
, some custom fetching mechanism, for examplehttps://github.com/restrry/kibana/blob/354a152caa94d856b8ffe1fa4df0981421c1e134/x-pack/legacy/plugins/canvas/common/lib/fetch.ts#L10
We need to talk to solution teams about unifying the network stack.
@elastic/kibana-platform
Should we create a separate issue to track?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want an issue, or should we 'just' add in our guidelines that the fetching mecanism in kibana should be
core.http
?Apollo can be hard to migrate though, as it's not 'only' a fetch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we need to solve several problems:
That could require adjusting interceptor API.