mirror of
https://github.com/ansible/awx.git
synced 2026-05-13 20:37:39 -02:30
default credentials are selected on POL load
This commit is contained in:
committed by
Shane McDonald
parent
1422bb2043
commit
3cdd35f2cf
@@ -37,7 +37,6 @@ function LaunchButton({ resource, children, history }) {
|
|||||||
const [launchConfig, setLaunchConfig] = useState(null);
|
const [launchConfig, setLaunchConfig] = useState(null);
|
||||||
const [surveyConfig, setSurveyConfig] = useState(null);
|
const [surveyConfig, setSurveyConfig] = useState(null);
|
||||||
const [isLaunching, setIsLaunching] = useState(false);
|
const [isLaunching, setIsLaunching] = useState(false);
|
||||||
const [resourceCredentials, setResourceCredentials] = useState([]);
|
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
const handleLaunch = async () => {
|
const handleLaunch = async () => {
|
||||||
@@ -60,17 +59,6 @@ function LaunchButton({ resource, children, history }) {
|
|||||||
setSurveyConfig(data);
|
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)) {
|
if (canLaunchWithoutPrompt(launch)) {
|
||||||
launchWithParams({});
|
launchWithParams({});
|
||||||
} else {
|
} else {
|
||||||
@@ -184,7 +172,6 @@ function LaunchButton({ resource, children, history }) {
|
|||||||
resource={resource}
|
resource={resource}
|
||||||
onLaunch={launchWithParams}
|
onLaunch={launchWithParams}
|
||||||
onCancel={() => setShowLaunchPrompt(false)}
|
onCancel={() => setShowLaunchPrompt(false)}
|
||||||
resourceDefaultCredentials={resourceCredentials}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Fragment>
|
</Fragment>
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ function PromptModalForm({
|
|||||||
onSubmit,
|
onSubmit,
|
||||||
resource,
|
resource,
|
||||||
surveyConfig,
|
surveyConfig,
|
||||||
resourceDefaultCredentials,
|
|
||||||
}) {
|
}) {
|
||||||
const { setFieldTouched, values } = useFormikContext();
|
const { setFieldTouched, values } = useFormikContext();
|
||||||
const [showDescription, setShowDescription] = useState(false);
|
const [showDescription, setShowDescription] = useState(false);
|
||||||
@@ -28,12 +27,7 @@ function PromptModalForm({
|
|||||||
visitStep,
|
visitStep,
|
||||||
visitAllSteps,
|
visitAllSteps,
|
||||||
contentError,
|
contentError,
|
||||||
} = useLaunchSteps(
|
} = useLaunchSteps(launchConfig, surveyConfig, resource);
|
||||||
launchConfig,
|
|
||||||
surveyConfig,
|
|
||||||
resource,
|
|
||||||
resourceDefaultCredentials
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
const postValues = {};
|
const postValues = {};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
import LaunchPrompt from './LaunchPrompt';
|
import LaunchPrompt from './LaunchPrompt';
|
||||||
import InventoryStep from './steps/InventoryStep';
|
import InventoryStep from './steps/InventoryStep';
|
||||||
import CredentialsStep from './steps/CredentialsStep';
|
import CredentialsStep from './steps/CredentialsStep';
|
||||||
|
import CredentialPasswordsStep from './steps/CredentialPasswordsStep';
|
||||||
import OtherPromptsStep from './steps/OtherPromptsStep';
|
import OtherPromptsStep from './steps/OtherPromptsStep';
|
||||||
import PreviewStep from './steps/PreviewStep';
|
import PreviewStep from './steps/PreviewStep';
|
||||||
import {
|
import {
|
||||||
@@ -27,6 +28,18 @@ const resource = {
|
|||||||
description: 'Foo Description',
|
description: 'Foo Description',
|
||||||
name: 'Foobar',
|
name: 'Foobar',
|
||||||
type: 'job_template',
|
type: 'job_template',
|
||||||
|
summary_fields: {
|
||||||
|
credentials: [
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
name: 'cred that prompts',
|
||||||
|
credential_type: 1,
|
||||||
|
inputs: {
|
||||||
|
password: 'ASK',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
|
|
||||||
@@ -101,7 +114,12 @@ describe('LaunchPrompt', () => {
|
|||||||
summary_fields: {
|
summary_fields: {
|
||||||
credentials: [
|
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 wizard = await waitForElement(wrapper, 'Wizard');
|
||||||
const steps = wizard.prop('steps');
|
const steps = wizard.prop('steps');
|
||||||
|
|
||||||
expect(steps).toHaveLength(2);
|
expect(steps).toHaveLength(3);
|
||||||
expect(steps[0].name.props.children).toEqual('Credentials');
|
expect(steps[0].name.props.children).toEqual('Credentials');
|
||||||
expect(isElementOfType(steps[0].component, CredentialsStep)).toEqual(true);
|
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 () => {
|
test('should add other prompts step', async () => {
|
||||||
|
|||||||
@@ -17,19 +17,18 @@ export default function credentialsValidator(
|
|||||||
if (
|
if (
|
||||||
!selectedCredentials.find(selectedCredential => {
|
!selectedCredentials.find(selectedCredential => {
|
||||||
return (
|
return (
|
||||||
(selectedCredential.credential_type ===
|
(selectedCredential?.credential_type ===
|
||||||
defaultCredential.credential_type &&
|
defaultCredential?.credential_type &&
|
||||||
!selectedCredential.inputs.vault_id &&
|
!selectedCredential.inputs?.vault_id &&
|
||||||
!defaultCredential.inputs.vault_id) ||
|
!defaultCredential.inputs?.vault_id) ||
|
||||||
(selectedCredential.inputs.vault_id &&
|
(defaultCredential.inputs?.vault_id &&
|
||||||
defaultCredential.inputs.vault_id &&
|
selectedCredential.inputs?.vault_id ===
|
||||||
selectedCredential.inputs.vault_id ===
|
defaultCredential.inputs?.vault_id)
|
||||||
defaultCredential.inputs.vault_id)
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
missingCredentialTypes.push(
|
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} | ${defaultCredential.inputs.vault_id}`
|
||||||
: defaultCredential.summary_fields.credential_type.name
|
: defaultCredential.summary_fields.credential_type.name
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export default function useCredentialsStep(
|
|||||||
launchConfig,
|
launchConfig,
|
||||||
resource,
|
resource,
|
||||||
resourceDefaultCredentials,
|
resourceDefaultCredentials,
|
||||||
|
|
||||||
allowCredentialsWithPasswords = false
|
allowCredentialsWithPasswords = false
|
||||||
) {
|
) {
|
||||||
const [field, meta, helpers] = useField('credentials');
|
const [field, meta, helpers] = useField('credentials');
|
||||||
@@ -22,7 +21,6 @@ export default function useCredentialsStep(
|
|||||||
return {
|
return {
|
||||||
step: getStep(
|
step: getStep(
|
||||||
launchConfig,
|
launchConfig,
|
||||||
|
|
||||||
allowCredentialsWithPasswords,
|
allowCredentialsWithPasswords,
|
||||||
formError,
|
formError,
|
||||||
resourceDefaultCredentials
|
resourceDefaultCredentials
|
||||||
|
|||||||
@@ -39,12 +39,7 @@ function showCredentialPasswordsStep(credentials = [], launchConfig) {
|
|||||||
return credentialPasswordStepRequired;
|
return credentialPasswordStepRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function useLaunchSteps(
|
export default function useLaunchSteps(launchConfig, surveyConfig, resource) {
|
||||||
launchConfig,
|
|
||||||
surveyConfig,
|
|
||||||
resource,
|
|
||||||
resourceDefaultCredentials
|
|
||||||
) {
|
|
||||||
const [visited, setVisited] = useState({});
|
const [visited, setVisited] = useState({});
|
||||||
const [isReady, setIsReady] = useState(false);
|
const [isReady, setIsReady] = useState(false);
|
||||||
const { touched, values: formikValues } = useFormikContext();
|
const { touched, values: formikValues } = useFormikContext();
|
||||||
@@ -53,7 +48,7 @@ export default function useLaunchSteps(
|
|||||||
useCredentialsStep(
|
useCredentialsStep(
|
||||||
launchConfig,
|
launchConfig,
|
||||||
resource,
|
resource,
|
||||||
resourceDefaultCredentials,
|
resource.summary_fields.credentials || [],
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
useCredentialPasswordsStep(
|
useCredentialPasswordsStep(
|
||||||
|
|||||||
Reference in New Issue
Block a user