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

[Ingest] Support show_user package registry flag #60338

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export interface RegistryVarsEntry {
description?: string;
type: string;
required?: boolean;
show_user?: boolean;
multi?: boolean;
default?: string | string[];
os?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiTitle,
} from '@elastic/eui';
import { DatasourceInput, RegistryVarsEntry } from '../../../../types';
import { isAdvancedVar } from '../services';
import { DatasourceInputVarField } from './datasource_input_var_field';

export const DatasourceInputConfig: React.FunctionComponent<{
Expand All @@ -30,10 +31,10 @@ export const DatasourceInputConfig: React.FunctionComponent<{

if (packageInputVars) {
packageInputVars.forEach(varDef => {
if (varDef.required && !varDef.default) {
requiredVars.push(varDef);
} else {
if (isAdvancedVar(varDef)) {
advancedVars.push(varDef);
} else {
requiredVars.push(varDef);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
EuiButtonEmpty,
} from '@elastic/eui';
import { DatasourceInputStream, RegistryStream, RegistryVarsEntry } from '../../../../types';
import { isAdvancedVar } from '../services';
import { DatasourceInputVarField } from './datasource_input_var_field';

export const DatasourceInputStreamConfig: React.FunctionComponent<{
Expand All @@ -31,10 +32,10 @@ export const DatasourceInputStreamConfig: React.FunctionComponent<{

if (packageInputStream.vars && packageInputStream.vars.length) {
packageInputStream.vars.forEach(varDef => {
if (varDef.required && !varDef.default) {
requiredVars.push(varDef);
} else {
if (isAdvancedVar(varDef)) {
advancedVars.push(varDef);
} else {
requiredVars.push(varDef);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* 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.
*/
export { isAdvancedVar } from './is_advanced_var';
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 { isAdvancedVar } from './is_advanced_var';

describe('Ingest Manager - isAdvancedVar', () => {
it('returns true for vars that should be show under advanced options', () => {
expect(
isAdvancedVar({
name: 'mock_var',
type: 'text',
required: true,
default: 'default string',
})
).toBe(true);

expect(
isAdvancedVar({
name: 'mock_var',
type: 'text',
default: 'default string',
})
).toBe(true);

expect(
isAdvancedVar({
name: 'mock_var',
type: 'text',
})
).toBe(true);
});

it('returns false for vars that should be show by default', () => {
expect(
isAdvancedVar({
name: 'mock_var',
type: 'text',
required: true,
default: 'default string',
show_user: true,
})
).toBe(false);

expect(
isAdvancedVar({
name: 'mock_var',
type: 'text',
required: true,
})
).toBe(false);

expect(
isAdvancedVar({
name: 'mock_var',
type: 'text',
show_user: true,
})
).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { RegistryVarsEntry } from '../../../../types';

export const isAdvancedVar = (varDef: RegistryVarsEntry): boolean => {
if (varDef.show_user || (varDef.required && !varDef.default)) {
return false;
}
return true;
};