mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 01:47:31 -02:30
Merge pull request #7172 from keithjgrant/7142-prompt-extra-vars
Preserve extra_vars when they are not prompted Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -44,7 +44,10 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
|
|||||||
setValue('limit', values.limit);
|
setValue('limit', values.limit);
|
||||||
setValue('job_tags', values.job_tags);
|
setValue('job_tags', values.job_tags);
|
||||||
setValue('skip_tags', values.skip_tags);
|
setValue('skip_tags', values.skip_tags);
|
||||||
setValue('extra_vars', mergeExtraVars(values.extra_vars, surveyValues));
|
const extraVars = config.ask_variables_on_launch
|
||||||
|
? values.extra_vars || '---'
|
||||||
|
: resource.extra_vars;
|
||||||
|
setValue('extra_vars', mergeExtraVars(extraVars, surveyValues));
|
||||||
setValue('scm_branch', values.scm_branch);
|
setValue('scm_branch', values.scm_branch);
|
||||||
onLaunch(postValues);
|
onLaunch(postValues);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import yaml from 'js-yaml';
|
import yaml from 'js-yaml';
|
||||||
|
|
||||||
export default function mergeExtraVars(extraVars, survey = {}) {
|
export default function mergeExtraVars(extraVars = '', survey = {}) {
|
||||||
const vars = yaml.safeLoad(extraVars) || {};
|
const vars = yaml.safeLoad(extraVars) || {};
|
||||||
return {
|
return {
|
||||||
...vars,
|
...vars,
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ describe('mergeExtraVars', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should handle undefined', () => {
|
||||||
|
expect(mergeExtraVars(undefined, undefined)).toEqual({});
|
||||||
|
});
|
||||||
|
|
||||||
describe('maskPasswords', () => {
|
describe('maskPasswords', () => {
|
||||||
test('should mask password fields', () => {
|
test('should mask password fields', () => {
|
||||||
const vars = {
|
const vars = {
|
||||||
|
|||||||
@@ -8,27 +8,32 @@ import getSurveyValues from '../getSurveyValues';
|
|||||||
function PreviewStep({ resource, config, survey, formErrors }) {
|
function PreviewStep({ resource, config, survey, formErrors }) {
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
const surveyValues = getSurveyValues(values);
|
const surveyValues = getSurveyValues(values);
|
||||||
let extraVars;
|
|
||||||
if (survey && survey.spec) {
|
const overrides = { ...values };
|
||||||
const passwordFields = survey.spec
|
|
||||||
.filter(q => q.type === 'password')
|
if (config.ask_variables_on_launch || config.survey_enabled) {
|
||||||
.map(q => q.variable);
|
const initialExtraVars = config.ask_variables_on_launch
|
||||||
const masked = maskPasswords(surveyValues, passwordFields);
|
? values.extra_vars || '---'
|
||||||
extraVars = yaml.safeDump(
|
: resource.extra_vars;
|
||||||
mergeExtraVars(values.extra_vars || '---', masked)
|
if (survey && survey.spec) {
|
||||||
);
|
const passwordFields = survey.spec
|
||||||
} else {
|
.filter(q => q.type === 'password')
|
||||||
extraVars = values.extra_vars || '---';
|
.map(q => q.variable);
|
||||||
|
const masked = maskPasswords(surveyValues, passwordFields);
|
||||||
|
overrides.extra_vars = yaml.safeDump(
|
||||||
|
mergeExtraVars(initialExtraVars, masked)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
overrides.extra_vars = initialExtraVars;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<PromptDetail
|
<PromptDetail
|
||||||
resource={resource}
|
resource={resource}
|
||||||
launchConfig={config}
|
launchConfig={config}
|
||||||
overrides={{
|
overrides={overrides}
|
||||||
...values,
|
|
||||||
extra_vars: extraVars,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
{formErrors && (
|
{formErrors && (
|
||||||
<ul css="color: red">
|
<ul css="color: red">
|
||||||
|
|||||||
@@ -71,8 +71,30 @@ describe('PreviewStep', () => {
|
|||||||
expect(detail).toHaveLength(1);
|
expect(detail).toHaveLength(1);
|
||||||
expect(detail.prop('resource')).toEqual(resource);
|
expect(detail.prop('resource')).toEqual(resource);
|
||||||
expect(detail.prop('overrides')).toEqual({
|
expect(detail.prop('overrides')).toEqual({
|
||||||
extra_vars: '---',
|
|
||||||
limit: '4',
|
limit: '4',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should handle extra vars without survey', async () => {
|
||||||
|
let wrapper;
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<Formik initialValues={{ extra_vars: 'one: 1' }}>
|
||||||
|
<PreviewStep
|
||||||
|
resource={resource}
|
||||||
|
config={{
|
||||||
|
ask_variables_on_launch: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Formik>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const detail = wrapper.find('PromptDetail');
|
||||||
|
expect(detail).toHaveLength(1);
|
||||||
|
expect(detail.prop('resource')).toEqual(resource);
|
||||||
|
expect(detail.prop('overrides')).toEqual({
|
||||||
|
extra_vars: 'one: 1',
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user