|
| 1 | +import React from 'react'; |
| 2 | +import { Base64 } from 'js-base64'; |
| 3 | +import { ForkliftTrans, useForkliftTranslation } from 'src/utils/i18n'; |
| 4 | + |
| 5 | +import { Text, TextVariants } from '@patternfly/react-core'; |
| 6 | + |
| 7 | +import { FieldWithClipboardCopy } from '../../FieldWithClipboardCopy'; |
| 8 | +import { MaskedField } from '../../MaskedField'; |
| 9 | +import { ListComponentProps } from '../BaseCredentialsSection'; |
| 10 | + |
| 11 | +import { Fields } from './Fields'; |
| 12 | + |
| 13 | +export const EsxiCredentialsList: React.FC<ListComponentProps> = ({ secret, reveal }) => { |
| 14 | + const { t } = useForkliftTranslation(); |
| 15 | + |
| 16 | + const items = []; |
| 17 | + |
| 18 | + const insecureSkipVerifyHelperTextPopover = ( |
| 19 | + <ForkliftTrans> |
| 20 | + <p> |
| 21 | + Select <strong>Skip certificate validation</strong> to skip certificate verification, which |
| 22 | + proceeds with an insecure migration and then the certificate is not required. Insecure |
| 23 | + migration means that the transferred data is sent over an insecure connection and |
| 24 | + potentially sensitive data could be exposed. |
| 25 | + </p> |
| 26 | + </ForkliftTrans> |
| 27 | + ); |
| 28 | + |
| 29 | + const cacertHelperTextPopover = ( |
| 30 | + <ForkliftTrans> |
| 31 | + <p> |
| 32 | + Use the CA certificate of the Manager unless it was replaced by a third-party certificate, |
| 33 | + in which case enter the Manager Apache CA certificate. |
| 34 | + </p> |
| 35 | + <p>When left empty the system CA certificate is used.</p> |
| 36 | + <p> |
| 37 | + The certificate is not verified when <strong>Skip certificate validation</strong> is set. |
| 38 | + </p> |
| 39 | + </ForkliftTrans> |
| 40 | + ); |
| 41 | + |
| 42 | + const fields: Fields = { |
| 43 | + user: { |
| 44 | + label: t('Username'), |
| 45 | + description: ( |
| 46 | + <div className="forklift-page-provider-field-default-validation"> |
| 47 | + <ForkliftTrans> |
| 48 | + A username and domain for connecting to the ESXi API endpoint. For example:{' '} |
| 49 | + <strong>user</strong>. |
| 50 | + </ForkliftTrans> |
| 51 | + </div> |
| 52 | + ), |
| 53 | + }, |
| 54 | + password: { |
| 55 | + label: t('Password'), |
| 56 | + description: 'A user password for connecting to the ESXi API endpoint.', |
| 57 | + }, |
| 58 | + insecureSkipVerify: { |
| 59 | + label: t('Skip certificate validation'), |
| 60 | + description: t("If true, the provider's TLS certificate won't be validated."), |
| 61 | + cacertHelperTextPopover: insecureSkipVerifyHelperTextPopover, |
| 62 | + displayType: 'switch', |
| 63 | + }, |
| 64 | + cacert: { |
| 65 | + label: t('CA certificate'), |
| 66 | + description: t( |
| 67 | + 'A CA certificate to be trusted when connecting to the ESXi API endpoint. Ensure the CA certificate format is in a PEM encoded X.509 format. To use a CA certificate, drag the file to the text box or browse for it. To use the system CA certificate, leave the field empty.', |
| 68 | + ), |
| 69 | + helperTextPopover: cacertHelperTextPopover, |
| 70 | + displayType: 'textArea', |
| 71 | + }, |
| 72 | + }; |
| 73 | + |
| 74 | + for (const key in fields) { |
| 75 | + const field = fields[key]; |
| 76 | + const base64Value = secret.data?.[key]; |
| 77 | + const value = base64Value ? Base64.decode(secret.data[key]) : undefined; |
| 78 | + |
| 79 | + items.push( |
| 80 | + <> |
| 81 | + <div className="forklift-page-secret-title-div"> |
| 82 | + <Text component={TextVariants.h6} className="forklift-page-secret-title"> |
| 83 | + {field.label} |
| 84 | + </Text> |
| 85 | + <Text component={TextVariants.small} className="forklift-page-secret-subtitle"> |
| 86 | + {field.description} |
| 87 | + </Text> |
| 88 | + </div> |
| 89 | + <div className="forklift-page-secret-content-div"> |
| 90 | + {reveal ? <FieldWithClipboardCopy field={field} value={value} /> : <MaskedField />} |
| 91 | + </div> |
| 92 | + </>, |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + return <>{items}</>; |
| 97 | +}; |
0 commit comments