-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RBAC Phase 1] - Update application privileges when XPack license cha…
…nges (#19839) * Adding start to supporting basic license and switching to plat/gold * Initialize application privilages on XPack license change * restore mirror_status_and_initialize * additional tests and peer review updates * Introducing watchStatusAndLicenseToInitialize * Adding some tests * One more test * Even better tests * Removing unused mirrorStatusAndInitialize * Throwing an error if the wrong status function is called
- Loading branch information
Showing
8 changed files
with
429 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
x-pack/plugins/security/server/lib/mirror_status_and_initialize.js
This file was deleted.
Oops, something went wrong.
138 changes: 0 additions & 138 deletions
138
x-pack/plugins/security/server/lib/mirror_status_and_initialize.test.js
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/security/server/lib/watch_status_and_license_to_initialize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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 { Observable } from 'rxjs'; | ||
|
||
export function watchStatusAndLicenseToInitialize(xpackMainPlugin, downstreamPlugin, initialize) { | ||
const xpackInfo = xpackMainPlugin.info; | ||
const xpackInfoFeature = xpackInfo.feature(downstreamPlugin.id); | ||
|
||
const upstreamStatus = xpackMainPlugin.status; | ||
const currentStatus$ = Observable | ||
.of({ | ||
state: upstreamStatus.state, | ||
message: upstreamStatus.message, | ||
}); | ||
const newStatus$ = Observable | ||
.fromEvent(upstreamStatus, 'change', null, (previousState, previousMsg, state, message) => { | ||
return { | ||
state, | ||
message, | ||
}; | ||
}); | ||
const status$ = Observable.merge(currentStatus$, newStatus$); | ||
|
||
const currentLicense$ = Observable | ||
.of(xpackInfoFeature.getLicenseCheckResults()); | ||
const newLicense$ = Observable | ||
.fromEventPattern(xpackInfoFeature.registerLicenseChangeCallback) | ||
.map(() => xpackInfoFeature.getLicenseCheckResults()); | ||
const license$ = Observable.merge(currentLicense$, newLicense$); | ||
|
||
Observable.combineLatest(status$, license$) | ||
.map(([status, license]) => ({ status, license })) | ||
.switchMap(({ status, license }) => { | ||
if (status.state !== 'green') { | ||
return Observable.of({ state: status.state, message: status.message }); | ||
} | ||
|
||
return initialize(license) | ||
.then(() => ({ | ||
state: 'green', | ||
message: 'Ready', | ||
})) | ||
.catch((err) => ({ | ||
state: 'red', | ||
message: err.message | ||
})); | ||
}) | ||
.do(({ state, message }) => { | ||
downstreamPlugin.status[state](message); | ||
}) | ||
.subscribe(); | ||
} |
Oops, something went wrong.