mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 14:27:42 -02:30
Remove credential password mapping in favor of using keys that the api accepts
This commit is contained in:
@@ -7,7 +7,6 @@ import ContentError from '../ContentError';
|
|||||||
import ContentLoading from '../ContentLoading';
|
import ContentLoading from '../ContentLoading';
|
||||||
import { useDismissableError } from '../../util/useRequest';
|
import { useDismissableError } from '../../util/useRequest';
|
||||||
import mergeExtraVars from '../../util/prompt/mergeExtraVars';
|
import mergeExtraVars from '../../util/prompt/mergeExtraVars';
|
||||||
import getCredentialPasswords from '../../util/prompt/getCredentialPasswords';
|
|
||||||
import getSurveyValues from '../../util/prompt/getSurveyValues';
|
import getSurveyValues from '../../util/prompt/getSurveyValues';
|
||||||
import useLaunchSteps from './useLaunchSteps';
|
import useLaunchSteps from './useLaunchSteps';
|
||||||
import AlertModal from '../AlertModal';
|
import AlertModal from '../AlertModal';
|
||||||
@@ -39,8 +38,7 @@ function PromptModalForm({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const surveyValues = getSurveyValues(values);
|
const surveyValues = getSurveyValues(values);
|
||||||
const credentialPasswords = getCredentialPasswords(values);
|
setValue('credential_passwords', values.credential_passwords);
|
||||||
setValue('credential_passwords', credentialPasswords);
|
|
||||||
setValue('inventory_id', values.inventory?.id);
|
setValue('inventory_id', values.inventory?.id);
|
||||||
setValue(
|
setValue(
|
||||||
'credentials',
|
'credentials',
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ function CredentialPasswordsStep({ launchConfig, i18n }) {
|
|||||||
<PasswordField
|
<PasswordField
|
||||||
id="launch-ssh-password"
|
id="launch-ssh-password"
|
||||||
label={i18n._(t`SSH password`)}
|
label={i18n._(t`SSH password`)}
|
||||||
name="credentialPasswordSsh"
|
name="credential_passwords.ssh_password"
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -97,7 +97,7 @@ function CredentialPasswordsStep({ launchConfig, i18n }) {
|
|||||||
<PasswordField
|
<PasswordField
|
||||||
id="launch-private-key-passphrase"
|
id="launch-private-key-passphrase"
|
||||||
label={i18n._(t`Private key passphrase`)}
|
label={i18n._(t`Private key passphrase`)}
|
||||||
name="credentialPasswordPrivateKeyPassphrase"
|
name="credential_passwords.ssh_key_unlock"
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -105,7 +105,7 @@ function CredentialPasswordsStep({ launchConfig, i18n }) {
|
|||||||
<PasswordField
|
<PasswordField
|
||||||
id="launch-privilege-escalation-password"
|
id="launch-privilege-escalation-password"
|
||||||
label={i18n._(t`Privilege escalation password`)}
|
label={i18n._(t`Privilege escalation password`)}
|
||||||
name="credentialPasswordPrivilegeEscalation"
|
name="credential_passwords.become_password"
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -118,7 +118,9 @@ function CredentialPasswordsStep({ launchConfig, i18n }) {
|
|||||||
? i18n._(t`Vault password`)
|
? i18n._(t`Vault password`)
|
||||||
: i18n._(t`Vault password | ${credId}`)
|
: i18n._(t`Vault password | ${credId}`)
|
||||||
}
|
}
|
||||||
name={`credentialPasswordVault_${credId}`}
|
name={`credential_passwords['vault_password${
|
||||||
|
credId !== '' ? `.${credId}` : ''
|
||||||
|
}']`}
|
||||||
isRequired
|
isRequired
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -41,48 +41,26 @@ export default function useCredentialPasswordsStep(
|
|||||||
contentError: null,
|
contentError: null,
|
||||||
hasError,
|
hasError,
|
||||||
setTouched: setFieldTouched => {
|
setTouched: setFieldTouched => {
|
||||||
Object.keys(values)
|
Object.keys(values.credential_passwords).forEach(credentialValueKey =>
|
||||||
.filter(valueKey => valueKey.startsWith('credentialPassword'))
|
setFieldTouched(
|
||||||
.forEach(credentialValueKey =>
|
`credential_passwords['${credentialValueKey}']`,
|
||||||
setFieldTouched(credentialValueKey, true, false)
|
true,
|
||||||
);
|
false
|
||||||
|
)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
validate: () => {
|
validate: () => {
|
||||||
const setPasswordFieldError = fieldName => {
|
const setPasswordFieldError = fieldName => {
|
||||||
setFieldError(fieldName, i18n._(t`This field may not be blank`));
|
setFieldError(fieldName, i18n._(t`This field may not be blank`));
|
||||||
};
|
};
|
||||||
|
|
||||||
const {
|
|
||||||
credentialPasswordSsh,
|
|
||||||
credentialPasswordPrivilegeEscalation,
|
|
||||||
credentialPasswordPrivateKeyPassphrase,
|
|
||||||
} = values;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!launchConfig.ask_credential_on_launch &&
|
!launchConfig.ask_credential_on_launch &&
|
||||||
launchConfig.passwords_needed_to_start
|
launchConfig.passwords_needed_to_start
|
||||||
) {
|
) {
|
||||||
launchConfig.passwords_needed_to_start.forEach(password => {
|
launchConfig.passwords_needed_to_start.forEach(password => {
|
||||||
if (
|
if (isValueMissing(values.credential_passwords[password])) {
|
||||||
password === 'ssh_password' &&
|
setPasswordFieldError(`credential_passwords['${password}']`);
|
||||||
isValueMissing(credentialPasswordSsh)
|
|
||||||
) {
|
|
||||||
setPasswordFieldError('credentialPasswordSsh');
|
|
||||||
} else if (
|
|
||||||
password === 'become_password' &&
|
|
||||||
isValueMissing(credentialPasswordPrivilegeEscalation)
|
|
||||||
) {
|
|
||||||
setPasswordFieldError('credentialPasswordPrivilegeEscalation');
|
|
||||||
} else if (
|
|
||||||
password === 'ssh_key_unlock' &&
|
|
||||||
isValueMissing(credentialPasswordPrivateKeyPassphrase)
|
|
||||||
) {
|
|
||||||
setPasswordFieldError('credentialPasswordPrivateKeyPassphrase');
|
|
||||||
} else if (password.startsWith('vault_password')) {
|
|
||||||
const vaultId = password.split(/\.(.+)/)[1] || '';
|
|
||||||
if (isValueMissing(values[`credentialPasswordVault_${vaultId}`])) {
|
|
||||||
setPasswordFieldError(`credentialPasswordVault_${vaultId}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (values.credentials) {
|
} else if (values.credentials) {
|
||||||
@@ -93,74 +71,52 @@ export default function useCredentialPasswordsStep(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (launchConfigCredential?.passwords_needed.length > 0) {
|
if (launchConfigCredential?.passwords_needed.length > 0) {
|
||||||
if (
|
launchConfigCredential.passwords_needed.forEach(password => {
|
||||||
launchConfigCredential.passwords_needed.includes(
|
if (isValueMissing(values.credential_passwords[password])) {
|
||||||
'ssh_password'
|
setPasswordFieldError(`credential_passwords['${password}']`);
|
||||||
) &&
|
}
|
||||||
isValueMissing(credentialPasswordSsh)
|
});
|
||||||
) {
|
|
||||||
setPasswordFieldError('credentialPasswordSsh');
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
launchConfigCredential.passwords_needed.includes(
|
|
||||||
'become_password'
|
|
||||||
) &&
|
|
||||||
isValueMissing(credentialPasswordPrivilegeEscalation)
|
|
||||||
) {
|
|
||||||
setPasswordFieldError('credentialPasswordPrivilegeEscalation');
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
launchConfigCredential.passwords_needed.includes(
|
|
||||||
'ssh_key_unlock'
|
|
||||||
) &&
|
|
||||||
isValueMissing(credentialPasswordPrivateKeyPassphrase)
|
|
||||||
) {
|
|
||||||
setPasswordFieldError('credentialPasswordPrivateKeyPassphrase');
|
|
||||||
}
|
|
||||||
|
|
||||||
launchConfigCredential.passwords_needed
|
|
||||||
.filter(passwordNeeded =>
|
|
||||||
passwordNeeded.startsWith('vault_password')
|
|
||||||
)
|
|
||||||
.map(vaultPassword => vaultPassword.split(/\.(.+)/)[1] || '')
|
|
||||||
.forEach(vaultId => {
|
|
||||||
if (
|
|
||||||
isValueMissing(values[`credentialPasswordVault_${vaultId}`])
|
|
||||||
) {
|
|
||||||
setPasswordFieldError(`credentialPasswordVault_${vaultId}`);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
credential?.inputs?.password === 'ASK' &&
|
credential?.inputs?.password === 'ASK' &&
|
||||||
isValueMissing(credentialPasswordSsh)
|
isValueMissing(values.credential_passwords.ssh_password)
|
||||||
) {
|
) {
|
||||||
setPasswordFieldError('credentialPasswordSsh');
|
setPasswordFieldError('credential_passwords.ssh_password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
credential?.inputs?.become_password === 'ASK' &&
|
credential?.inputs?.become_password === 'ASK' &&
|
||||||
isValueMissing(credentialPasswordPrivilegeEscalation)
|
isValueMissing(values.credential_passwords.become_password)
|
||||||
) {
|
) {
|
||||||
setPasswordFieldError('credentialPasswordPrivilegeEscalation');
|
setPasswordFieldError('credential_passwords.become_password');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
credential?.inputs?.ssh_key_unlock === 'ASK' &&
|
credential?.inputs?.ssh_key_unlock === 'ASK' &&
|
||||||
isValueMissing(credentialPasswordPrivateKeyPassphrase)
|
isValueMissing(values.credential_passwords.ssh_key_unlock)
|
||||||
) {
|
) {
|
||||||
setPasswordFieldError('credentialPasswordPrivateKeyPassphrase');
|
setPasswordFieldError('credential_passwords.ssh_key_unlock');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
credential?.inputs?.vault_password === 'ASK' &&
|
credential?.inputs?.vault_password === 'ASK' &&
|
||||||
isValueMissing(
|
isValueMissing(
|
||||||
values[`credentialPasswordVault_${credential.inputs.vault_id}`]
|
values.credential_passwords[
|
||||||
|
`vault_password${
|
||||||
|
credential.inputs.vault_id !== ''
|
||||||
|
? `.${credential.inputs.vault_id}`
|
||||||
|
: ''
|
||||||
|
}`
|
||||||
|
]
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
setPasswordFieldError(
|
setPasswordFieldError(
|
||||||
`credentialPasswordVault_${credential.inputs.vault_id}`
|
`credential_passwords['vault_password${
|
||||||
|
credential.inputs.vault_id !== ''
|
||||||
|
? `.${credential.inputs.vault_id}`
|
||||||
|
: ''
|
||||||
|
}']`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,7 +127,9 @@ export default function useCredentialPasswordsStep(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getInitialValues(launchConfig, selectedCredentials = []) {
|
function getInitialValues(launchConfig, selectedCredentials = []) {
|
||||||
const initialValues = {};
|
const initialValues = {
|
||||||
|
credential_passwords: {},
|
||||||
|
};
|
||||||
|
|
||||||
if (!launchConfig) {
|
if (!launchConfig) {
|
||||||
return initialValues;
|
return initialValues;
|
||||||
@@ -182,16 +140,7 @@ function getInitialValues(launchConfig, selectedCredentials = []) {
|
|||||||
launchConfig.passwords_needed_to_start
|
launchConfig.passwords_needed_to_start
|
||||||
) {
|
) {
|
||||||
launchConfig.passwords_needed_to_start.forEach(password => {
|
launchConfig.passwords_needed_to_start.forEach(password => {
|
||||||
if (password === 'ssh_password') {
|
initialValues.credential_passwords[password] = '';
|
||||||
initialValues.credentialPasswordSsh = '';
|
|
||||||
} else if (password === 'become_password') {
|
|
||||||
initialValues.credentialPasswordPrivilegeEscalation = '';
|
|
||||||
} else if (password === 'ssh_key_unlock') {
|
|
||||||
initialValues.credentialPasswordPrivateKeyPassphrase = '';
|
|
||||||
} else if (password.startsWith('vault_password')) {
|
|
||||||
const vaultId = password.split(/\.(.+)/)[1] || '';
|
|
||||||
initialValues[`credentialPasswordVault_${vaultId}`] = '';
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return initialValues;
|
return initialValues;
|
||||||
}
|
}
|
||||||
@@ -203,44 +152,31 @@ function getInitialValues(launchConfig, selectedCredentials = []) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (launchConfigCredential?.passwords_needed.length > 0) {
|
if (launchConfigCredential?.passwords_needed.length > 0) {
|
||||||
if (launchConfigCredential.passwords_needed.includes('ssh_password')) {
|
launchConfigCredential.passwords_needed.forEach(password => {
|
||||||
initialValues.credentialPasswordSsh = '';
|
initialValues.credential_passwords[password] = '';
|
||||||
}
|
|
||||||
if (
|
|
||||||
launchConfigCredential.passwords_needed.includes('become_password')
|
|
||||||
) {
|
|
||||||
initialValues.credentialPasswordPrivilegeEscalation = '';
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
launchConfigCredential.passwords_needed.includes('ssh_key_unlock')
|
|
||||||
) {
|
|
||||||
initialValues.credentialPasswordPrivateKeyPassphrase = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
const vaultPasswordIds = launchConfigCredential.passwords_needed
|
|
||||||
.filter(passwordNeeded => passwordNeeded.startsWith('vault_password'))
|
|
||||||
.map(vaultPassword => vaultPassword.split(/\.(.+)/)[1] || '');
|
|
||||||
|
|
||||||
vaultPasswordIds.forEach(vaultPasswordId => {
|
|
||||||
initialValues[`credentialPasswordVault_${vaultPasswordId}`] = '';
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (credential?.inputs?.password === 'ASK') {
|
if (credential?.inputs?.password === 'ASK') {
|
||||||
initialValues.credentialPasswordSsh = '';
|
initialValues.credential_passwords.ssh_password = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (credential?.inputs?.become_password === 'ASK') {
|
if (credential?.inputs?.become_password === 'ASK') {
|
||||||
initialValues.credentialPasswordPrivilegeEscalation = '';
|
initialValues.credential_passwords.become_password = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (credential?.inputs?.ssh_key_unlock === 'ASK') {
|
if (credential?.inputs?.ssh_key_unlock === 'ASK') {
|
||||||
initialValues.credentialPasswordPrivateKeyPassphrase = '';
|
initialValues.credential_passwords.ssh_key_unlock = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (credential?.inputs?.vault_password === 'ASK') {
|
if (credential?.inputs?.vault_password === 'ASK') {
|
||||||
initialValues[`credentialPasswordVault_${credential.inputs.vault_id}`] =
|
if (!credential.inputs.vault_id || credential.inputs.vault_id === '') {
|
||||||
'';
|
initialValues.credential_passwords.vault_password = '';
|
||||||
|
} else {
|
||||||
|
initialValues.credential_passwords[
|
||||||
|
`vault_password.${credential.inputs.vault_id}`
|
||||||
|
] = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -249,12 +185,6 @@ function getInitialValues(launchConfig, selectedCredentials = []) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkForError(launchConfig, values) {
|
function checkForError(launchConfig, values) {
|
||||||
const {
|
|
||||||
credentialPasswordSsh,
|
|
||||||
credentialPasswordPrivilegeEscalation,
|
|
||||||
credentialPasswordPrivateKeyPassphrase,
|
|
||||||
} = values;
|
|
||||||
|
|
||||||
let hasError = false;
|
let hasError = false;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -262,20 +192,8 @@ function checkForError(launchConfig, values) {
|
|||||||
launchConfig.passwords_needed_to_start
|
launchConfig.passwords_needed_to_start
|
||||||
) {
|
) {
|
||||||
launchConfig.passwords_needed_to_start.forEach(password => {
|
launchConfig.passwords_needed_to_start.forEach(password => {
|
||||||
if (
|
if (isValueMissing(values.credential_passwords[password])) {
|
||||||
(password === 'ssh_password' &&
|
|
||||||
isValueMissing(credentialPasswordSsh)) ||
|
|
||||||
(password === 'become_password' &&
|
|
||||||
isValueMissing(credentialPasswordPrivilegeEscalation)) ||
|
|
||||||
(password === 'ssh_key_unlock' &&
|
|
||||||
isValueMissing(credentialPasswordPrivateKeyPassphrase))
|
|
||||||
) {
|
|
||||||
hasError = true;
|
hasError = true;
|
||||||
} else if (password.startsWith('vault_password')) {
|
|
||||||
const vaultId = password.split(/\.(.+)/)[1] || '';
|
|
||||||
if (isValueMissing(values[`credentialPasswordVault_${vaultId}`])) {
|
|
||||||
hasError = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (values.credentials) {
|
} else if (values.credentials) {
|
||||||
@@ -286,42 +204,30 @@ function checkForError(launchConfig, values) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (launchConfigCredential?.passwords_needed.length > 0) {
|
if (launchConfigCredential?.passwords_needed.length > 0) {
|
||||||
if (
|
launchConfigCredential.passwords_needed.forEach(password => {
|
||||||
(launchConfigCredential.passwords_needed.includes('ssh_password') &&
|
if (isValueMissing(values.credential_passwords[password])) {
|
||||||
isValueMissing(credentialPasswordSsh)) ||
|
hasError = true;
|
||||||
(launchConfigCredential.passwords_needed.includes(
|
}
|
||||||
'become_password'
|
});
|
||||||
) &&
|
|
||||||
isValueMissing(credentialPasswordPrivilegeEscalation)) ||
|
|
||||||
(launchConfigCredential.passwords_needed.includes(
|
|
||||||
'ssh_key_unlock'
|
|
||||||
) &&
|
|
||||||
isValueMissing(credentialPasswordPrivateKeyPassphrase))
|
|
||||||
) {
|
|
||||||
hasError = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
launchConfigCredential.passwords_needed
|
|
||||||
.filter(passwordNeeded =>
|
|
||||||
passwordNeeded.startsWith('vault_password')
|
|
||||||
)
|
|
||||||
.map(vaultPassword => vaultPassword.split(/\.(.+)/)[1] || '')
|
|
||||||
.forEach(vaultId => {
|
|
||||||
if (
|
|
||||||
isValueMissing(values[`credentialPasswordVault_${vaultId}`])
|
|
||||||
) {
|
|
||||||
hasError = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
(credential?.inputs?.password === 'ASK' &&
|
credential?.inputs?.password === 'ASK' &&
|
||||||
isValueMissing(credentialPasswordSsh)) ||
|
isValueMissing(values.credential_passwords.ssh_password)
|
||||||
(credential?.inputs?.become_password === 'ASK' &&
|
) {
|
||||||
isValueMissing(credentialPasswordPrivilegeEscalation)) ||
|
hasError = true;
|
||||||
(credential?.inputs?.ssh_key_unlock === 'ASK' &&
|
}
|
||||||
isValueMissing(credentialPasswordPrivateKeyPassphrase))
|
|
||||||
|
if (
|
||||||
|
credential?.inputs?.become_password === 'ASK' &&
|
||||||
|
isValueMissing(values.credential_passwords.become_password)
|
||||||
|
) {
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
credential?.inputs?.ssh_key_unlock === 'ASK' &&
|
||||||
|
isValueMissing(values.credential_passwords.ssh_key_unlock)
|
||||||
) {
|
) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
@@ -329,7 +235,13 @@ function checkForError(launchConfig, values) {
|
|||||||
if (
|
if (
|
||||||
credential?.inputs?.vault_password === 'ASK' &&
|
credential?.inputs?.vault_password === 'ASK' &&
|
||||||
isValueMissing(
|
isValueMissing(
|
||||||
values[`credentialPasswordVault_${credential.inputs.vault_id}`]
|
values.credential_passwords[
|
||||||
|
`vault_password${
|
||||||
|
credential.inputs.vault_id !== ''
|
||||||
|
? `.${credential.inputs.vault_id}`
|
||||||
|
: ''
|
||||||
|
}`
|
||||||
|
]
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
|||||||
@@ -83,6 +83,27 @@ export default function useLaunchSteps(
|
|||||||
|
|
||||||
Object.keys(formikValues).forEach(formikValueKey => {
|
Object.keys(formikValues).forEach(formikValueKey => {
|
||||||
if (
|
if (
|
||||||
|
formikValueKey === 'credential_passwords' &&
|
||||||
|
Object.prototype.hasOwnProperty.call(
|
||||||
|
newFormValues,
|
||||||
|
'credential_passwords'
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
const formikCredentialPasswords = formikValues.credential_passwords;
|
||||||
|
Object.keys(formikCredentialPasswords).forEach(
|
||||||
|
credentialPasswordValueKey => {
|
||||||
|
if (
|
||||||
|
Object.prototype.hasOwnProperty.call(
|
||||||
|
newFormValues.credential_passwords,
|
||||||
|
credentialPasswordValueKey
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
newFormValues.credential_passwords[credentialPasswordValueKey] =
|
||||||
|
formikCredentialPasswords[credentialPasswordValueKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
Object.prototype.hasOwnProperty.call(newFormValues, formikValueKey)
|
Object.prototype.hasOwnProperty.call(newFormValues, formikValueKey)
|
||||||
) {
|
) {
|
||||||
newFormValues[formikValueKey] = formikValues[formikValueKey];
|
newFormValues[formikValueKey] = formikValues[formikValueKey];
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
export default function getCredentialPasswords(values) {
|
|
||||||
const credentialPasswords = {};
|
|
||||||
Object.keys(values)
|
|
||||||
.filter(valueKey => valueKey.startsWith('credentialPassword'))
|
|
||||||
.forEach(credentialValueKey => {
|
|
||||||
if (credentialValueKey === 'credentialPasswordSsh') {
|
|
||||||
credentialPasswords.ssh_password = values[credentialValueKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (credentialValueKey === 'credentialPasswordPrivilegeEscalation') {
|
|
||||||
credentialPasswords.become_password = values[credentialValueKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (credentialValueKey === 'credentialPasswordPrivateKeyPassphrase') {
|
|
||||||
credentialPasswords.ssh_key_unlock = values[credentialValueKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (credentialValueKey.startsWith('credentialPasswordVault_')) {
|
|
||||||
const vaultId = credentialValueKey.split('credentialPasswordVault_')[1];
|
|
||||||
if (vaultId.length > 0) {
|
|
||||||
credentialPasswords[`vault_password.${vaultId}`] =
|
|
||||||
values[credentialValueKey];
|
|
||||||
} else {
|
|
||||||
credentialPasswords.vault_password = values[credentialValueKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return credentialPasswords;
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import getCredentialPasswords from './getCredentialPasswords';
|
|
||||||
|
|
||||||
describe('getCredentialPasswords', () => {
|
|
||||||
test('should handle ssh password', () => {
|
|
||||||
expect(
|
|
||||||
getCredentialPasswords({
|
|
||||||
credentialPasswordSsh: 'foobar',
|
|
||||||
})
|
|
||||||
).toEqual({
|
|
||||||
ssh_password: 'foobar',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('should handle become password', () => {
|
|
||||||
expect(
|
|
||||||
getCredentialPasswords({
|
|
||||||
credentialPasswordPrivilegeEscalation: 'foobar',
|
|
||||||
})
|
|
||||||
).toEqual({
|
|
||||||
become_password: 'foobar',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('should handle ssh key unlock', () => {
|
|
||||||
expect(
|
|
||||||
getCredentialPasswords({
|
|
||||||
credentialPasswordPrivateKeyPassphrase: 'foobar',
|
|
||||||
})
|
|
||||||
).toEqual({
|
|
||||||
ssh_key_unlock: 'foobar',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('should handle vault password with identifier', () => {
|
|
||||||
expect(
|
|
||||||
getCredentialPasswords({
|
|
||||||
credentialPasswordVault_1: 'foobar',
|
|
||||||
})
|
|
||||||
).toEqual({
|
|
||||||
'vault_password.1': 'foobar',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('should handle vault password without identifier', () => {
|
|
||||||
expect(
|
|
||||||
getCredentialPasswords({
|
|
||||||
credentialPasswordVault_: 'foobar',
|
|
||||||
})
|
|
||||||
).toEqual({
|
|
||||||
vault_password: 'foobar',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
test('should handle all password types', () => {
|
|
||||||
expect(
|
|
||||||
getCredentialPasswords({
|
|
||||||
credentialPasswordSsh: '1',
|
|
||||||
credentialPasswordPrivilegeEscalation: '2',
|
|
||||||
credentialPasswordPrivateKeyPassphrase: '3',
|
|
||||||
credentialPasswordVault_: '4',
|
|
||||||
credentialPasswordVault_1: '5',
|
|
||||||
})
|
|
||||||
).toEqual({
|
|
||||||
ssh_password: '1',
|
|
||||||
become_password: '2',
|
|
||||||
ssh_key_unlock: '3',
|
|
||||||
vault_password: '4',
|
|
||||||
'vault_password.1': '5',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user