Skip to content

Commit d663b9f

Browse files
authored
Display configured logger_webhook endpoints (#2279)
1 parent ae14735 commit d663b9f

File tree

10 files changed

+161
-346
lines changed

10 files changed

+161
-346
lines changed

portal-ui/build/asset-manifest.json

Lines changed: 0 additions & 303 deletions
This file was deleted.

portal-ui/build/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

portal-ui/src/screens/Console/NotificationEndpoints/CustomForms/EditConfiguration.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
} from "../../../../systemSlice";
4848
import { useAppDispatch } from "../../../../store";
4949
import Loader from "../../Common/Loader/Loader";
50+
import EndpointDisplay from "./EndpointDisplay";
5051

5152
const styles = (theme: Theme) =>
5253
createStyles({
@@ -82,6 +83,7 @@ const EditConfiguration = ({
8283
const [saving, setSaving] = useState<boolean>(false);
8384
const [loadingConfig, setLoadingConfig] = useState<boolean>(true);
8485
const [configValues, setConfigValues] = useState<IElementValue[]>([]);
86+
const [configSubsysList, setConfigSubsysList] = useState<any>([]);
8587
const [resetConfigurationOpen, setResetConfigurationOpen] =
8688
useState<boolean>(false);
8789

@@ -97,7 +99,8 @@ const EditConfiguration = ({
9799
api
98100
.invoke("GET", `/api/v1/configs/${configId}`)
99101
.then((res) => {
100-
const keyVals = get(res, "key_values", []);
102+
setConfigSubsysList(res);
103+
const keyVals = get(res[0], "key_values", []);
101104
setConfigValues(keyVals);
102105
setLoadingConfig(false);
103106
})
@@ -196,6 +199,13 @@ const EditConfiguration = ({
196199
onChange={onValueChange}
197200
defaultVals={configValues}
198201
/>
202+
{(selectedConfiguration.configuration_id === "logger_webhook" ||
203+
selectedConfiguration.configuration_id === "audit_webhook") && (
204+
<EndpointDisplay
205+
classes={classes}
206+
configSubsysList={configSubsysList}
207+
/>
208+
)}
199209
</Grid>
200210
<Grid
201211
item
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2022 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React, { Fragment, useEffect, useState } from "react";
18+
19+
import { Theme } from "@mui/material/styles";
20+
import createStyles from "@mui/styles/createStyles";
21+
import withStyles from "@mui/styles/withStyles";
22+
23+
import {
24+
fieldBasic,
25+
settingsCommon,
26+
} from "../../Common/FormComponents/common/styleLibrary";
27+
28+
import TableWrapper from "../../Common/TableWrapper/TableWrapper";
29+
30+
const styles = (theme: Theme) =>
31+
createStyles({
32+
...fieldBasic,
33+
...settingsCommon,
34+
settingsFormContainer: {
35+
display: "grid",
36+
gridTemplateColumns: "1fr",
37+
gridGap: "10px",
38+
},
39+
});
40+
41+
interface IEndpointDisplayProps {
42+
// selectedConfiguration: IConfigurationElement;
43+
classes: any;
44+
configSubsysList: any[];
45+
className?: string;
46+
}
47+
48+
const EndpointDisplay = ({
49+
// selectedConfiguration,
50+
classes,
51+
configSubsysList,
52+
className = "",
53+
}: IEndpointDisplayProps) => {
54+
const [configRecords, setConfigRecords] = useState<any>([]);
55+
56+
useEffect(() => {
57+
let records: any[] = [];
58+
if (configSubsysList !== null) {
59+
configSubsysList.forEach((config) => {
60+
if (config.name !== null && config.key_values !== null) {
61+
records.push({
62+
name: config.name,
63+
endpoint: config.key_values[0]["value"],
64+
});
65+
if (config.key_values[0]["value"] === "off") {
66+
records = [];
67+
}
68+
}
69+
});
70+
setConfigRecords(records);
71+
}
72+
}, [configSubsysList]);
73+
74+
return (
75+
<Fragment>
76+
<h3>Currently Configured Endpoints</h3>
77+
78+
<TableWrapper
79+
columns={[
80+
{ label: "Name", elementKey: "name" },
81+
{ label: "Endpoint", elementKey: "endpoint" },
82+
]}
83+
idField="config-id"
84+
isLoading={false}
85+
records={configRecords}
86+
classes={classes}
87+
entityName="endpoints"
88+
/>
89+
</Fragment>
90+
);
91+
};
92+
93+
export default withStyles(styles)(EndpointDisplay);

restapi/admin_config.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package restapi
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"strings"
2324

@@ -113,34 +114,39 @@ func getListConfigResponse(session *models.Principal, params cfgApi.ListConfigPa
113114
// `madmin.Default`. Some configuration sub-systems are multi-target and since
114115
// this function does not accept a target argument, it ignores all non-default
115116
// targets.
116-
func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.ConfigurationKV, error) {
117+
func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.Configuration, error) {
117118
configBytes, err := client.getConfigKV(ctx, name)
118119
if err != nil {
119120
return nil, err
120121
}
121-
122122
subSysConfigs, err := madmin.ParseServerConfigOutput(string(configBytes))
123123
if err != nil {
124124
return nil, err
125125
}
126-
126+
var configSubSysList []*models.Configuration
127127
for _, scfg := range subSysConfigs {
128+
var confkv []*models.ConfigurationKV
129+
for _, kv := range scfg.KV {
130+
// FIXME: Ignoring env-overrides for now as support for this
131+
// needs to be added for presentation.
132+
confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
133+
}
134+
if len(confkv) == 0 {
135+
return nil, errors.New("Invalid SubSystem - check config format")
136+
}
137+
var fullConfigName string
128138
if scfg.Target == "" {
129-
var confkv []*models.ConfigurationKV
130-
for _, kv := range scfg.KV {
131-
// FIXME: Ignoring env-overrides for now as support for this
132-
// needs to be added for presentation.
133-
confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
134-
}
135-
return confkv, nil
139+
fullConfigName = scfg.SubSystem
140+
} else {
141+
fullConfigName = scfg.SubSystem + ":" + scfg.Target
136142
}
143+
configSubSysList = append(configSubSysList, &models.Configuration{KeyValues: confkv, Name: fullConfigName})
137144
}
138-
139-
return nil, fmt.Errorf("unable to find configuration for: %s (default target)", name)
145+
return configSubSysList, nil
140146
}
141147

142148
// getConfigResponse performs getConfig() and serializes it to the handler's output
143-
func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams) (*models.Configuration, *models.Error) {
149+
func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams) ([]*models.Configuration, *models.Error) {
144150
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
145151
defer cancel()
146152
mAdmin, err := NewMinioAdminClient(session)
@@ -151,7 +157,7 @@ func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams
151157
// defining the client to be used
152158
adminClient := AdminClient{Client: mAdmin}
153159

154-
configkv, err := getConfig(ctx, adminClient, params.Name)
160+
configurations, err := getConfig(ctx, adminClient, params.Name)
155161
if err != nil {
156162
errorVal := ErrorWithContext(ctx, err)
157163
minioError := madmin.ToErrorResponse(err)
@@ -160,11 +166,7 @@ func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams
160166
}
161167
return nil, errorVal
162168
}
163-
configurationObj := &models.Configuration{
164-
Name: params.Name,
165-
KeyValues: configkv,
166-
}
167-
return configurationObj, nil
169+
return configurations, nil
168170
}
169171

170172
// setConfig sets a configuration with the defined key values

restapi/admin_config_test.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func Test_getConfig(t *testing.T) {
384384
name string
385385
args args
386386
mock func()
387-
want []*models.ConfigurationKV
387+
want []*models.Configuration
388388
wantErr bool
389389
}{
390390
{
@@ -445,14 +445,18 @@ func Test_getConfig(t *testing.T) {
445445
return mockConfigList, nil
446446
}
447447
},
448-
want: []*models.ConfigurationKV{
448+
want: []*models.Configuration{
449449
{
450-
Key: PostgresConnectionString,
451-
Value: "host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable",
452-
},
453-
{
454-
Key: PostgresTable,
455-
Value: "bucketevents",
450+
KeyValues: []*models.ConfigurationKV{
451+
{
452+
Key: PostgresConnectionString,
453+
Value: "host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable",
454+
},
455+
{
456+
Key: PostgresTable,
457+
Value: "bucketevents",
458+
},
459+
}, Name: "notify_postgres",
456460
},
457461
},
458462
wantErr: false,
@@ -516,7 +520,7 @@ func Test_getConfig(t *testing.T) {
516520
}
517521
},
518522
want: nil,
519-
wantErr: false,
523+
wantErr: true,
520524
},
521525
{
522526
name: "random bytes coming out of getConfigKv",

restapi/embedded_spec.go

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restapi/operations/configuration/config_info.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

restapi/operations/configuration/config_info_responses.go

Lines changed: 11 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger-console.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,9 @@ paths:
21842184
200:
21852185
description: A successful response.
21862186
schema:
2187-
$ref: "#/definitions/configuration"
2187+
type: array
2188+
items:
2189+
$ref: "#/definitions/configuration"
21882190
default:
21892191
description: Generic error response.
21902192
schema:

0 commit comments

Comments
 (0)