// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance // with the License. A copy of the License is located at // // http://aws.amazon.com/apache2.0/ // // or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES // OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and // limitations under the License. // Fameworks import * as React from 'react' // UI Elements import { Button, Container, ExpandableSection, FormField, Header, Input, SpaceBetween, CheckboxProps, Link, } from '@cloudscape-design/components' // State import {setState, useState, getState, clearState} from '../../store' // Components import {CheckboxWithHelpPanel, HelpTextInput} from './Components' import {Trans, useTranslation} from 'react-i18next' import TitleDescriptionHelpPanel from '../../components/help-panel/TitleDescriptionHelpPanel' import InfoLink from '../../components/InfoLink' import {NonCancelableEventHandler} from '@cloudscape-design/components/internal/events' // Constants const errorsPath = ['app', 'wizard', 'errors', 'multiUser'] const dsPath = ['app', 'wizard', 'config', 'DirectoryService'] const generateSshKeysPath = [...dsPath, 'GenerateSshKeysForUsers'] function multiUserValidate() { let valid = true const checkRequired = (key: any) => { const value = getState([...dsPath, key]) if (!value || value === '') { console.log('invalid: ', key, 'setting: ', [...errorsPath, key]) setState([...errorsPath, key], `You must specify a value for ${key}.`) valid = false } else { clearState([...errorsPath, key]) } } checkRequired('DomainName') checkRequired('DomainAddr') checkRequired('PasswordSecretArn') checkRequired('DomainReadOnlyUser') return valid } function AdditionalSssdOptions() { const {t} = useTranslation() let additionalSssdConfigsErrors = useState([ ...errorsPath, 'additionalSssdConfigs', ]) let additionalSssdConfigs = useState([...dsPath, 'AdditionalSssdConfigs']) || {} let key = useState(['app', 'wizard', 'multiUser', 'key']) let value = useState(['app', 'wizard', 'multiUser', 'value']) const addConfig = () => { if (!key || !value || key === '' || value === '') { setState( [...errorsPath, 'additionalSssdConfigs'], t('wizard.cluster.multiUser.sssdParameters.validation'), ) } else { setState([...dsPath, 'AdditionalSssdConfigs', key || ''], value || '') clearState([...errorsPath, 'additionalSssdConfigs']) } } const removeConfig = (key: any) => { let config = {...additionalSssdConfigs} delete config[key] if (Object.keys(config).length === 0) clearState([...dsPath, 'AdditionalSssdConfigs']) else setState([...dsPath, 'AdditionalSssdConfigs'], config) } return ( <> setState(['app', 'wizard', 'multiUser', 'key'], detail.value) } /> setState(['app', 'wizard', 'multiUser', 'value'], detail.value) } /> {Object.keys(additionalSssdConfigs).map((key, index) => (
{key}: {String(additionalSssdConfigs[key])}
))}
) } function MultiUser() { const {t} = useTranslation() const generateSshKeys = useState(generateSshKeysPath) const onGenerateSshKeysChange: NonCancelableEventHandler = React.useCallback(({detail}) => { setState(generateSshKeysPath, detail.checked) }, []) React.useEffect(() => { if (generateSshKeys === null) setState(generateSshKeysPath, true) }, [generateSshKeys]) return ( } />} > {t('wizard.cluster.multiUser.title')} } > { setState([...dsPath, 'DomainName'], detail.value) }} /> { setState([...dsPath, 'DomainAddr'], detail.value) }} /> { setState([...dsPath, 'PasswordSecretArn'], detail.value) }} /> { setState([...dsPath, 'DomainReadOnlyUser'], detail.value) }} /> { setState([...dsPath, 'LdapTlsCaCert'], detail.value) }} /> { setState([...dsPath, 'LdapTlsReqCert'], detail.value) }} /> { setState([...dsPath, 'LdapAccessFilter'], detail.value) }} /> } /> } > {t('wizard.cluster.multiUser.generateSSHKeys.name')} ) } export const MultiUserHelpPanel = () => { const {t} = useTranslation() const footerLinks = React.useMemo( () => [ { title: t('wizard.cluster.multiUser.multiUserAccessLink.title'), href: t('wizard.cluster.multiUser.multiUserAccessLink.href'), }, { title: t('wizard.cluster.multiUser.directoryServiceLink.title'), href: t('wizard.cluster.multiUser.directoryServiceLink.href'), }, ], [t], ) return ( } footerLinks={footerLinks} /> ) } export {MultiUser, multiUserValidate}