-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[AAP-23162] Add credentials test button #2217
Conversation
5798a85
to
1945f87
Compare
1945f87
to
e25a692
Compare
4fef443
to
77d2c9b
Compare
frontend/awx/access/credentials/utils/CredentialsExternalTestModal.tsx
Outdated
Show resolved
Hide resolved
frontend/awx/access/credentials/utils/CredentialsExternalTestModal.tsx
Outdated
Show resolved
Hide resolved
c638065
to
55e0f08
Compare
55e0f08
to
78ccffa
Compare
78ccffa
to
55d7f3c
Compare
b214b0f
to
08f8424
Compare
This was a complicated piece of our code to nail down and implement, nice work. A suggestion to simplify/refactor some of the logic came to mind: export const useTestButton = () => {
const { t } = useTranslation();
const openCredentialsExternalTestModal = useCredentialsTestModal()
const [disableButton, setDisableButton] = useState(false);
const [values, setValues] = useState({});
const TestButton = () => (
<Button
variant="primary"
onClick={() => {
console.log('Test button clicked');
console.log(values);
openCredentialsExternalTestModal(...)
}}
isDisabled={disableButton}
>
{t('Test')}
</Button>
);
return { TestButton, setDisableButton, setValues };
}; Then, within CreateCredential: const { TestButton, setDisableButton, setValues } = useTestButton(); Pass the Within the CredentialInputs component set a watcher for the form values to change/update: const {
formState: { isValid },
} = useFormContext();
const watchedValues = useWatch();
useEffect(() => {
setDisableButton(!isValid);
setValues(watchedValues as initialValues);
}, [isValid, setDisableButton, setValues, watchedValues]); This would then give you the form values needed to render the Test Modal, as well as the validation logic to enable/disable the Test button within the form. We can then remove (I think): const [selectedCredentialTypeId, setSelectedCredentialTypeId] = useState<number>(0);
const [watchedSubFormFields, setWatchedSubFormFields] = useState<unknown[]>([]);
const [isTestButtonEnabled, setIsTestButtonEnabled] = useState(false);
const [isTestButtonEnabledSubForm, setIsTestButtonEnabledSubForm] = useState(false); Repeat for We can do this as a follow up PR as well, so I'll go ahead and approve this. |
08f8424
to
1cd2397
Compare
This PR adds a 'test' button to the credentials edit and create pages when an external credential type is selected. This button opens a modal which asks for some additional fields (dynamic depending on the credential type that is selected) and has a run button to run the test. Running the test then displays either a success or error alert on the page.
Jira issue: https://issues.redhat.com/browse/AAP-23162
Steps to see a mock successful response:
In AWX run:
Then, in a separate window (still in AWX):
ansible-playbook tools/docker-compose/ansible/plumb_vault.yml -e enable_ldap=false
ansible-playbook tools/docker-compose/ansible/unseal_vault.yml
Open a new window, in ansible-ui:
Point frontend to local backend using
export AWX_SERVER=https://127.0.0.1:8043
Npm run awx
In UI, go to credentials list
Vault lookup cred => edit => test button =>
Name of secret backend: my_engine
Path to secret: /my_root/my_folder
Key name: my_key