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

Introduce Enroll API endpoint. #108835

Merged
merged 12 commits into from
Aug 19, 2021
Merged
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 {
/**
azasypkin marked this conversation as resolved.
Show resolved Hide resolved
* 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.';
}
Comment on lines +20 to +22
Copy link
Member Author

Choose a reason for hiding this comment

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

note: just like with minimum value for the session cleanup interval, we set minimum to 1 seconds to prevent our users from shooting themselves in the foot.

},
}),
}),
});
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