/* 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. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React, { useState, useEffect } from "react"; import HeaderPanel from "components/HeaderPanel"; import PagePanel from "components/PagePanel"; import Tiles from "components/Tiles"; import Alert from "components/Alert"; import { CreateLogMethod, ENABLE_RDS_LOGS_LINK, RDSTypes, RDS_LOG_GROUP_SUFFIX_AUDIT, RDS_LOG_GROUP_SUFFIX_ERROR, RDS_LOG_GROUP_SUFFIX_GENERAL, RDS_LOG_GROUP_SUFFIX_SLOWQUERY, RDS_TASK_GROUP_PREFIX, RDS_TYPE_LIST, } from "assets/js/const"; import FormItem from "components/FormItem"; import { SelectItem } from "components/Select/select"; import { appSyncRequestQuery } from "assets/js/request"; import { LoggingBucket, Resource, ResourceType } from "API"; import { getResourceLoggingBucket, listResources } from "graphql/queries"; import AutoComplete from "components/AutoComplete"; import { RDSTaskProps } from "../CreateRDS"; import { OptionType } from "components/AutoComplete/autoComplete"; import TextInput from "components/TextInput"; import Select from "components/Select"; import { AlertType } from "components/Alert/alert"; import ExtLink from "components/ExtLink"; import { AmplifyConfigType } from "types"; import { useSelector } from "react-redux"; import { AppStateProps, InfoBarTypes } from "reducer/appReducer"; import { buildRDSLink } from "assets/js/utils"; import { useTranslation } from "react-i18next"; import CrossAccountSelect from "pages/comps/account/CrossAccountSelect"; interface SpecifySettingsProps { rdsTask: RDSTaskProps; changeTaskType: (type: string) => void; changeS3Bucket: (bucket: string) => void; changeRDSObj: (rds: OptionType | null) => void; errorLogEnabled: (enable: boolean) => void; queryLogEnabled: (enable: boolean) => void; generalLogEnabled: (enable: boolean) => void; auditLogEnabled: (enable: boolean) => void; manualChangeDBIdentifier: (bucket: string) => void; manualChangeDBType: (type: string) => void; changeErrorARN: (arn: string) => void; changeQeuryARN: (arn: string) => void; changeGeneralARN: (arn: string) => void; changeAuditARN: (arn: string) => void; autoRDSEmptyError: boolean; manualRDSEmptyError: boolean; setNextStepDisableStatus: (status: boolean) => void; setISChanging: (changing: boolean) => void; changeRDSBucket: (bucket: string, prefix: string) => void; changeCrossAccount: (id: string) => void; } const SpecifySettings: React.FC = ( props: SpecifySettingsProps ) => { const { rdsTask, changeRDSObj, errorLogEnabled, queryLogEnabled, generalLogEnabled, auditLogEnabled, manualChangeDBIdentifier, manualChangeDBType, changeErrorARN, changeQeuryARN, changeGeneralARN, changeAuditARN, // changeS3Bucket, changeTaskType, autoRDSEmptyError, manualRDSEmptyError, // setNextStepDisableStatus, setISChanging, changeRDSBucket, changeCrossAccount, } = props; const amplifyConfig: AmplifyConfigType = useSelector( (state: AppStateProps) => state.amplifyConfig ); const { t } = useTranslation(); const [loadingRDSList, setLoadingRDSList] = useState(false); const [rdsOptionList, setRDSOptionList] = useState([]); const [showLogTypes, setShowLogTypes] = useState(false); const [disabeRDS, setDisableRDS] = useState(false); const getRDSList = async (accountId: string) => { try { setLoadingRDSList(true); const resData: any = await appSyncRequestQuery(listResources, { type: ResourceType.RDS, accountId: accountId, }); console.info("getRDSList:", resData.data); const dataList: Resource[] = resData.data.listResources; const tmpOptionList: SelectItem[] = []; dataList.forEach((element) => { tmpOptionList.push({ name: `${element.name}`, value: element.id, description: element.description || "", }); }); setRDSOptionList(tmpOptionList); setLoadingRDSList(false); } catch (error) { console.error(error); } }; const getRDSBucketPrefix = async (rdsId: string) => { setISChanging(true); const resData: any = await appSyncRequestQuery(getResourceLoggingBucket, { type: ResourceType.RDS, resourceName: rdsId, accountId: rdsTask.logSourceAccountId, }); console.info("getBucketPrefix:", resData.data); const logginBucket: LoggingBucket = resData?.data?.getResourceLoggingBucket; changeRDSBucket(logginBucket?.bucket || "", logginBucket.prefix || ""); setISChanging(false); }; useEffect(() => { if (rdsTask.params.taskType === CreateLogMethod.Automatic) { getRDSList(rdsTask.logSourceAccountId); } }, [rdsTask.logSourceAccountId]); useEffect(() => { if (rdsTask.params.rdsObj?.value) { setShowLogTypes(true); // get rds bucket info getRDSBucketPrefix(rdsTask.params.rdsObj.value); } else { setShowLogTypes(false); } }, [rdsTask.params.rdsObj]); return (
{ changeTaskType(event.target.value); changeRDSObj(null); }} items={[ { label: t("servicelog:rds.auto"), description: t("servicelog:rds.autoDesc"), value: CreateLogMethod.Automatic, }, { label: t("servicelog:rds.manual"), description: t("servicelog:rds.manualDesc"), value: CreateLogMethod.Manual, }, ]} />
{showLogTypes && ( {t("servicelog:rds.enableAlert1")} {t("servicelog:rds.enableAlert2")} .
} /> )} { changeCrossAccount(id); changeRDSObj(null); }} loadingAccount={(loading) => { setDisableRDS(loading); }} /> {rdsTask.params.taskType === CreateLogMethod.Automatic && (
{t("servicelog:rds.selectDB")} {t("servicelog:rds.curAccount")} .
} errorText={ autoRDSEmptyError ? t("servicelog:rds.dbError") : "" } > , data ) => { changeRDSObj(data); }} /> {showLogTypes && (
)}
)} {rdsTask.params.taskType === CreateLogMethod.Manual && (
{ manualChangeDBIdentifier(event.target.value); }} onBlur={(event) => { getRDSBucketPrefix(event.target.value); }} /> { errorLogEnabled(event.target.checked); }} /> {t("servicelog:rds.errorLog")}
{ console.info("event:", event); changeErrorARN(event.target.value); }} />
{ console.info("event:", event); changeQeuryARN(event.target.value); }} />
{ console.info("event:", event); changeGeneralARN(event.target.value); }} />
{ console.info("event:", event); changeAuditARN(event.target.value); }} />
)} ); }; export default SpecifySettings;