[Security] Add readOnly, writeOnly button in create api key flyout (#181615)

## Summary
Add ready only and write only button to show privileges in code editor
in API key section in Serverless project and Stack

**Stack**


13081d62-256f-44be-8f23-a907e52e60c9

**Serverless**


eb337ccc-a0d0-448e-8355-3157c18d123a







### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
This commit is contained in:
Saarika Bhasi 2024-04-26 10:45:35 -04:00 committed by GitHub
parent 21585c156c
commit 91cfb36040
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -137,6 +137,29 @@ const defaultInitialValues: ApiKeyFormValues = {
role_descriptors: '{}',
};
const READ_ONLY_BOILERPLATE = `{
"read-only-role": {
"cluster": [],
"indices": [
{
"names": ["*"],
"privileges": ["read"]
}
]
}
}`;
const WRITE_ONLY_BOILERPLATE = `{
"write-only-role": {
"cluster": [],
"indices": [
{
"names": ["*"],
"privileges": ["write"]
}
]
}
}`;
export const ApiKeyFlyout: FunctionComponent<ApiKeyFlyoutProps> = ({
onSuccess,
onCancel,
@ -704,6 +727,57 @@ export const ApiKeyFlyout: FunctionComponent<ApiKeyFlyoutProps> = ({
{formik.values.customPrivileges && (
<>
<EuiSpacer />
<EuiPanel hasShadow={false} color="subdued">
<EuiFlexGroup
gutterSize="none"
justifyContent="flexEnd"
alignItems="baseline"
>
<EuiFlexItem grow={false}>
<EuiText size="xs">
<h4>
{i18n.translate(
'xpack.security.apiKey.privileges.boilerplate.label',
{
defaultMessage: 'Replace with boilerplate:',
}
)}
</h4>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
data-test-subj="apiKeysReadOnlyDescriptors"
onClick={() =>
formik.setFieldValue('role_descriptors', READ_ONLY_BOILERPLATE)
}
>
{i18n.translate(
'xpack.security.apiKeys.apiKeyFlyout.roleDescriptors.readOnlyLabel',
{
defaultMessage: 'Read-only',
}
)}
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonEmpty
data-test-subj="apiKeysWriteOnlyDescriptors"
onClick={() =>
formik.setFieldValue('role_descriptors', WRITE_ONLY_BOILERPLATE)
}
>
{i18n.translate(
'xpack.security.management.apiKeys.apiKeyFlyout.roleDescriptors.writeOnlyLabel',
{
defaultMessage: 'Write-only',
}
)}
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
<FormRow
helpText={
<DocLink