Display configured logger_webhook endpoints (#2279)

This commit is contained in:
jinapurapu
2022-09-01 13:23:55 -07:00
committed by GitHub
parent ae147358b1
commit d663b9f346
10 changed files with 162 additions and 347 deletions

View File

@@ -18,6 +18,7 @@ package restapi
import (
"context"
"errors"
"fmt"
"strings"
@@ -113,34 +114,39 @@ func getListConfigResponse(session *models.Principal, params cfgApi.ListConfigPa
// `madmin.Default`. Some configuration sub-systems are multi-target and since
// this function does not accept a target argument, it ignores all non-default
// targets.
func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.ConfigurationKV, error) {
func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.Configuration, error) {
configBytes, err := client.getConfigKV(ctx, name)
if err != nil {
return nil, err
}
subSysConfigs, err := madmin.ParseServerConfigOutput(string(configBytes))
if err != nil {
return nil, err
}
var configSubSysList []*models.Configuration
for _, scfg := range subSysConfigs {
if scfg.Target == "" {
var confkv []*models.ConfigurationKV
for _, kv := range scfg.KV {
// FIXME: Ignoring env-overrides for now as support for this
// needs to be added for presentation.
confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
}
return confkv, nil
var confkv []*models.ConfigurationKV
for _, kv := range scfg.KV {
// FIXME: Ignoring env-overrides for now as support for this
// needs to be added for presentation.
confkv = append(confkv, &models.ConfigurationKV{Key: kv.Key, Value: kv.Value})
}
if len(confkv) == 0 {
return nil, errors.New("Invalid SubSystem - check config format")
}
var fullConfigName string
if scfg.Target == "" {
fullConfigName = scfg.SubSystem
} else {
fullConfigName = scfg.SubSystem + ":" + scfg.Target
}
configSubSysList = append(configSubSysList, &models.Configuration{KeyValues: confkv, Name: fullConfigName})
}
return nil, fmt.Errorf("unable to find configuration for: %s (default target)", name)
return configSubSysList, nil
}
// getConfigResponse performs getConfig() and serializes it to the handler's output
func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams) (*models.Configuration, *models.Error) {
func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams) ([]*models.Configuration, *models.Error) {
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
defer cancel()
mAdmin, err := NewMinioAdminClient(session)
@@ -151,7 +157,7 @@ func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams
// defining the client to be used
adminClient := AdminClient{Client: mAdmin}
configkv, err := getConfig(ctx, adminClient, params.Name)
configurations, err := getConfig(ctx, adminClient, params.Name)
if err != nil {
errorVal := ErrorWithContext(ctx, err)
minioError := madmin.ToErrorResponse(err)
@@ -160,11 +166,7 @@ func getConfigResponse(session *models.Principal, params cfgApi.ConfigInfoParams
}
return nil, errorVal
}
configurationObj := &models.Configuration{
Name: params.Name,
KeyValues: configkv,
}
return configurationObj, nil
return configurations, nil
}
// setConfig sets a configuration with the defined key values

View File

@@ -384,7 +384,7 @@ func Test_getConfig(t *testing.T) {
name string
args args
mock func()
want []*models.ConfigurationKV
want []*models.Configuration
wantErr bool
}{
{
@@ -445,14 +445,18 @@ func Test_getConfig(t *testing.T) {
return mockConfigList, nil
}
},
want: []*models.ConfigurationKV{
want: []*models.Configuration{
{
Key: PostgresConnectionString,
Value: "host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable",
},
{
Key: PostgresTable,
Value: "bucketevents",
KeyValues: []*models.ConfigurationKV{
{
Key: PostgresConnectionString,
Value: "host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable",
},
{
Key: PostgresTable,
Value: "bucketevents",
},
}, Name: "notify_postgres",
},
},
wantErr: false,
@@ -516,7 +520,7 @@ func Test_getConfig(t *testing.T) {
}
},
want: nil,
wantErr: false,
wantErr: true,
},
{
name: "random bytes coming out of getConfigKv",

View File

@@ -2543,7 +2543,10 @@ func init() {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/configuration"
"type": "array",
"items": {
"$ref": "#/definitions/configuration"
}
}
},
"default": {
@@ -9683,7 +9686,10 @@ func init() {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/configuration"
"type": "array",
"items": {
"$ref": "#/definitions/configuration"
}
}
},
"default": {

View File

@@ -63,7 +63,7 @@ func (o *ConfigInfo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
if rCtx != nil {
*r = *rCtx
}
var Params = NewConfigInfoParams()
Params := NewConfigInfoParams()
uprinc, aCtx, err := o.Context.Authorize(r, route)
if err != nil {
o.Context.Respond(rw, r, route.Produces, route, err)
@@ -84,5 +84,4 @@ func (o *ConfigInfo) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
res := o.Handler.Handle(Params, principal) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@@ -43,7 +43,7 @@ type ConfigInfoOK struct {
/*
In: Body
*/
Payload *models.Configuration `json:"body,omitempty"`
Payload []*models.Configuration `json:"body,omitempty"`
}
// NewConfigInfoOK creates ConfigInfoOK with default headers values
@@ -53,13 +53,13 @@ func NewConfigInfoOK() *ConfigInfoOK {
}
// WithPayload adds the payload to the config info o k response
func (o *ConfigInfoOK) WithPayload(payload *models.Configuration) *ConfigInfoOK {
func (o *ConfigInfoOK) WithPayload(payload []*models.Configuration) *ConfigInfoOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the config info o k response
func (o *ConfigInfoOK) SetPayload(payload *models.Configuration) {
func (o *ConfigInfoOK) SetPayload(payload []*models.Configuration) {
o.Payload = payload
}
@@ -67,11 +67,14 @@ func (o *ConfigInfoOK) SetPayload(payload *models.Configuration) {
func (o *ConfigInfoOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
payload := o.Payload
if payload == nil {
// return empty array
payload = make([]*models.Configuration, 0, 50)
}
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}