Skip to content
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

[Alerting] Secret Service #28894

Closed
wants to merge 195 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
256fda8
Begin SecretStore implementation.
njd5475 Dec 10, 2018
fb6bff6
Merge branch 'master' into alerting/needed-services
njd5475 Dec 11, 2018
ebc65e8
Starting to use the saved objects client.
njd5475 Dec 12, 2018
0687917
Adds ability to hide attributes inside saved objects.
njd5475 Dec 14, 2018
42e1cdd
The secret store plugin should be loaded.
njd5475 Dec 14, 2018
1969aa6
Merge branch 'master' into alerting/needed-services
njd5475 Dec 14, 2018
68314ce
A number of options to saved clients should be empty objects.
njd5475 Dec 17, 2018
4ba0fb7
Merge branch 'master' into alerting/needed-services
njd5475 Dec 17, 2018
70b0630
The plugin should expose the secret store.
njd5475 Dec 18, 2018
a853ba3
Merge branch 'master' into alerting/needed-services
njd5475 Dec 18, 2018
7d3163f
SecretStore should hide details in saved objects.
njd5475 Dec 19, 2018
8317c82
Saved Objects routes and service should be able to hide objects.
njd5475 Dec 20, 2018
41e15cc
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 9, 2019
eb54ceb
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 9, 2019
c7b2aa7
Adds keystore generation if none exists and inserts key.
njd5475 Jan 10, 2019
8f2b399
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 10, 2019
23d64df
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 11, 2019
1932993
Do not notify every startup unless its important.
njd5475 Jan 11, 2019
417fd9f
Fix savedobject type mappings for secrets SOs.
njd5475 Jan 14, 2019
128ad90
Merge branch 'alerting/masked-saved-objects' into alerting/needed-ser…
njd5475 Jan 14, 2019
baa34ec
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 14, 2019
bb839ae
Remove context providers as a feature.
njd5475 Jan 14, 2019
eda401e
Merge branch 'alerting/masked-saved-objects' into alerting/needed-ser…
njd5475 Jan 14, 2019
df909a9
SecretStore should use the appropriate repository.
njd5475 Jan 14, 2019
4f7312b
Respository should be creatable to include hidden types.
njd5475 Jan 14, 2019
4e64a7b
Merge branch 'alerting/masked-saved-objects' into alerting/needed-ser…
njd5475 Jan 14, 2019
ec22f45
Secret store saves and loads key from keystore.
njd5475 Jan 14, 2019
d11c05a
Saved Objects routes and service should be able to hide objects.
njd5475 Dec 20, 2018
f897f1c
Remove context providers as a feature.
njd5475 Jan 14, 2019
2c7b603
Respository should be creatable to include hidden types.
njd5475 Jan 14, 2019
680e3f1
Fixes failing unit tests.
njd5475 Jan 15, 2019
5bfb756
Fixes issues with filter method.
njd5475 Jan 15, 2019
5cd0ef3
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 15, 2019
a30f897
Adds check to get method for allowed types.
njd5475 Jan 17, 2019
fad7e9d
Adds tests for get,delete,bulkGet,find
njd5475 Jan 17, 2019
d31c589
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 17, 2019
94d1777
Remove need for schema in saved objects api.
njd5475 Jan 17, 2019
494aeb6
Remove more traces of schema validation added to rest api.
njd5475 Jan 17, 2019
dba327c
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 17, 2019
430f65e
Remove inclusion of hidden types in route specific client.
njd5475 Jan 17, 2019
e4a8b3e
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 17, 2019
6f9e0e6
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Jan 17, 2019
25de9ae
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Jan 17, 2019
698ff47
Repeat removal of getAvailableTypes.
njd5475 Jan 17, 2019
e531739
Simplifies secretstore to be basically a crypt method.
njd5475 Jan 17, 2019
11683d4
Removes getAvailableTypes as it is no longer used.
njd5475 Jan 17, 2019
c3f6a90
Fixing up initialization of components.
njd5475 Jan 17, 2019
a90e579
Moves default setting for includeHiddenTypes
njd5475 Jan 17, 2019
1b3e235
Allows for single value or array in assertAllowedTypes.
njd5475 Jan 17, 2019
3be7373
Adds type assertion to bulkCreate, and incrementCounter with tests.
njd5475 Jan 18, 2019
1d15b48
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Jan 18, 2019
7d9bdc8
Conversion to boolean should be more explicit.
njd5475 Jan 18, 2019
49315c7
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 18, 2019
9f0fd42
Revert "Simplifies secretstore to be basically a crypt method."
njd5475 Jan 18, 2019
39e80d6
Starts to combine create/update in saved objects creation.
njd5475 Jan 21, 2019
8ca9bb7
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 23, 2019
846bc3d
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 24, 2019
5877fb9
Repository should restrict types allowed to be manipulated.
njd5475 Jan 24, 2019
32f0203
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 28, 2019
d62b678
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 30, 2019
a638188
Saved objects should use the right root type.
njd5475 Jan 30, 2019
e54caee
All saved objects APIs should validate types.
njd5475 Jan 30, 2019
4fed095
No need for test to be typescript if under test not ts.
njd5475 Jan 31, 2019
4ff5c8b
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 31, 2019
6bd8f56
Handle extraTypes being undefined.
njd5475 Jan 31, 2019
726c2ab
Routes should verify that they do not allow invalid types.
njd5475 Jan 31, 2019
02bc63d
Bulk create should be tested.
njd5475 Jan 31, 2019
70d8ce8
Saved objects mixin does not need extra blank lines.
njd5475 Jan 31, 2019
349f1e2
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Jan 31, 2019
9b86952
Saved objects integration tests should test unknown types.
njd5475 Jan 31, 2019
f282b25
Integration tests should test for bad request with unknown type.
njd5475 Jan 31, 2019
c1ebef8
Adds missing privileges to global all.
njd5475 Jan 31, 2019
59e6d03
Tests should use valid types.
njd5475 Feb 1, 2019
acc006e
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 1, 2019
5dcb051
Fix bulkCreate to assert allowed types.
njd5475 Feb 1, 2019
ef931da
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 1, 2019
22da72d
Fix unknown search field tests.
njd5475 Feb 1, 2019
ce9357e
Adjust expectations for unknown type in saved object api.
njd5475 Feb 1, 2019
780e415
Saved object integration should return proper responses.
njd5475 Feb 1, 2019
f2f2887
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 1, 2019
5856a5a
Fix expect to use a separated matcher.
njd5475 Feb 1, 2019
3befab4
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 1, 2019
69b6b28
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 2, 2019
36d48f5
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 4, 2019
7861d2f
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 4, 2019
3ab122d
Should expect forbidden responses for unauthorized users.
njd5475 Feb 4, 2019
8e6908f
Should expect 400 when trying to use unknown types.
njd5475 Feb 4, 2019
3bed5c8
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Feb 4, 2019
57f9628
Secret service does not use create then update.
njd5475 Feb 4, 2019
c0b2971
Adds types for object-hash package.
njd5475 Feb 4, 2019
a427cb7
Adds keystore mixin for usage in plugins.
njd5475 Feb 4, 2019
e909579
Secret service should use keystore mixin.
njd5475 Feb 4, 2019
ecfb8c0
Removes unwanted .only call.
njd5475 Feb 5, 2019
d986da3
Adjust repository to throw error unless it has allowed types.
njd5475 Feb 5, 2019
0c95fcc
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 6, 2019
2c2212e
Unknown types should return 403s and empty results where applicable
njd5475 Feb 6, 2019
96da1c9
Removes type validation from saved object API.
njd5475 Feb 6, 2019
68f8673
Captures and returns appropriate exceptions for type assertion.
njd5475 Feb 6, 2019
5d124ad
Properly filtter c'tor params to repository.
njd5475 Feb 6, 2019
c8cbd31
Checking allowed type should be bool check function.
njd5475 Feb 7, 2019
6183622
Cleanup test situation descriptions.
njd5475 Feb 7, 2019
9afd2be
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Feb 7, 2019
6d79462
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 7, 2019
a742044
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 7, 2019
f131b05
Updating snapshot file for jest tests.
njd5475 Feb 7, 2019
df6f979
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Feb 7, 2019
c71ead4
Renames the secretstore to secret_service moving files.
njd5475 Feb 7, 2019
ce64482
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 7, 2019
1febac6
Renames SecretStore to SecretService.
njd5475 Feb 7, 2019
b477eab
Starts adding audit logging to Secret Service.
njd5475 Feb 8, 2019
47b4173
Changes expected results for find from saved object service.
njd5475 Feb 8, 2019
3e6d7c8
Expect an empty response when attempting to access an unsupported type.
njd5475 Feb 8, 2019
9aa914f
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 8, 2019
bcc3a2f
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Feb 8, 2019
7f1a9d0
Fix issues with config key name.
njd5475 Feb 8, 2019
ac2e47e
Adds test coverage for new error methods added.
njd5475 Feb 8, 2019
9e1e2e4
Adds bulkGet, bulkCreate unsupported type errors.
njd5475 Feb 8, 2019
9a90a60
First step in refactoring saved object service.
njd5475 Feb 11, 2019
68d62cb
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 11, 2019
7d8311a
Move extra saved objects test to legacy folder.
njd5475 Feb 11, 2019
92b07d4
Adds references filtering by allowed type.
njd5475 Feb 12, 2019
aca559b
Adds more coverage for mixin repository creation.
njd5475 Feb 12, 2019
0054bfb
Removes unnecessary decorate on server object for unused method.
njd5475 Feb 12, 2019
e7c60df
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 12, 2019
6d38575
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 12, 2019
3eb98fc
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 13, 2019
35c883b
Revert reworking how kibana migrator uses mappings.
njd5475 Feb 13, 2019
dee6e7c
Revert "Adds references filtering by allowed type."
njd5475 Feb 13, 2019
88215cf
Adds check for unexpected callCluster type.
njd5475 Feb 13, 2019
bc66231
Should cover as many parts of the mixin as possible.
njd5475 Feb 13, 2019
d74479d
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 13, 2019
e54596c
More expectations to tests.
njd5475 Feb 13, 2019
287004f
Keeps ordering of created items but does not pass unsupported types.
njd5475 Feb 13, 2019
128aa88
Fix a failing before hook test.
njd5475 Feb 14, 2019
a4fa204
Merge remote-tracking branch 'upstream/master' into alerting/add-hidd…
njd5475 Feb 14, 2019
2ae5ace
Merge branch 'alerting/add-hidden-types-to-savedobjects' into alertin…
njd5475 Feb 14, 2019
2597af2
Moving keystore mixin to new area.
njd5475 Feb 14, 2019
1c09cb4
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 14, 2019
ba0c33f
Fix error with moved scripts.
njd5475 Feb 14, 2019
26f46ac
Fix missing expectation.
njd5475 Feb 14, 2019
42b6b80
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 20, 2019
8956c7d
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 21, 2019
fd7ec07
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 22, 2019
95113cb
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 25, 2019
042cd26
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 26, 2019
9fcd6c8
Only need object-hash in x-pack not all of kibana.
njd5475 Feb 26, 2019
ed94270
Fixes restricting saved objects api repository.
njd5475 Feb 27, 2019
d0d77de
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 27, 2019
0f059d7
Adds tests for get method on keystore.
njd5475 Feb 27, 2019
a765571
Uses @elastic/node-crytpo instead of own implementaiton.
njd5475 Feb 27, 2019
9cff873
Partial validation of encryption key.
njd5475 Feb 28, 2019
c29ea09
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Feb 28, 2019
8327938
Adds key validation via, saving a doc in the kibana index.
njd5475 Mar 1, 2019
8b23d91
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 1, 2019
b6a9b7a
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 6, 2019
aa0c863
Fixes tests and adds key validation.
njd5475 Mar 6, 2019
e2c24e5
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 6, 2019
e5696aa
Secret service should be red if unable to validate key.
njd5475 Mar 6, 2019
6eefd5e
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 6, 2019
712ba8e
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 6, 2019
c49dc27
Should use absolute project paths for imports.
njd5475 Mar 7, 2019
633e1fb
Updates to yarn lock file.
njd5475 Mar 7, 2019
b1b57ba
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 8, 2019
c49ec5f
Remove unnecessary falsy check.
njd5475 Mar 8, 2019
7f5ed81
Updates to yarn lock are not supposed to be funky.
njd5475 Mar 8, 2019
3d8a5d9
Adds unit tests for validateKey.
njd5475 Mar 8, 2019
0442daa
Bring types/mocha in sync between kibana and xpack.
njd5475 Mar 8, 2019
50a8d72
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 9, 2019
d97c4e9
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 11, 2019
c36dc33
Types mocha should be the same in dev dependencies.
njd5475 Mar 11, 2019
af82e74
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 11, 2019
70ffcbd
Removes dependence on server ready before migratoins.
njd5475 Mar 12, 2019
5c9e1d0
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 12, 2019
6829bf0
No longer expecting ready to be called.
njd5475 Mar 12, 2019
3f267d9
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 12, 2019
b15f935
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 13, 2019
aefde7a
Remove unneeded interface defined ready function.
njd5475 Mar 13, 2019
77ddb00
No need to test add method twice.
njd5475 Mar 13, 2019
3ebae23
Support keystore changes.
njd5475 Mar 13, 2019
a944c56
Ensure keystore is loaded correctly.
njd5475 Mar 14, 2019
401bbb4
Test messages should be consistent with their expectations.
njd5475 Mar 14, 2019
b42a9ed
Export the SavedObjectsRepository type.
njd5475 Mar 14, 2019
035ef81
Messaging should include specific key used for encryption.
njd5475 Mar 14, 2019
b864f58
Remove public dir definition in plugin definition.
njd5475 Mar 19, 2019
088e035
Temporarily remove audit logging.
njd5475 Mar 21, 2019
d750223
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 25, 2019
1d19557
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 25, 2019
9b61aff
Adds support for building separate providers to saved objects.
njd5475 Mar 26, 2019
51aaa9c
Start to change the interface to align with proposal.
njd5475 Mar 26, 2019
8e69307
Adds client wrapper factory and client.
njd5475 Mar 27, 2019
d94554a
Merge remote-tracking branch 'upstream/master' into alerting/needed-s…
njd5475 Mar 27, 2019
a747a09
Adds valid wrapper factory and client wrapper.
njd5475 Mar 27, 2019
00d6a44
Revert "Uses @elastic/node-crytpo instead of own implementaiton."
njd5475 Mar 27, 2019
93e2300
Fixes unit tests with crypt keeper.
njd5475 Mar 27, 2019
40b71c7
Revert "Adds support for building separate providers to saved objects."
njd5475 Mar 27, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/legacy/server/kbn_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { serverExtensionsMixin } from './server_extensions';
import { uiMixin } from '../ui';
import { sassMixin } from './sass';
import { i18nMixin } from './i18n';
import { keystoreMixin } from './keystore';

