default credentials are selected on POL load

This commit is contained in:
Alex Corey 2021-06-18 13:58:21 -04:00 committed by Shane McDonald
parent 1422bb2043
commit 3cdd35f2cf
No known key found for this signature in database
GPG Key ID: 6F374AF6E9EB9374
6 changed files with 35 additions and 51 deletions

View File

@ -37,7 +37,6 @@ function LaunchButton({ resource, children, history }) {
const [launchConfig, setLaunchConfig] = useState(null);
const [surveyConfig, setSurveyConfig] = useState(null);
const [isLaunching, setIsLaunching] = useState(false);
const [resourceCredentials, setResourceCredentials] = useState([]);
const [error, setError] = useState(null);
const handleLaunch = async () => {
@ -60,17 +59,6 @@ function LaunchButton({ resource, children, history }) {
setSurveyConfig(data);
}
if (
launch.ask_credential_on_launch &&
resource.type === 'workflow_job_template'
) {
const {
data: { results: jobTemplateCredentials },
} = await JobTemplatesAPI.readCredentials(resource.id);
setResourceCredentials(jobTemplateCredentials);
}
if (canLaunchWithoutPrompt(launch)) {
launchWithParams({});
} else {
@ -184,7 +172,6 @@ function LaunchButton({ resource, children, history }) {
resource={resource}
onLaunch={launchWithParams}
onCancel={() => setShowLaunchPrompt(false)}
resourceDefaultCredentials={resourceCredentials}
/>
)}
</Fragment>

View File

@ -16,7 +16,6 @@ function PromptModalForm({
onSubmit,
resource,
surveyConfig,
resourceDefaultCredentials,
}) {
const { setFieldTouched, values } = useFormikContext();
const [showDescription, setShowDescription] = useState(false);
@ -28,12 +27,7 @@ function PromptModalForm({
visitStep,
visitAllSteps,
contentError,
} = useLaunchSteps(
launchConfig,
surveyConfig,
resource,
resourceDefaultCredentials
);
} = useLaunchSteps(launchConfig, surveyConfig, resource);
const handleSubmit = () => {
const postValues = {};

View File

@ -7,6 +7,7 @@ import {
import LaunchPrompt from './LaunchPrompt';
import InventoryStep from './steps/InventoryStep';
import CredentialsStep from './steps/CredentialsStep';
import CredentialPasswordsStep from './steps/CredentialPasswordsStep';
import OtherPromptsStep from './steps/OtherPromptsStep';
import PreviewStep from './steps/PreviewStep';
import {
@ -27,6 +28,18 @@ const resource = {
description: 'Foo Description',
name: 'Foobar',
type: 'job_template',
summary_fields: {
credentials: [
{
id: 5,
name: 'cred that prompts',
credential_type: 1,
inputs: {
password: 'ASK',
},
},
],
},
};
const noop = () => {};
@ -101,7 +114,12 @@ describe('LaunchPrompt', () => {
summary_fields: {
credentials: [
{
id: 1,
id: 5,
name: 'cred that prompts',
credential_type: 1,
inputs: {
password: 'ASK',
},
},
],
},
@ -126,16 +144,6 @@ describe('LaunchPrompt', () => {
},
],
}}
resourceDefaultCredentials={[
{
id: 5,
name: 'cred that prompts',
credential_type: 1,
inputs: {
password: 'ASK',
},
},
]}
/>
);
});
@ -197,10 +205,13 @@ describe('LaunchPrompt', () => {
const wizard = await waitForElement(wrapper, 'Wizard');
const steps = wizard.prop('steps');
expect(steps).toHaveLength(2);
expect(steps).toHaveLength(3);
expect(steps[0].name.props.children).toEqual('Credentials');
expect(isElementOfType(steps[0].component, CredentialsStep)).toEqual(true);
expect(isElementOfType(steps[1].component, PreviewStep)).toEqual(true);
expect(
isElementOfType(steps[1].component, CredentialPasswordsStep)
).toEqual(true);
expect(isElementOfType(steps[2].component, PreviewStep)).toEqual(true);
});
test('should add other prompts step', async () => {

View File

@ -17,19 +17,18 @@ export default function credentialsValidator(
if (
!selectedCredentials.find(selectedCredential => {
return (
(selectedCredential.credential_type ===
defaultCredential.credential_type &&
!selectedCredential.inputs.vault_id &&
!defaultCredential.inputs.vault_id) ||
(selectedCredential.inputs.vault_id &&
defaultCredential.inputs.vault_id &&
selectedCredential.inputs.vault_id ===
defaultCredential.inputs.vault_id)
(selectedCredential?.credential_type ===
defaultCredential?.credential_type &&
!selectedCredential.inputs?.vault_id &&
!defaultCredential.inputs?.vault_id) ||
(defaultCredential.inputs?.vault_id &&
selectedCredential.inputs?.vault_id ===
defaultCredential.inputs?.vault_id)
);
})
) {
missingCredentialTypes.push(
defaultCredential.inputs.vault_id
defaultCredential.inputs?.vault_id
? `${defaultCredential.summary_fields.credential_type.name} | ${defaultCredential.inputs.vault_id}`
: defaultCredential.summary_fields.credential_type.name
);

View File

@ -11,7 +11,6 @@ export default function useCredentialsStep(
launchConfig,
resource,
resourceDefaultCredentials,
allowCredentialsWithPasswords = false
) {
const [field, meta, helpers] = useField('credentials');
@ -22,7 +21,6 @@ export default function useCredentialsStep(
return {
step: getStep(
launchConfig,
allowCredentialsWithPasswords,
formError,
resourceDefaultCredentials

View File

@ -39,12 +39,7 @@ function showCredentialPasswordsStep(credentials = [], launchConfig) {
return credentialPasswordStepRequired;
}
export default function useLaunchSteps(
launchConfig,
surveyConfig,
resource,
resourceDefaultCredentials
) {
export default function useLaunchSteps(launchConfig, surveyConfig, resource) {
const [visited, setVisited] = useState({});
const [isReady, setIsReady] = useState(false);
const { touched, values: formikValues } = useFormikContext();
@ -53,7 +48,7 @@ export default function useLaunchSteps(
useCredentialsStep(
launchConfig,
resource,
resourceDefaultCredentials,
resource.summary_fields.credentials || [],
true
),
useCredentialPasswordsStep(