mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 19:10:07 -03: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:
commit
9de83fdcfe
@ -44,7 +44,10 @@ function LaunchPrompt({ config, resource, onLaunch, onCancel, i18n }) {
|
||||
setValue('limit', values.limit);
|
||||
setValue('job_tags', values.job_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);
|
||||
onLaunch(postValues);
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import yaml from 'js-yaml';
|
||||
|
||||
export default function mergeExtraVars(extraVars, survey = {}) {
|
||||
export default function mergeExtraVars(extraVars = '', survey = {}) {
|
||||
const vars = yaml.safeLoad(extraVars) || {};
|
||||
return {
|
||||
...vars,
|
||||
|
||||
@ -32,6 +32,10 @@ describe('mergeExtraVars', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('should handle undefined', () => {
|
||||
expect(mergeExtraVars(undefined, undefined)).toEqual({});
|
||||
});
|
||||
|
||||
describe('maskPasswords', () => {
|
||||
test('should mask password fields', () => {
|
||||
const vars = {
|
||||
|
||||
@ -8,27 +8,32 @@ import getSurveyValues from '../getSurveyValues';
|
||||
function PreviewStep({ resource, config, survey, formErrors }) {
|
||||
const { values } = useFormikContext();
|
||||
const surveyValues = getSurveyValues(values);
|
||||
let extraVars;
|
||||
if (survey && survey.spec) {
|
||||
const passwordFields = survey.spec
|
||||
.filter(q => q.type === 'password')
|
||||
.map(q => q.variable);
|
||||
const masked = maskPasswords(surveyValues, passwordFields);
|
||||
extraVars = yaml.safeDump(
|
||||
mergeExtraVars(values.extra_vars || '---', masked)
|
||||
);
|
||||
} else {
|
||||
extraVars = values.extra_vars || '---';
|
||||
|
||||
const overrides = { ...values };
|
||||
|
||||
if (config.ask_variables_on_launch || config.survey_enabled) {
|
||||
const initialExtraVars = config.ask_variables_on_launch
|
||||
? values.extra_vars || '---'
|
||||
: resource.extra_vars;
|
||||
if (survey && survey.spec) {
|
||||
const passwordFields = survey.spec
|
||||
.filter(q => q.type === 'password')
|
||||
.map(q => q.variable);
|
||||
const masked = maskPasswords(surveyValues, passwordFields);
|
||||
overrides.extra_vars = yaml.safeDump(
|
||||
mergeExtraVars(initialExtraVars, masked)
|
||||
);
|
||||
} else {
|
||||
overrides.extra_vars = initialExtraVars;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<PromptDetail
|
||||
resource={resource}
|
||||
launchConfig={config}
|
||||
overrides={{
|
||||
...values,
|
||||
extra_vars: extraVars,
|
||||
}}
|
||||
overrides={overrides}
|
||||
/>
|
||||
{formErrors && (
|
||||
<ul css="color: red">
|
||||
|
||||
@ -71,8 +71,30 @@ describe('PreviewStep', () => {
|
||||
expect(detail).toHaveLength(1);
|
||||
expect(detail.prop('resource')).toEqual(resource);
|
||||
expect(detail.prop('overrides')).toEqual({
|
||||
extra_vars: '---',
|
||||
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',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user