const rootDir = fromRoot('.');

Expand Down Expand Up @@ -101,6 +102,9 @@ export default class KbnServer {
// tell the config we are done loading plugins
configCompleteMixin,

// once the main config is loaded add the keystore
keystoreMixin,

// setup this.uiExports and this.uiBundles
uiMixin,
indexPatternsMixin,
Expand Down
1 change: 1 addition & 0 deletions src/legacy/server/keystore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export { Keystore } from './keystore';
export { keystoreMixin } from './keystore_mixin';
4 changes: 4 additions & 0 deletions src/legacy/server/keystore/keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export class Keystore {
return this.keys().indexOf(key) > -1;
}

get(key) {
njd5475 marked this conversation as resolved.
Show resolved Hide resolved
return this.data[key];
}

add(key, value) {
this.data[key] = value;
}
Expand Down
13 changes: 13 additions & 0 deletions src/legacy/server/keystore/keystore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ describe('Keystore', () => {
});
});

describe('get', () => {
it('gets a value by key', () => {
const keystore = new Keystore('/data/unprotected.keystore');
expect(keystore.get('a2')).toEqual('bar');
});

it('gets a value that has been added', () => {
const keystore = new Keystore('/data/unprotected.keystore');
keystore.add('foo', 'baz');
expect(keystore.get('foo')).toEqual('baz');
});
});

