Skip to content

Commit

Permalink
check if rbac is enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Muthukaruppan <[email protected]>
  • Loading branch information
smuthukaruppannp committed Apr 18, 2024
1 parent 00aa50a commit b32b507
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
RECOMMENDED_DURATION,
} from '../../components/QueryPerformance/QueryPerformance';
import MonitorSecurity from '../MonitorSecurity';
import { FILTER_BY_BACKEND_ROLES_SETTING_PATH } from './utils/constants';

export default class CreateMonitor extends Component {
static defaultProps = {
Expand Down Expand Up @@ -58,16 +59,47 @@ export default class CreateMonitor extends Component {
triggerToEdit,
createModalOpen: false,
formikBag: undefined,
filterByBackendRolesEnabled: false,
};

this.onCancel = this.onCancel.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.evaluateSubmission = this.evaluateSubmission.bind(this);
this.getSettings = this.getSettings.bind(this);
}

async getSettings() {
try {
const { httpClient } = this.props;
const response = await httpClient.get('../api/alerting/_settings');
if (response.ok) {
const { defaults, transient, persistent } = response.resp;
let filterByBackendRolesEnabled = _.get(
// If present, take the 'transient' setting.
transient,
FILTER_BY_BACKEND_ROLES_SETTING_PATH,
// Else take the 'persistent' setting.
_.get(
persistent,
FILTER_BY_BACKEND_ROLES_SETTING_PATH,
// Else take the 'default' setting.
_.get(defaults, FILTER_BY_BACKEND_ROLES_SETTING_PATH, false)
)
);
// Boolean settings are returned as strings (e.g., `"true"`, and `"false"`). Constructing boolean value from the string.
if (typeof filterByBackendRolesEnabled === 'string')
filterByBackendRolesEnabled = JSON.parse(filterByBackendRolesEnabled);
this.setState({ filterByBackendRolesEnabled: filterByBackendRolesEnabled });
}
} catch (e) {
console.log('Error while retrieving settings', e);
}
}

componentDidMount() {
const { httpClient } = this.props;

this.getSettings();
const updatePlugins = async () => {
const newPlugins = await getPlugins(httpClient);
this.setState({ plugins: newPlugins });
Expand Down Expand Up @@ -163,7 +195,7 @@ export default class CreateMonitor extends Component {
isDarkMode,
notificationService,
} = this.props;
const { createModalOpen, initialValues, plugins } = this.state;
const { createModalOpen, initialValues, plugins, filterByBackendRolesEnabled } = this.state;

return (
<div style={{ padding: '25px 50px' }}>
Expand Down Expand Up @@ -205,6 +237,11 @@ export default class CreateMonitor extends Component {
httpClient={httpClient}
errors={errors}
/>
</>
) : null}

{isComposite && filterByBackendRolesEnabled ? (
<>
<EuiSpacer />
<MonitorSecurity values={values} httpClient={httpClient} errors={errors} />
</>
Expand Down
22 changes: 19 additions & 3 deletions public/pages/CreateMonitor/containers/MonitorRoles/MonitorRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
import { EuiHealth, EuiHighlight } from '@elastic/eui';
import { EuiHealth, EuiHighlight, EuiText, EuiLink } from '@elastic/eui';

import { FormikComboBox } from '../../../../components/FormControls';
import { createReasonableWait } from '../MonitorIndex/utils/helpers';
Expand Down Expand Up @@ -93,8 +93,24 @@ class MonitorRoles extends React.Component {
name="roles"
formRow
rowProps={{
label: 'Backend roles',
helpText: 'You can optionally assign one or more backend roles to the monitor',
label: (
<div>
<EuiText size={'xs'}>
<strong>Backend roles</strong>
<i> - optional </i>
</EuiText>
<EuiText color={'subdued'} size={'xs'} style={{ width: '400px' }}>
Specify role-based access control (RBAC) backend roles.{' '}
<EuiLink
external
href={'https://opensearch.org/docs/latest/observing-your-data/alerting/security/'}
target={'_blank'}
>
Learn more
</EuiLink>
</EuiText>
</div>
),
style: { paddingLeft: '10px' },
}}
inputProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import MonitorRoles from '../MonitorRoles';
import ContentPanel from '../../../../components/ContentPanel';

const propTypes = {
values: PropTypes.object.isRequired,
httpClient: PropTypes.object.isRequired,
isMinimal: PropTypes.bool,
};
Expand Down

0 comments on commit b32b507

Please sign in to comment.