-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathLoggingPage.js
More file actions
222 lines (203 loc) · 8.03 KB
/
LoggingPage.js
File metadata and controls
222 lines (203 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import React, { useEffect, useState, useMemo, useCallback } from 'react'
import { Form, FormGroup, Card, CardBody, Col, CustomInput, Row } from 'Components'
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import GluuViewWrapper from 'Routes/Apps/Gluu/GluuViewWrapper'
import GluuCommitDialog from 'Routes/Apps/Gluu/GluuCommitDialog'
import GluuCommitFooter from 'Routes/Apps/Gluu/GluuCommitFooter'
import { JSON_CONFIG } from 'Utils/ApiResources'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import { useDispatch, useSelector } from 'react-redux'
import { Formik } from 'formik'
import {
getLoggingConfig,
editLoggingConfig,
} from 'Plugins/auth-server/redux/features/loggingSlice'
import { LOGGING_READ, LOGGING_WRITE } from 'Utils/PermChecker'
import { useCedarling } from '@/cedarling'
import { useTranslation } from 'react-i18next'
import SetTitle from 'Utils/SetTitle'
import GluuToogleRow from 'Routes/Apps/Gluu/GluuToogleRow'
import { getChangedFields, getMergedValues } from '@/helpers'
function LoggingPage() {
const { t } = useTranslation()
const { hasCedarPermission, authorize } = useCedarling()
const logging = useSelector((state) => state.loggingReducer.logging)
const loading = useSelector((state) => state.loggingReducer.loading)
const { permissions: cedarPermissions } = useSelector((state) => state.cedarPermissions)
const dispatch = useDispatch()
const [showCommitDialog, setShowCommitDialog] = useState(false)
const [pendingValues, setPendingValues] = useState(null)
const [localLogging, setLocalLogging] = useState(null)
useEffect(() => {
const initPermissions = async () => {
const permissions = [LOGGING_READ, LOGGING_WRITE]
for (const permission of permissions) {
await authorize([permission])
}
}
initPermissions()
dispatch(getLoggingConfig())
}, [dispatch, authorize])
useEffect(() => {
if (logging) {
setLocalLogging(logging)
}
}, [logging])
useEffect(() => {}, [cedarPermissions])
const initialValues = useMemo(
() => ({
loggingLevel: localLogging?.loggingLevel,
loggingLayout: localLogging?.loggingLayout,
httpLoggingEnabled: localLogging?.httpLoggingEnabled,
disableJdkLogger: localLogging?.disableJdkLogger,
enabledOAuthAuditLogging: localLogging?.enabledOAuthAuditLogging,
}),
[localLogging],
)
const levels = useMemo(() => ['TRACE', 'DEBUG', 'INFO', 'ERROR', 'WARN'], [])
const logLayouts = useMemo(() => ['text', 'json'], [])
SetTitle('Logging')
const handleSubmit = useCallback(
(values) => {
const mergedValues = getMergedValues(localLogging, values)
const changedFields = getChangedFields(localLogging, mergedValues)
setPendingValues({ mergedValues, changedFields })
setShowCommitDialog(true)
},
[localLogging],
)
const handleAccept = useCallback(
(userMessage) => {
if (pendingValues) {
const { mergedValues, changedFields } = pendingValues
const opts = {}
opts['logging'] = JSON.stringify(mergedValues)
dispatch(
editLoggingConfig({
data: opts,
otherFields: { userMessage, changedFields },
}),
)
setShowCommitDialog(false)
setPendingValues(null)
}
},
[pendingValues, dispatch],
)
return (
<GluuLoader blocking={loading}>
<Card style={applicationStyle.mainCard}>
<CardBody style={{ minHeight: 500 }}>
<GluuViewWrapper canShow={hasCedarPermission(LOGGING_READ)}>
<Formik initialValues={initialValues} enableReinitialize onSubmit={handleSubmit}>
{(formik) => (
<Form onSubmit={formik.handleSubmit}>
<FormGroup row>
<GluuLabel
label="fields.log_level"
size={4}
doc_category={JSON_CONFIG}
doc_entry="loggingLevel"
/>
<Col sm={8}>
<CustomInput
type="select"
id="loggingLevel"
name="loggingLevel"
data-testid="loggingLevel"
value={formik.values.loggingLevel}
onChange={(e) => formik.setFieldValue('loggingLevel', e.target.value)}
>
<option value="">{t('actions.choose')}...</option>
{levels.map((item, key) => (
<option value={item} key={key}>
{item}
</option>
))}
</CustomInput>
</Col>
</FormGroup>
<FormGroup row>
<GluuLabel
label="fields.log_layout"
size={4}
doc_category={JSON_CONFIG}
doc_entry="loggingLayout"
/>
<Col sm={8}>
<CustomInput
type="select"
id="loggingLayout"
name="loggingLayout"
data-testid="loggingLayout"
value={formik.values.loggingLayout}
onChange={(e) => formik.setFieldValue('loggingLayout', e.target.value)}
>
<option value="">{t('actions.choose')}...</option>
{logLayouts.map((item, key) => (
<option value={item} key={key}>
{item}
</option>
))}
</CustomInput>
</Col>
</FormGroup>
<GluuToogleRow
label="fields.http_logging_enabled"
name="httpLoggingEnabled"
handler={(e) => formik.setFieldValue('httpLoggingEnabled', e.target.checked)}
lsize={5}
rsize={7}
value={formik.values.httpLoggingEnabled}
doc_category={JSON_CONFIG}
/>
<GluuToogleRow
label="fields.disable_jdk_logger"
name="disableJdkLogger"
handler={(e) => formik.setFieldValue('disableJdkLogger', e.target.checked)}
lsize={5}
rsize={7}
doc_category={JSON_CONFIG}
value={formik.values.disableJdkLogger}
/>
<GluuToogleRow
label="fields.enabled_oAuth_audit_logging"
name="enabledOAuthAuditLogging"
handler={(e) =>
formik.setFieldValue('enabledOAuthAuditLogging', e.target.checked)
}
lsize={5}
rsize={7}
doc_category={JSON_CONFIG}
value={formik.values.enabledOAuthAuditLogging}
/>
{hasCedarPermission(LOGGING_WRITE) && (
<Row>
<Col>
<GluuCommitFooter
saveHandler={formik.handleSubmit}
extraLabel={t('actions.cancel')}
extraOnClick={() => formik.resetForm()}
hideButtons={{ save: true, back: true }}
type="submit"
/>
</Col>
</Row>
)}
</Form>
)}
</Formik>
<GluuCommitDialog
handler={() => setShowCommitDialog(false)}
modal={showCommitDialog}
onAccept={handleAccept}
isLicenseLabel={false}
/>
</GluuViewWrapper>
</CardBody>
</Card>
</GluuLoader>
)
}
export default LoggingPage