/* * Copyright OpenSearch Contributors * * 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://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file 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 { EuiButton, EuiCode, EuiDescribedFormGroup, EuiFlexGroup, EuiFlexItem, EuiForm, EuiFormRow, EuiHorizontalRule, EuiPanel, EuiSpacer, EuiSwitch, EuiText, EuiTitle, } from '@elastic/eui'; import React from 'react'; import { FormattedMessage } from '@osd/i18n/react'; import { AppDependencies } from '../../../types'; import { ResourceType } from '../../types'; import { getAuditLogging, updateAuditLogging } from '../../utils/audit-logging-utils'; import { displayBoolean, ExternalLink } from '../../utils/display-utils'; import { buildHashUrl } from '../../utils/url-builder'; import { SETTING_GROUPS, SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT, SUB_URL_FOR_GENERAL_SETTINGS_EDIT, } from './constants'; import { AuditLoggingSettings } from './types'; import { ViewSettingGroup } from './view-setting-group'; import { DocLinks } from '../../constants'; interface AuditLoggingProps extends AppDependencies { fromType: string; } function renderStatusPanel(onSwitchChange: () => void, auditLoggingEnabled: boolean) { return (

Audit logging

Storage location} className="described-form-group"> opensearch.yml, internalOpenSearchCode: internal_opensearch, }} />{' '} Enable audit logging} className="described-form-group" >
); } export function renderGeneralSettings(config: AuditLoggingSettings) { return ( <> ); } export function renderComplianceSettings(config: AuditLoggingSettings) { return ( <> ); } export function AuditLogging(props: AuditLoggingProps) { const [configuration, setConfiguration] = React.useState({}); const onSwitchChange = async () => { try { const updatedConfiguration = { ...configuration }; updatedConfiguration.enabled = !updatedConfiguration.enabled; await updateAuditLogging(props.coreStart.http, updatedConfiguration); setConfiguration(updatedConfiguration); } catch (e) { console.error(e); } }; React.useEffect(() => { const fetchData = async () => { try { const auditLogging = await getAuditLogging(props.coreStart.http); setConfiguration(auditLogging); } catch (e) { // TODO: switch to better error handling. console.log(e); } }; fetchData(); }, [props.coreStart.http, props.fromType]); const statusPanel = renderStatusPanel(onSwitchChange, configuration.enabled || false); let content; if (!configuration.enabled) { content = statusPanel; } else { content = ( <> {statusPanel}

General settings

{ window.location.href = buildHashUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT; }} > Configure
{renderGeneralSettings(configuration)}

Compliance settings

{ window.location.href = buildHashUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT; }} > Configure
{renderComplianceSettings(configuration)}
); } return
{content}
; }