Skip to content

Commit

Permalink
Introduce Enroll API endpoint. (#108835)
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin authored Aug 19, 2021
1 parent fe08d0a commit cb0ce59
Show file tree
Hide file tree
Showing 17 changed files with 1,650 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
* Describes current status of the Elasticsearch connection.
*/
export enum ElasticsearchConnectionStatus {
/**
* Indicates that Kibana hasn't figured out yet if existing Elasticsearch connection configuration is valid.
*/
Unknown = 'unknown',

/**
* Indicates that current Elasticsearch connection configuration valid and sufficient.
*/
Expand Down
43 changes: 43 additions & 0 deletions src/plugins/interactive_setup/server/config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { ConfigSchema } from './config';

describe('config schema', () => {
it('generates proper defaults', () => {
expect(ConfigSchema.validate({})).toMatchInlineSnapshot(`
Object {
"connectionCheck": Object {
"interval": "PT5S",
},
"enabled": false,
}
`);
});

describe('#connectionCheck', () => {
it('should properly set required connection check interval', () => {
expect(ConfigSchema.validate({ connectionCheck: { interval: '1s' } })).toMatchInlineSnapshot(`
Object {
"connectionCheck": Object {
"interval": "PT1S",
},
"enabled": false,
}
`);
});

it('should throw error if interactiveSetup.connectionCheck.interval is less than 1 second', () => {
expect(() =>
ConfigSchema.validate({ connectionCheck: { interval: 100 } })
).toThrowErrorMatchingInlineSnapshot(
`"[connectionCheck.interval]: the value must be greater or equal to 1 second."`
);
});
});
});
10 changes: 10 additions & 0 deletions src/plugins/interactive_setup/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@ export type ConfigType = TypeOf<typeof ConfigSchema>;

export const ConfigSchema = schema.object({
enabled: schema.boolean({ defaultValue: false }),
connectionCheck: schema.object({
interval: schema.duration({
defaultValue: '5s',
validate(value) {
if (value.asSeconds() < 1) {
return 'the value must be greater or equal to 1 second.';
}
},
}),
}),
});
20 changes: 20 additions & 0 deletions src/plugins/interactive_setup/server/elasticsearch_service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { BehaviorSubject } from 'rxjs';

import { ElasticsearchConnectionStatus } from '../common';

export const elasticsearchServiceMock = {
createSetup: () => ({
connectionStatus$: new BehaviorSubject<ElasticsearchConnectionStatus>(
ElasticsearchConnectionStatus.Configured
),
enroll: jest.fn(),
}),
};
Loading

0 comments on commit cb0ce59

Please sign in to comment.