|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import { EuiButton, EuiInMemoryTable, EuiIcon } from '@elastic/eui'; |
| 17 | +import React, { useContext, useState } from 'react'; |
| 18 | +import { AppDependencies } from '../../types'; |
| 19 | +import { API_ENDPOINT_AUTHFAILURELISTENERS } from '../constants'; |
| 20 | +import { createRequestContextWithDataSourceId } from '../utils/request-utils'; |
| 21 | +import { SecurityPluginTopNavMenu } from '../top-nav-menu'; |
| 22 | +import { DataSourceContext } from '../app-router'; |
| 23 | +import { getResourceUrl } from '../utils/resource-utils'; |
| 24 | + |
| 25 | +export function AuthFailureListeners(props: AppDependencies) { |
| 26 | + const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled; |
| 27 | + const { dataSource, setDataSource } = useContext(DataSourceContext)!; |
| 28 | + |
| 29 | + const [listeners, setListeners] = useState([]); |
| 30 | + |
| 31 | + const fetchData = async () => { |
| 32 | + const data = await createRequestContextWithDataSourceId(dataSource.id).httpGet<any>({ |
| 33 | + http: props.coreStart.http, |
| 34 | + url: API_ENDPOINT_AUTHFAILURELISTENERS, |
| 35 | + }); |
| 36 | + setListeners(data.data); |
| 37 | + }; |
| 38 | + |
| 39 | + const handleDelete = async (name: string) => { |
| 40 | + await createRequestContextWithDataSourceId(dataSource.id).httpDelete<any>({ |
| 41 | + http: props.coreStart.http, |
| 42 | + url: getResourceUrl(API_ENDPOINT_AUTHFAILURELISTENERS, name), |
| 43 | + }); |
| 44 | + }; |
| 45 | + |
| 46 | + const createDummyAuthFailureListener = async () => { |
| 47 | + await createRequestContextWithDataSourceId(dataSource.id).httpPost<any>({ |
| 48 | + http: props.coreStart.http, |
| 49 | + url: getResourceUrl(API_ENDPOINT_AUTHFAILURELISTENERS, 'test'), |
| 50 | + body: { |
| 51 | + type: 'ip', |
| 52 | + authentication_backend: 'test', |
| 53 | + allowed_tries: 10, |
| 54 | + time_window_seconds: 3600, |
| 55 | + block_expiry_seconds: 600, |
| 56 | + max_blocked_clients: 100000, |
| 57 | + max_tracked_clients: 100000, |
| 58 | + }, |
| 59 | + }); |
| 60 | + }; |
| 61 | + |
| 62 | + const columns = [ |
| 63 | + { |
| 64 | + field: 'name', |
| 65 | + name: 'Name', |
| 66 | + }, |
| 67 | + { |
| 68 | + field: 'type', |
| 69 | + name: 'Type', |
| 70 | + }, |
| 71 | + { |
| 72 | + field: 'authentication_backend', |
| 73 | + name: 'Authentication backend', |
| 74 | + }, |
| 75 | + { |
| 76 | + field: 'allowed_tries', |
| 77 | + name: 'Allowed tries', |
| 78 | + }, |
| 79 | + { |
| 80 | + field: 'time_window_seconds', |
| 81 | + name: 'Time window (sec)', |
| 82 | + }, |
| 83 | + { |
| 84 | + field: 'block_expiry_seconds', |
| 85 | + name: 'Block expiry (sec)', |
| 86 | + }, |
| 87 | + { |
| 88 | + field: 'max_blocked_clients', |
| 89 | + name: 'Max blocked clients', |
| 90 | + }, |
| 91 | + { |
| 92 | + field: 'max_tracked_clients', |
| 93 | + name: 'Max tracked clients', |
| 94 | + }, |
| 95 | + { |
| 96 | + field: 'name', |
| 97 | + name: 'Actions', |
| 98 | + render: (name) => <EuiIcon type="trash" onClick={() => handleDelete(name)} />, |
| 99 | + }, |
| 100 | + ]; |
| 101 | + |
| 102 | + return ( |
| 103 | + <> |
| 104 | + <div className="panel-restrict-width"> |
| 105 | + <SecurityPluginTopNavMenu |
| 106 | + {...props} |
| 107 | + dataSourcePickerReadOnly={false} |
| 108 | + setDataSource={setDataSource} |
| 109 | + selectedDataSource={dataSource} |
| 110 | + /> |
| 111 | + </div> |
| 112 | + <EuiButton onClick={fetchData}>GET</EuiButton> |
| 113 | + <EuiInMemoryTable |
| 114 | + tableLayout={'auto'} |
| 115 | + columns={columns} |
| 116 | + items={listeners} |
| 117 | + itemId={'domain_name'} |
| 118 | + pagination={true} |
| 119 | + sorting={true} |
| 120 | + /> |
| 121 | + |
| 122 | + <EuiButton onClick={createDummyAuthFailureListener}>CREATE</EuiButton> |
| 123 | + </> |
| 124 | + ); |
| 125 | +} |
0 commit comments