Skip to content

Commit

Permalink
Expose security license on setup (elastic#64651)
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego authored Apr 29, 2020
1 parent da4c33b commit f1d72ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 1 addition & 3 deletions x-pack/legacy/plugins/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export const security = (kibana: Record<string, any>) =>
// features are up to date.
xpackInfo
.feature(this.id)
.registerLicenseCheckResultsGenerator(() =>
securityPlugin.__legacyCompat.license.getFeatures()
);
.registerLicenseCheckResultsGenerator(() => securityPlugin.license.getFeatures());

server.expose({
getUser: async (request: LegacyRequest) =>
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/security/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { SecurityPluginSetup } from './plugin';

import { authenticationMock } from './authentication/index.mock';
import { authorizationMock } from './authorization/index.mock';
import { licenseMock } from '../common/licensing/index.mock';

function createSetupMock() {
const mockAuthz = authorizationMock.create();
Expand All @@ -19,6 +20,7 @@ function createSetupMock() {
mode: mockAuthz.mode,
},
registerSpacesService: jest.fn(),
license: licenseMock.create(),
__legacyCompat: {} as SecurityPluginSetup['__legacyCompat'],
};
}
Expand Down
30 changes: 15 additions & 15 deletions x-pack/plugins/security/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ describe('Security Plugin', () => {
await expect(plugin.setup(mockCoreSetup, mockDependencies)).resolves.toMatchInlineSnapshot(`
Object {
"__legacyCompat": Object {
"license": Object {
"features$": Observable {
"_isScalar": false,
"operator": MapOperator {
"project": [Function],
"thisArg": undefined,
},
"source": Observable {
"_isScalar": false,
"_subscribe": [Function],
},
},
"getFeatures": [Function],
"isEnabled": [Function],
},
"registerLegacyAPI": [Function],
"registerPrivilegesWithCluster": [Function],
},
Expand Down Expand Up @@ -103,6 +88,21 @@ describe('Security Plugin', () => {
"useRbacForRequest": [Function],
},
},
"license": Object {
"features$": Observable {
"_isScalar": false,
"operator": MapOperator {
"project": [Function],
"thisArg": undefined,
},
"source": Observable {
"_isScalar": false,
"_subscribe": [Function],
},
},
"getFeatures": [Function],
"isEnabled": [Function],
},
"registerSpacesService": [Function],
}
`);
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/security/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface SecurityPluginSetup {
| 'invalidateAPIKeyAsInternalUser'
>;
authz: Pick<Authorization, 'actions' | 'checkPrivilegesWithRequest' | 'mode'>;
license: SecurityLicense;

/**
* If Spaces plugin is available it's supposed to register its SpacesService with Security plugin
Expand All @@ -73,7 +74,6 @@ export interface SecurityPluginSetup {
__legacyCompat: {
registerLegacyAPI: (legacyAPI: LegacyAPI) => void;
registerPrivilegesWithCluster: () => void;
license: SecurityLicense;
};
}

Expand Down Expand Up @@ -194,6 +194,8 @@ export class Plugin {
mode: authz.mode,
},

license,

registerSpacesService: service => {
if (this.wasSpacesServiceAccessed()) {
throw new Error('Spaces service has been accessed before registration.');
Expand All @@ -206,8 +208,6 @@ export class Plugin {
registerLegacyAPI: (legacyAPI: LegacyAPI) => (this.legacyAPI = legacyAPI),

registerPrivilegesWithCluster: async () => await authz.registerPrivilegesWithCluster(),

license,
},
});
}
Expand Down

0 comments on commit f1d72ad

Please sign in to comment.