describe('add', () => {
it('adds a key/value pair', () => {
const keystore = new Keystore('/data/unprotected.keystore');
Expand Down
26 changes: 26 additions & 0 deletions src/legacy/server/keystore/keystore_mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Keystore } from './keystore';
import { join } from 'path';

export function keystoreMixin(_, server) {
const keystorePath = join(server.config().get('path.data'), 'kibana.keystore');
server.decorate('server', 'keystore', new Keystore(keystorePath));
}
1 change: 1 addition & 0 deletions src/legacy/server/saved_objects/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export {
SavedObjectsClient,
SavedObjectsClientWrapperFactory,
SavedObjectReference,
SavedObjectsRepository,
SavedObjectsService,
} from './service';
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('KibanaMigrator', () => {
expect(result).toEqual({ status: 'skipped' });
});

it('waits for kbnServer.ready and elasticsearch.ready before attempting migrations', async () => {
it('waits for elasticsearch.ready before attempting migrations', async () => {
const { kbnServer } = mockKbnServer();
const clusterStub = jest.fn<any, any>(() => {
throw new Error('Doh!');
Expand All @@ -74,7 +74,6 @@ describe('KibanaMigrator', () => {
kbnServer.server.plugins.elasticsearch = {
waitUntilReady,
getCluster() {
expect(kbnServer.ready as any).toHaveBeenCalledTimes(1);
expect(waitUntilReady).toHaveBeenCalledTimes(1);

return {
Expand All @@ -92,7 +91,6 @@ function mockKbnServer({ configValues }: { configValues?: any } = {}) {
const callCluster = jest.fn();
const kbnServer: KbnServer = {
version: '8.2.3',
ready: jest.fn(async () => undefined),
uiExports: {
savedObjectValidations: {},
savedObjectMigrations: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { DocumentMigrator, VersionedTransformer } from '../core/document_migrato
export interface KbnServer {
server: Server;
version: string;
ready: () => Promise<any>;
uiExports: {
savedObjectMappings: any[];
savedObjectMigrations: any;
Expand Down Expand Up @@ -75,9 +74,6 @@ export class KibanaMigrator {
public awaitMigration = once(async () => {
const { server } = this.kbnServer;

// Wait until the plugins have been found an initialized...
await this.kbnServer.ready();
njd5475 marked this conversation as resolved.
Show resolved Hide resolved

// We can't do anything if the elasticsearch plugin has been disabled.
if (!server.plugins.elasticsearch) {
server.log(
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/saved_objects/service/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface SavedObjectsService<Request = any> {
getSavedObjectsRepository(...rest: any[]): any;
}

export { SavedObjectsClientWrapperFactory } from './lib';
export { SavedObjectsClientWrapperFactory, SavedObjectsRepository } from './lib';
export {
FindOptions,
GetResponse,
Expand Down
58 changes: 54 additions & 4 deletions src/legacy/server/saved_objects/service/lib/repository.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@
* under the License.
*/

import { BaseOptions, SavedObject } from '../saved_objects_client';
import {
BaseOptions,
BulkCreateObject,
BulkCreateResponse,
BulkGetObjects,
BulkGetResponse,
CreateOptions,
CreateResponse,
FindOptions,
FindResponse,
GetResponse,
SavedObject,
SavedObjectAttributes,
UpdateOptions,
UpdateResponse,
} from '../saved_objects_client';
import * as errors from './errors';

export interface SavedObjectsRepositoryOptions {
index: string | string[];
Expand All @@ -30,9 +46,8 @@ export interface SavedObjectsRepositoryOptions {
}

export declare class SavedObjectsRepository {
// ATTENTION: this interface is incomplete

public get: (type: string, id: string, options?: BaseOptions) => Promise<SavedObject>;
public static errors: typeof errors;
public errors: typeof errors;
public incrementCounter: (
type: string,
id: string,
Expand All @@ -41,4 +56,39 @@ export declare class SavedObjectsRepository {
) => Promise<SavedObject>;

constructor(options: SavedObjectsRepositoryOptions);

public create<T extends SavedObjectAttributes = any>(
type: string,
attributes: T,
options?: CreateOptions
): Promise<CreateResponse<T>>;

public bulkCreate<T extends SavedObjectAttributes = any>(
objects: Array<BulkCreateObject<T>>,
options?: CreateOptions
): Promise<BulkCreateResponse<T>>;

public delete(type: string, id: string, options?: BaseOptions): Promise<{}>;

public find<T extends SavedObjectAttributes = any>(
options: FindOptions
): Promise<FindResponse<T>>;

public bulkGet<T extends SavedObjectAttributes = any>(
objects: BulkGetObjects,
options?: BaseOptions
): Promise<BulkGetResponse<T>>;

public get<T extends SavedObjectAttributes = any>(
type: string,
id: string,
options?: BaseOptions
): Promise<GetResponse<T>>;

public update<T extends SavedObjectAttributes = any>(
type: string,
id: string,
attributes: Partial<T>,
options?: UpdateOptions
): Promise<UpdateResponse<T>>;
}
1 change: 1 addition & 0 deletions src/legacy/server/saved_objects/service/lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class SavedObjectsRepository {
//
// The migrator performs double-duty, and validates the documents prior
// to returning them.
this.errors = errors;
this._migrator = migrator;
this._index = index;
this._mappings = mappings;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { crossClusterReplication } from './plugins/cross_cluster_replication';
import { translations } from './plugins/translations';
import { upgradeAssistant } from './plugins/upgrade_assistant';
import { uptime } from './plugins/uptime';
import { secretService } from './plugins/secret_service';
import { ossTelemetry } from './plugins/oss_telemetry';

module.exports = function (kibana) {
Expand Down Expand Up @@ -72,6 +73,7 @@ module.exports = function (kibana) {
translations(kibana),
upgradeAssistant(kibana),
uptime(kibana),
secretService(kibana),
ossTelemetry(kibana),
];
};
2 changes: 2 additions & 0 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@types/jsonwebtoken": "^7.2.7",
"@types/lodash": "^3.10.1",
"@types/mocha": "^5.2.6",
"@types/object-hash": "^1.2.0",
"@types/pngjs": "^3.3.1",
"@types/prop-types": "^15.5.3",
"@types/react": "^16.8.0",
Expand Down Expand Up @@ -226,6 +227,7 @@
"ngreact": "^0.5.1",
"node-fetch": "^2.1.2",
"nodemailer": "^4.6.4",
"object-hash": "^1.3.1",
"object-path-immutable": "^0.5.3",
"oppsy": "^2.0.0",
"papaparse": "^4.6.0",
Expand Down
85 changes: 85 additions & 0 deletions x-pack/plugins/secret_service/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 { secretService } from './';
import { PluginSpec } from './mocks';

describe('The SecretService', function TestSecretService() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what is the benefit of having "named" TestSecretService function here comparing to arrow functions you use for beforeAll/it?

const mockKbn = {
Plugin: PluginSpec,
};
const subject = secretService(mockKbn);
beforeAll(() => {
expect(subject).not.toBeNull();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: hmm, you have a dedicated test exactly for this, maybe we can remove this expect from here?

mockKbn.Plugin = jest.fn();
});

it('should expose itself to other plugins', () => {
expect(subject).not.toBeNull();
});

it('should expose a method to encrypt data', async () => {
const stubConfigGet = jest.fn();
const stubKeystore = {
has: jest.fn(),
get: jest.fn(),
add: jest.fn(),
exists: jest.fn(),
save: jest.fn(),
};
let secret: string;
const core = {
expose: jest.fn(),
log: jest.fn(),
logWithMetadata: jest.fn(),
savedObjects: {
addScopedSavedObjectsClientWrapperFactory: jest.fn(),
getSavedObjectsRepository: jest.fn(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: if the logic inside of the mock implementation doesn't depend on arguments and there is no requirement to return new value on every call, I'd say jest.fn().mockReturnValue would make intention clearer.

return {
errors: {
isConflictError: jest.fn(),
},
create: jest.fn((type, attributes, { id }) => {
secret = attributes.secret;
return {
id,
type,
attributes,
};
}),
get: jest.fn((type, id) => {
return {
id,
type,
attributes: {
secret,
},
};
}),
};
}),
},
config: () => {
return {
get: stubConfigGet,
};
},
keystore: stubKeystore,
plugins: {
elasticsearch: {
getCluster: () => {
return { callWithInternalUser: jest.fn() };
},
},
},
};

stubKeystore.get.mockReturnValue('bogusencrpyptionley');
stubConfigGet.mockReturnValueOnce(false);
await subject.init(core);
expect(core.expose).toHaveBeenCalledWith('secretService', expect.any(Object));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: expect.any(SecretService)?

question: can we also test key auto-generation flow?

});
});
Loading