Fix password field showing as null instead of empty string (#65183)
This commit is contained in:
parent
6d78489c14
commit
86332e2bb8
|
@ -17,9 +17,14 @@ describe('createStream', () => {
|
|||
exclude_files: [".gz$"]
|
||||
processors:
|
||||
- add_locale: ~
|
||||
password: {{password}}
|
||||
{{#if password}}
|
||||
hidden_password: {{password}}
|
||||
{{/if}}
|
||||
`;
|
||||
const vars = {
|
||||
paths: { value: ['/usr/local/var/log/nginx/access.log'] },
|
||||
password: { type: 'password', value: '' },
|
||||
};
|
||||
|
||||
const output = createStream(vars, streamTemplate);
|
||||
|
@ -28,6 +33,7 @@ describe('createStream', () => {
|
|||
paths: ['/usr/local/var/log/nginx/access.log'],
|
||||
exclude_files: ['.gz$'],
|
||||
processors: [{ add_locale: null }],
|
||||
password: '',
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -36,6 +42,7 @@ describe('createStream', () => {
|
|||
input: redis/metrics
|
||||
metricsets: ["key"]
|
||||
test: null
|
||||
password: {{password}}
|
||||
{{#if key.patterns}}
|
||||
key.patterns: {{key.patterns}}
|
||||
{{/if}}
|
||||
|
@ -48,6 +55,7 @@ describe('createStream', () => {
|
|||
pattern: '*'
|
||||
`,
|
||||
},
|
||||
password: { type: 'password', value: '' },
|
||||
};
|
||||
|
||||
const output = createStream(vars, streamTemplate);
|
||||
|
@ -61,6 +69,7 @@ describe('createStream', () => {
|
|||
pattern: '*',
|
||||
},
|
||||
],
|
||||
password: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -71,5 +71,16 @@ export function createStream(variables: DatasourceConfigRecord, streamTemplate:
|
|||
const stream = template(vars);
|
||||
const yamlFromStream = safeLoad(stream, {});
|
||||
|
||||
return replaceVariablesInYaml(yamlValues, yamlFromStream);
|
||||
// Hack to keep empty string ('') values around in the end yaml because
|
||||
// `safeLoad` replaces empty strings with null
|
||||
const patchedYamlFromStream = Object.entries(yamlFromStream).reduce((acc, [key, value]) => {
|
||||
if (value === null && typeof vars[key] === 'string' && vars[key].trim() === '') {
|
||||
acc[key] = '';
|
||||
} else {
|
||||
acc[key] = value;
|
||||
}
|
||||
return acc;
|
||||
}, {} as { [k: string]: any });
|
||||
|
||||
return replaceVariablesInYaml(yamlValues, patchedYamlFromStream);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue