Skip to content

Commit

Permalink
[Ingest Manager] Replace OutputType enum with separate type and runti…
Browse files Browse the repository at this point in the history
…me object (#82230)

## Summary

Expands on pattern added in #82188

### rutime value is now `outputType.Elasticsearch` (lowercase b/c JS value)

```diff
-  type: OutputType.Elasticsearch,
+  type: outputType.Elasticsearch,
```

<img width="821" alt="Screen Shot 2020-11-02 at 4 46 24 PM" src="https://user-images.githubusercontent.com/57655/97923244-ae4ccc80-1d2b-11eb-9cc9-d98636ca9a40.png">
<img width="594" alt="Screen Shot 2020-11-02 at 4 46 35 PM" src="https://user-images.githubusercontent.com/57655/97923245-aee56300-1d2b-11eb-917e-483a68280e8e.png">
<img width="429" alt="Screen Shot 2020-11-02 at 4 46 47 PM" src="https://user-images.githubusercontent.com/57655/97923246-aee56300-1d2b-11eb-964a-37b496211167.png">

### TS type is `OutputType`
#### Can get union type of values with `ValueOf<OutputType>`
<img width="455" alt="Screen Shot 2020-11-02 at 4 47 31 PM" src="https://user-images.githubusercontent.com/57655/97923247-aee56300-1d2b-11eb-8492-40a9367ad90e.png">

#### Or access as `OutputType['Elasticsearch']`
  • Loading branch information
John Schulz authored Nov 3, 2020
1 parent ffc4ba2 commit e916a1d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
10 changes: 7 additions & 3 deletions x-pack/plugins/ingest_manager/common/constants/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { OutputType } from '../types';
import { NewOutput } from '../types';

export const OUTPUT_SAVED_OBJECT_TYPE = 'ingest-outputs';

export const DEFAULT_OUTPUT = {
export const outputType = {
Elasticsearch: 'elasticsearch',
} as const;

export const DEFAULT_OUTPUT: NewOutput = {
name: 'default',
is_default: true,
type: OutputType.Elasticsearch,
type: outputType.Elasticsearch,
hosts: [''],
};
9 changes: 5 additions & 4 deletions x-pack/plugins/ingest_manager/common/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

export enum OutputType {
Elasticsearch = 'elasticsearch',
}
import { outputType } from '../../constants';
import type { ValueOf } from '../index';

export type OutputType = typeof outputType;

export interface NewOutput {
is_default: boolean;
name: string;
type: OutputType;
type: ValueOf<OutputType>;
hosts?: string[];
ca_sha256?: string;
api_key?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
createNewActionsSharedObservable,
} from './state_new_actions';
import { getNewActionsSince } from '../actions';
import { OutputType, Agent, AgentAction, AgentPolicyAction } from '../../../types';
import { Agent, AgentAction, AgentPolicyAction } from '../../../types';
import { outputType } from '../../../../common/constants';

jest.mock('../../app_context', () => ({
appContextService: {
Expand Down Expand Up @@ -128,7 +129,7 @@ describe('test agent checkin new action services', () => {
id: 'policy1',
outputs: {
default: {
type: OutputType.Elasticsearch,
type: outputType.Elasticsearch,
hosts: [],
ca_sha256: undefined,
api_key: undefined,
Expand Down
7 changes: 2 additions & 5 deletions x-pack/plugins/ingest_manager/server/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { schema } from '@kbn/config-schema';

export enum OutputType {
Elasticsearch = 'elasticsearch',
}
import { outputType } from '../../../common/constants';

const OutputBaseSchema = {
name: schema.string(),
type: schema.oneOf([schema.literal(OutputType.Elasticsearch)]),
type: schema.oneOf([schema.literal(outputType.Elasticsearch)]),
hosts: schema.maybe(schema.arrayOf(schema.string())),
api_key: schema.maybe(schema.string()),
fleet_enroll_username: schema.maybe(schema.string()),
Expand Down

0 comments on commit e916a1d

Please sign in to comment.