From 5755b98b66cccfb13d82c336a81619837a8e8494 Mon Sep 17 00:00:00 2001 From: Daniel Valdivia Date: Thu, 9 Apr 2020 16:07:26 -0700 Subject: [PATCH] API to list and add Notification Endpoints (#50) --- models/add_notification_endpoint.go | 147 +++++++ models/nofitication_service.go | 104 +++++ models/notif_endpoint_response.go | 97 +++++ models/notification_endpoint.go | 114 +++++ models/notification_endpoint_item.go | 92 ++++ restapi/admin_config.go | 33 +- restapi/admin_config_test.go | 165 ++++++- restapi/admin_notification_endpoints.go | 173 ++++++++ restapi/admin_notification_endpoints_test.go | 411 ++++++++++++++++++ restapi/configure_mcs.go | 2 + restapi/embedded_spec.go | 232 ++++++++++ .../admin_api/add_notification_endpoint.go | 90 ++++ .../add_notification_endpoint_parameters.go | 94 ++++ .../add_notification_endpoint_responses.go | 133 ++++++ .../add_notification_endpoint_urlbuilder.go | 104 +++++ .../admin_api/notification_endpoint_list.go | 90 ++++ .../notification_endpoint_list_parameters.go | 62 +++ .../notification_endpoint_list_responses.go | 133 ++++++ .../notification_endpoint_list_urlbuilder.go | 104 +++++ restapi/operations/mcs_api.go | 24 + swagger.yml | 79 ++++ 21 files changed, 2457 insertions(+), 26 deletions(-) create mode 100644 models/add_notification_endpoint.go create mode 100644 models/nofitication_service.go create mode 100644 models/notif_endpoint_response.go create mode 100644 models/notification_endpoint.go create mode 100644 models/notification_endpoint_item.go create mode 100644 restapi/admin_notification_endpoints.go create mode 100644 restapi/admin_notification_endpoints_test.go create mode 100644 restapi/operations/admin_api/add_notification_endpoint.go create mode 100644 restapi/operations/admin_api/add_notification_endpoint_parameters.go create mode 100644 restapi/operations/admin_api/add_notification_endpoint_responses.go create mode 100644 restapi/operations/admin_api/add_notification_endpoint_urlbuilder.go create mode 100644 restapi/operations/admin_api/notification_endpoint_list.go create mode 100644 restapi/operations/admin_api/notification_endpoint_list_parameters.go create mode 100644 restapi/operations/admin_api/notification_endpoint_list_responses.go create mode 100644 restapi/operations/admin_api/notification_endpoint_list_urlbuilder.go diff --git a/models/add_notification_endpoint.go b/models/add_notification_endpoint.go new file mode 100644 index 000000000..181c0b590 --- /dev/null +++ b/models/add_notification_endpoint.go @@ -0,0 +1,147 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// AddNotificationEndpoint add notification endpoint +// +// swagger:model addNotificationEndpoint +type AddNotificationEndpoint struct { + + // account + Account string `json:"account,omitempty"` + + // properties + Properties map[string]string `json:"properties,omitempty"` + + // service + // Enum: [webhook amqp kafka mqtt nats nsq mysql postgres elasticsearch redis] + Service string `json:"service,omitempty"` +} + +// Validate validates this add notification endpoint +func (m *AddNotificationEndpoint) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateService(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var addNotificationEndpointTypeServicePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["webhook","amqp","kafka","mqtt","nats","nsq","mysql","postgres","elasticsearch","redis"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + addNotificationEndpointTypeServicePropEnum = append(addNotificationEndpointTypeServicePropEnum, v) + } +} + +const ( + + // AddNotificationEndpointServiceWebhook captures enum value "webhook" + AddNotificationEndpointServiceWebhook string = "webhook" + + // AddNotificationEndpointServiceAmqp captures enum value "amqp" + AddNotificationEndpointServiceAmqp string = "amqp" + + // AddNotificationEndpointServiceKafka captures enum value "kafka" + AddNotificationEndpointServiceKafka string = "kafka" + + // AddNotificationEndpointServiceMqtt captures enum value "mqtt" + AddNotificationEndpointServiceMqtt string = "mqtt" + + // AddNotificationEndpointServiceNats captures enum value "nats" + AddNotificationEndpointServiceNats string = "nats" + + // AddNotificationEndpointServiceNsq captures enum value "nsq" + AddNotificationEndpointServiceNsq string = "nsq" + + // AddNotificationEndpointServiceMysql captures enum value "mysql" + AddNotificationEndpointServiceMysql string = "mysql" + + // AddNotificationEndpointServicePostgres captures enum value "postgres" + AddNotificationEndpointServicePostgres string = "postgres" + + // AddNotificationEndpointServiceElasticsearch captures enum value "elasticsearch" + AddNotificationEndpointServiceElasticsearch string = "elasticsearch" + + // AddNotificationEndpointServiceRedis captures enum value "redis" + AddNotificationEndpointServiceRedis string = "redis" +) + +// prop value enum +func (m *AddNotificationEndpoint) validateServiceEnum(path, location string, value string) error { + if err := validate.Enum(path, location, value, addNotificationEndpointTypeServicePropEnum); err != nil { + return err + } + return nil +} + +func (m *AddNotificationEndpoint) validateService(formats strfmt.Registry) error { + + if swag.IsZero(m.Service) { // not required + return nil + } + + // value enum + if err := m.validateServiceEnum("service", "body", m.Service); err != nil { + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *AddNotificationEndpoint) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *AddNotificationEndpoint) UnmarshalBinary(b []byte) error { + var res AddNotificationEndpoint + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/nofitication_service.go b/models/nofitication_service.go new file mode 100644 index 000000000..d17847193 --- /dev/null +++ b/models/nofitication_service.go @@ -0,0 +1,104 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" +) + +// NofiticationService nofitication service +// +// swagger:model nofiticationService +type NofiticationService string + +const ( + + // NofiticationServiceWebhook captures enum value "webhook" + NofiticationServiceWebhook NofiticationService = "webhook" + + // NofiticationServiceAmqp captures enum value "amqp" + NofiticationServiceAmqp NofiticationService = "amqp" + + // NofiticationServiceKafka captures enum value "kafka" + NofiticationServiceKafka NofiticationService = "kafka" + + // NofiticationServiceMqtt captures enum value "mqtt" + NofiticationServiceMqtt NofiticationService = "mqtt" + + // NofiticationServiceNats captures enum value "nats" + NofiticationServiceNats NofiticationService = "nats" + + // NofiticationServiceNsq captures enum value "nsq" + NofiticationServiceNsq NofiticationService = "nsq" + + // NofiticationServiceMysql captures enum value "mysql" + NofiticationServiceMysql NofiticationService = "mysql" + + // NofiticationServicePostgres captures enum value "postgres" + NofiticationServicePostgres NofiticationService = "postgres" + + // NofiticationServiceElasticsearch captures enum value "elasticsearch" + NofiticationServiceElasticsearch NofiticationService = "elasticsearch" + + // NofiticationServiceRedis captures enum value "redis" + NofiticationServiceRedis NofiticationService = "redis" +) + +// for schema +var nofiticationServiceEnum []interface{} + +func init() { + var res []NofiticationService + if err := json.Unmarshal([]byte(`["webhook","amqp","kafka","mqtt","nats","nsq","mysql","postgres","elasticsearch","redis"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + nofiticationServiceEnum = append(nofiticationServiceEnum, v) + } +} + +func (m NofiticationService) validateNofiticationServiceEnum(path, location string, value NofiticationService) error { + if err := validate.Enum(path, location, value, nofiticationServiceEnum); err != nil { + return err + } + return nil +} + +// Validate validates this nofitication service +func (m NofiticationService) Validate(formats strfmt.Registry) error { + var res []error + + // value enum + if err := m.validateNofiticationServiceEnum("", "body", m); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/models/notif_endpoint_response.go b/models/notif_endpoint_response.go new file mode 100644 index 000000000..d4ad4b019 --- /dev/null +++ b/models/notif_endpoint_response.go @@ -0,0 +1,97 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NotifEndpointResponse notif endpoint response +// +// swagger:model notifEndpointResponse +type NotifEndpointResponse struct { + + // notification endpoints + NotificationEndpoints []*NotificationEndpointItem `json:"notification_endpoints"` +} + +// Validate validates this notif endpoint response +func (m *NotifEndpointResponse) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateNotificationEndpoints(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NotifEndpointResponse) validateNotificationEndpoints(formats strfmt.Registry) error { + + if swag.IsZero(m.NotificationEndpoints) { // not required + return nil + } + + for i := 0; i < len(m.NotificationEndpoints); i++ { + if swag.IsZero(m.NotificationEndpoints[i]) { // not required + continue + } + + if m.NotificationEndpoints[i] != nil { + if err := m.NotificationEndpoints[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("notification_endpoints" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *NotifEndpointResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NotifEndpointResponse) UnmarshalBinary(b []byte) error { + var res NotifEndpointResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/notification_endpoint.go b/models/notification_endpoint.go new file mode 100644 index 000000000..28cdd174a --- /dev/null +++ b/models/notification_endpoint.go @@ -0,0 +1,114 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// NotificationEndpoint notification endpoint +// +// swagger:model notificationEndpoint +type NotificationEndpoint struct { + + // account id + // Required: true + AccountID *string `json:"account_id"` + + // properties + // Required: true + Properties map[string]string `json:"properties"` + + // service + // Required: true + Service NofiticationService `json:"service"` +} + +// Validate validates this notification endpoint +func (m *NotificationEndpoint) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAccountID(formats); err != nil { + res = append(res, err) + } + + if err := m.validateProperties(formats); err != nil { + res = append(res, err) + } + + if err := m.validateService(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NotificationEndpoint) validateAccountID(formats strfmt.Registry) error { + + if err := validate.Required("account_id", "body", m.AccountID); err != nil { + return err + } + + return nil +} + +func (m *NotificationEndpoint) validateProperties(formats strfmt.Registry) error { + + return nil +} + +func (m *NotificationEndpoint) validateService(formats strfmt.Registry) error { + + if err := m.Service.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("service") + } + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *NotificationEndpoint) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NotificationEndpoint) UnmarshalBinary(b []byte) error { + var res NotificationEndpoint + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/notification_endpoint_item.go b/models/notification_endpoint_item.go new file mode 100644 index 000000000..749726aed --- /dev/null +++ b/models/notification_endpoint_item.go @@ -0,0 +1,92 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NotificationEndpointItem notification endpoint item +// +// swagger:model notificationEndpointItem +type NotificationEndpointItem struct { + + // account id + AccountID string `json:"account_id,omitempty"` + + // service + Service NofiticationService `json:"service,omitempty"` + + // status + Status string `json:"status,omitempty"` +} + +// Validate validates this notification endpoint item +func (m *NotificationEndpointItem) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateService(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NotificationEndpointItem) validateService(formats strfmt.Registry) error { + + if swag.IsZero(m.Service) { // not required + return nil + } + + if err := m.Service.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("service") + } + return err + } + + return nil +} + +// MarshalBinary interface implementation +func (m *NotificationEndpointItem) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NotificationEndpointItem) UnmarshalBinary(b []byte) error { + var res NotificationEndpointItem + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/restapi/admin_config.go b/restapi/admin_config.go index 2ad5925a1..8a91fa7af 100644 --- a/restapi/admin_config.go +++ b/restapi/admin_config.go @@ -18,6 +18,7 @@ package restapi import ( "context" + "fmt" "log" "strings" @@ -141,26 +142,28 @@ func getConfigResponse(params admin_api.ConfigInfoParams) (*models.Configuration } // setConfig sets a configuration with the defined key values -func setConfig(client MinioAdmin, name *string, kvs []*models.ConfigurationKV, arnResourceID string) error { - config := buildConfig(name, kvs, arnResourceID) - ctx := context.Background() +func setConfig(ctx context.Context, client MinioAdmin, configName *string, kvs []*models.ConfigurationKV) error { + config := buildConfig(configName, kvs) if err := client.setConfigKV(ctx, *config); err != nil { return err } return nil } +func setConfigWithARNAccountID(ctx context.Context, client MinioAdmin, configName *string, kvs []*models.ConfigurationKV, arnAccountID string) error { + // if arnAccountID is not empty the configuration will be treated as a notification target + // arnAccountID will be used as an identifier for that specific target + // docs: https://docs.min.io/docs/minio-bucket-notification-guide.html + if arnAccountID != "" { + configName = swag.String(fmt.Sprintf("%s:%s", *configName, arnAccountID)) + } + return setConfig(ctx, client, configName, kvs) +} + // buildConfig builds a concatenated string including name and keyvalues // e.g. `region name=us-west-1` -func buildConfig(name *string, kvs []*models.ConfigurationKV, arnResourceID string) *string { - // if arnResourceID is not empty the configuration will be treated as a notification target - // arnResourceID will be used as an identifier for that specific target - // docs: https://docs.min.io/docs/minio-bucket-notification-guide.html - configName := *name - if arnResourceID != "" { - configName += ":" + arnResourceID - } - configElements := []string{configName} +func buildConfig(configName *string, kvs []*models.ConfigurationKV) *string { + configElements := []string{*configName} for _, kv := range kvs { configElements = append(configElements, kv.Key+"="+kv.Value) } @@ -178,7 +181,11 @@ func setConfigResponse(name string, configRequest *models.SetConfigRequest) erro // create a MinIO Admin Client interface implementation // defining the client to be used adminClient := adminClient{client: mAdmin} - if err := setConfig(adminClient, swag.String(name), configRequest.KeyValues, configRequest.ArnResourceID); err != nil { + configName := name + + ctx := context.Background() + + if err := setConfigWithARNAccountID(ctx, adminClient, &configName, configRequest.KeyValues, configRequest.ArnResourceID); err != nil { log.Println("error listing configurations:", err) return err } diff --git a/restapi/admin_config_test.go b/restapi/admin_config_test.go index e749b60e6..c8eea2856 100644 --- a/restapi/admin_config_test.go +++ b/restapi/admin_config_test.go @@ -19,9 +19,11 @@ package restapi import ( "context" "fmt" + "reflect" "testing" "github.com/go-openapi/swag" + "github.com/minio/mcs/models" "github.com/minio/minio/pkg/madmin" @@ -173,19 +175,19 @@ func TestSetConfig(t *testing.T) { } configName := "notify_postgres" kvs := []*models.ConfigurationKV{ - &models.ConfigurationKV{ + { Key: "enable", Value: "off", }, - &models.ConfigurationKV{ + { Key: "connection_string", Value: "", }, } - arnResourceID := "" + ctx := context.Background() // Test-1 : setConfig() sets a config with two key value pairs - err := setConfig(adminClient, swag.String(configName), kvs, arnResourceID) + err := setConfig(ctx, adminClient, &configName, kvs) if err != nil { t.Errorf("Failed on %s:, error occurred: %s", function, err.Error()) } @@ -194,16 +196,153 @@ func TestSetConfig(t *testing.T) { minioSetConfigKVMock = func(kv string) error { return errors.New("error") } - if err := setConfig(adminClient, swag.String(configName), kvs, arnResourceID); assert.Error(err) { + if err := setConfig(ctx, adminClient, &configName, kvs); assert.Error(err) { assert.Equal("error", err.Error()) } - // Test-3: buildConfig() format correctly configuration as "config_name k=v k2=v2" - config := buildConfig(swag.String(configName), kvs, arnResourceID) - assert.Equal(fmt.Sprintf("%s enable=off connection_string=", configName), *config) - - // Test-4: buildConfig() format correctly configuration if it has a non empty arnResourceID as "config_name:resourceid k=v k2=v2" - arnResourceID = "postgres" - config = buildConfig(swag.String(configName), kvs, arnResourceID) - assert.Equal(fmt.Sprintf("%s:%s enable=off connection_string=", configName, arnResourceID), *config) +} + +func Test_buildConfig(t *testing.T) { + type args struct { + configName *string + kvs []*models.ConfigurationKV + } + tests := []struct { + name string + args args + want *string + }{ + // Test-1: buildConfig() format correctly configuration as "config_name k=v k2=v2" + { + name: "format correctly", + args: args{ + configName: swag.String("notify_postgres"), + kvs: []*models.ConfigurationKV{ + { + Key: "enable", + Value: "off", + }, + { + Key: "connection_string", + Value: "", + }, + }, + }, + want: swag.String("notify_postgres enable=off connection_string="), + }, + // Test-2: buildConfig() format correctly configuration as "config_name k=v k2=v2 k2=v3" with duplicate keys + { + name: "duplicated keys in config", + args: args{ + configName: swag.String("notify_postgres"), + kvs: []*models.ConfigurationKV{ + { + Key: "enable", + Value: "off", + }, + { + Key: "connection_string", + Value: "", + }, + { + Key: "connection_string", + Value: "x", + }, + }, + }, + want: swag.String("notify_postgres enable=off connection_string= connection_string=x"), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := buildConfig(tt.args.configName, tt.args.kvs); !reflect.DeepEqual(got, tt.want) { + t.Errorf("buildConfig() = %s, want %s", *got, *tt.want) + } + }) + } +} + +func Test_setConfigWithARN(t *testing.T) { + client := adminClientMock{} + + type args struct { + ctx context.Context + client MinioAdmin + configName *string + kvs []*models.ConfigurationKV + arn string + } + tests := []struct { + name string + args args + mockSetConfig func(kv string) error + wantErr bool + }{ + { + name: "Set valid config with arn", + args: args{ + ctx: context.Background(), + client: client, + configName: swag.String("notify_kafka"), + kvs: []*models.ConfigurationKV{ + { + Key: "brokers", + Value: "http://localhost:8080/broker1,http://localhost:8080/broker2", + }, + }, + arn: "1", + }, + mockSetConfig: func(kv string) error { + return nil + }, + wantErr: false, + }, + { + name: "Set valid config without arn", + args: args{ + ctx: context.Background(), + client: client, + configName: swag.String("region"), + kvs: []*models.ConfigurationKV{ + { + Key: "name", + Value: "us-west-1", + }, + }, + arn: "", + }, + mockSetConfig: func(kv string) error { + return nil + }, + wantErr: false, + }, + { + name: "Setting an incorrect config", + args: args{ + ctx: context.Background(), + client: client, + configName: swag.String("oorgle"), + kvs: []*models.ConfigurationKV{ + { + Key: "name", + Value: "us-west-1", + }, + }, + arn: "", + }, + mockSetConfig: func(kv string) error { + return errors.New("error") + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // mock function response from setConfig() + minioSetConfigKVMock = tt.mockSetConfig + if err := setConfigWithARNAccountID(tt.args.ctx, tt.args.client, tt.args.configName, tt.args.kvs, tt.args.arn); (err != nil) != tt.wantErr { + t.Errorf("setConfigWithARNAccountID() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } } diff --git a/restapi/admin_notification_endpoints.go b/restapi/admin_notification_endpoints.go new file mode 100644 index 000000000..9311cdbd3 --- /dev/null +++ b/restapi/admin_notification_endpoints.go @@ -0,0 +1,173 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package restapi + +import ( + "context" + "errors" + "log" + "time" + + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/swag" + "github.com/minio/mcs/models" + "github.com/minio/mcs/restapi/operations" + "github.com/minio/mcs/restapi/operations/admin_api" +) + +func registerAdminNotificationEndpointsHandlers(api *operations.McsAPI) { + // return a list of notification endpoints + api.AdminAPINotificationEndpointListHandler = admin_api.NotificationEndpointListHandlerFunc(func(params admin_api.NotificationEndpointListParams, principal *models.Principal) middleware.Responder { + notifEndpoints, err := getNotificationEndpointsResponse() + if err != nil { + return admin_api.NewNotificationEndpointListDefault(500).WithPayload(&models.Error{Code: 500, Message: swag.String(err.Error())}) + } + return admin_api.NewNotificationEndpointListOK().WithPayload(notifEndpoints) + }) + // add a new notification endpoints + api.AdminAPIAddNotificationEndpointHandler = admin_api.AddNotificationEndpointHandlerFunc(func(params admin_api.AddNotificationEndpointParams, principal *models.Principal) middleware.Responder { + notifEndpoints, err := getAddNotificationEndpointResponse(¶ms) + if err != nil { + return admin_api.NewAddNotificationEndpointDefault(500).WithPayload(&models.Error{Code: 500, Message: swag.String(err.Error())}) + } + return admin_api.NewAddNotificationEndpointCreated().WithPayload(notifEndpoints) + }) + +} + +// getNotificationEndpoints invokes admin info and returns a list of notification endpoints +func getNotificationEndpoints(ctx context.Context, client MinioAdmin) (*models.NotifEndpointResponse, error) { + serverInfo, err := client.serverInfo(ctx) + if err != nil { + return nil, err + } + var listEndpoints []*models.NotificationEndpointItem + for i := range serverInfo.Services.Notifications { + for service, endpointStatus := range serverInfo.Services.Notifications[i] { + for j := range endpointStatus { + for account, status := range endpointStatus[j] { + listEndpoints = append(listEndpoints, &models.NotificationEndpointItem{ + Service: models.NofiticationService(service), + AccountID: account, + Status: status.Status, + }) + } + } + + } + } + + // build response + return &models.NotifEndpointResponse{ + NotificationEndpoints: listEndpoints, + }, nil +} + +// getNotificationEndpointsResponse returns a list of notification endpoints in the instance +func getNotificationEndpointsResponse() (*models.NotifEndpointResponse, error) { + mAdmin, err := newMAdminClient() + if err != nil { + log.Println("error creating Madmin Client:", err) + return nil, err + } + // create a minioClient interface implementation + // defining the client to be used + adminClient := adminClient{client: mAdmin} + // 20 seconds timeout + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + // serialize output + notfEndpointResp, err := getNotificationEndpoints(ctx, adminClient) + if err != nil { + log.Println("error getting notification endpoint list:", err) + return nil, err + } + return notfEndpointResp, nil +} + +func addNotificationEndpoint(ctx context.Context, client MinioAdmin, params *admin_api.AddNotificationEndpointParams) (*models.NotificationEndpoint, error) { + configs := []*models.ConfigurationKV{} + var configName string + + // we have different add validations for each service + switch params.Body.Service { + case models.NofiticationServiceAmqp: + configName = "notify_amqp" + case models.NofiticationServiceMqtt: + configName = "notify_mqtt" + case models.NofiticationServiceElasticsearch: + configName = "notify_elasticsearch" + case models.NofiticationServiceRedis: + configName = "notify_redis" + case models.NofiticationServiceNats: + configName = "notify_nats" + case models.NofiticationServicePostgres: + configName = "notify_postgres" + case models.NofiticationServiceMysql: + configName = "notify_mysql" + case models.NofiticationServiceKafka: + configName = "notify_kafka" + case models.NofiticationServiceWebhook: + configName = "notify_webhook" + case models.NofiticationServiceNsq: + configName = "notify_nsq" + default: + return nil, errors.New("provided service is not supported") + } + + // set all the config values if found on the param.Body.Properties + for k, val := range params.Body.Properties { + configs = append(configs, &models.ConfigurationKV{ + Key: k, + Value: val, + }) + } + + err := setConfigWithARNAccountID(ctx, client, &configName, configs, *params.Body.AccountID) + if err != nil { + log.Println(err) + return nil, err + } + + return &models.NotificationEndpoint{ + AccountID: params.Body.AccountID, + Properties: params.Body.Properties, + Service: params.Body.Service, + }, nil +} + +// getNotificationEndpointsResponse returns a list of notification endpoints in the instance +func getAddNotificationEndpointResponse(params *admin_api.AddNotificationEndpointParams) (*models.NotificationEndpoint, error) { + mAdmin, err := newMAdminClient() + if err != nil { + log.Println("error creating Madmin Client:", err) + return nil, err + } + // create a minioClient interface implementation + // defining the client to be used + adminClient := adminClient{client: mAdmin} + // 20 seconds timeout + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + // serialize output + notfEndpointResp, err := addNotificationEndpoint(ctx, adminClient, params) + if err != nil { + log.Println("error getting notification endpoint list:", err) + return nil, err + } + return notfEndpointResp, nil +} diff --git a/restapi/admin_notification_endpoints_test.go b/restapi/admin_notification_endpoints_test.go new file mode 100644 index 000000000..f6cf957a4 --- /dev/null +++ b/restapi/admin_notification_endpoints_test.go @@ -0,0 +1,411 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package restapi + +import ( + "context" + "errors" + "reflect" + "testing" + + "github.com/go-openapi/swag" + + "github.com/minio/mcs/models" + "github.com/minio/mcs/restapi/operations/admin_api" +) + +func Test_addNotificationEndpoint(t *testing.T) { + client := adminClientMock{} + + type args struct { + ctx context.Context + client MinioAdmin + params *admin_api.AddNotificationEndpointParams + } + tests := []struct { + name string + args args + mockSetConfig func(kv string) error + want *models.NotificationEndpoint + wantErr bool + }{ + { + name: "valid postgres", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "host": "localhost", + "user": "user", + "password": "passwrd", + }, + Service: "postgres", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "host": "localhost", + "user": "user", + "password": "passwrd", + }, + Service: "postgres", + }, + wantErr: false, + }, + { + name: "set config returns error", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "host": "localhost", + "user": "user", + "password": "passwrd", + }, + Service: "postgres", + }, + }, + }, + mockSetConfig: func(kv string) error { + return errors.New("error") + }, + want: nil, + wantErr: true, + }, + { + name: "valid mysql", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "host": "localhost", + "user": "user", + "password": "passwrd", + }, + Service: "mysql", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "host": "localhost", + "user": "user", + "password": "passwrd", + }, + Service: "mysql", + }, + wantErr: false, + }, + { + name: "valid kafka", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "brokers": "http://localhost:8080/broker1", + }, + Service: "kafka", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "brokers": "http://localhost:8080/broker1", + }, + Service: "kafka", + }, + wantErr: false, + }, + { + name: "valid amqp", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "url": "http://localhost:8080/broker1", + }, + Service: "amqp", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "url": "http://localhost:8080/broker1", + }, + Service: "amqp", + }, + wantErr: false, + }, + { + name: "valid mqtt", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "broker": "http://localhost:8080/broker1", + "topic": "minio", + }, + Service: "mqtt", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "broker": "http://localhost:8080/broker1", + "topic": "minio", + }, + Service: "mqtt", + }, + wantErr: false, + }, + { + name: "valid elasticsearch", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "url": "http://localhost:8080/broker1", + "index": "minio", + "format": "namespace", + }, + Service: "elasticsearch", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "url": "http://localhost:8080/broker1", + "index": "minio", + "format": "namespace", + }, + Service: "elasticsearch", + }, + wantErr: false, + }, + { + name: "valid redis", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "address": "http://localhost:8080/broker1", + "key": "minio", + "format": "namespace", + }, + Service: "redis", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "address": "http://localhost:8080/broker1", + "key": "minio", + "format": "namespace", + }, + Service: "redis", + }, + wantErr: false, + }, + { + name: "valid nats", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "address": "http://localhost:8080/broker1", + "subject": "minio", + }, + Service: "nats", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "address": "http://localhost:8080/broker1", + "subject": "minio", + }, + Service: "nats", + }, + wantErr: false, + }, + { + name: "valid webhook", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "endpoint": "http://localhost:8080/broker1", + }, + Service: "webhook", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "endpoint": "http://localhost:8080/broker1", + }, + Service: "webhook", + }, + wantErr: false, + }, + { + name: "valid nsq", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "nsqd_address": "http://localhost:8080/broker1", + "topic": "minio", + }, + Service: "nsq", + }, + }, + }, + mockSetConfig: func(kv string) error { + return nil + }, + want: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "nsqd_address": "http://localhost:8080/broker1", + "topic": "minio", + }, + Service: "nsq", + }, + wantErr: false, + }, + { + name: "invalid service", + args: args{ + ctx: context.Background(), + client: client, + params: &admin_api.AddNotificationEndpointParams{ + HTTPRequest: nil, + Body: &models.NotificationEndpoint{ + AccountID: swag.String("1"), + Properties: map[string]string{ + "host": "localhost", + "user": "user", + "password": "passwrd", + }, + Service: "oorgle", + }, + }, + }, + mockSetConfig: func(kv string) error { + return errors.New("invalid config") + }, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // mock function response from setConfig() + minioSetConfigKVMock = tt.mockSetConfig + got, err := addNotificationEndpoint(tt.args.ctx, tt.args.client, tt.args.params) + if (err != nil) != tt.wantErr { + t.Errorf("addNotificationEndpoint() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("addNotificationEndpoint() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/restapi/configure_mcs.go b/restapi/configure_mcs.go index d985ef5cc..465b14da8 100644 --- a/restapi/configure_mcs.go +++ b/restapi/configure_mcs.go @@ -94,6 +94,8 @@ func configureAPI(api *operations.McsAPI) http.Handler { registerAdminInfoHandlers(api) // Register admin arns handlers registerAdminArnsHandlers(api) + // Register admin notification endpoints handlers + registerAdminNotificationEndpointsHandlers(api) api.PreServerShutdown = func() {} diff --git a/restapi/embedded_spec.go b/restapi/embedded_spec.go index 693b07afe..38dd21d20 100644 --- a/restapi/embedded_spec.go +++ b/restapi/embedded_spec.go @@ -97,6 +97,60 @@ func init() { } } }, + "/admin/notification_endpoints": { + "get": { + "tags": [ + "AdminAPI" + ], + "summary": "Returns a list of active notification endpoints", + "operationId": "NotificationEndpointList", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/notifEndpointResponse" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, + "post": { + "tags": [ + "AdminAPI" + ], + "summary": "Allows to configure a new notification endpoint", + "operationId": "AddNotificationEndpoint", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/notificationEndpoint" + } + } + ], + "responses": { + "201": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/notificationEndpoint" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/buckets": { "get": { "tags": [ @@ -1444,6 +1498,32 @@ func init() { } } }, + "nofiticationService": { + "type": "string", + "enum": [ + "webhook", + "amqp", + "kafka", + "mqtt", + "nats", + "nsq", + "mysql", + "postgres", + "elasticsearch", + "redis" + ] + }, + "notifEndpointResponse": { + "type": "object", + "properties": { + "notification_endpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/notificationEndpointItem" + } + } + } + }, "notificationConfig": { "type": "object", "required": [ @@ -1473,6 +1553,42 @@ func init() { } } }, + "notificationEndpoint": { + "type": "object", + "required": [ + "service", + "account_id", + "properties" + ], + "properties": { + "account_id": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "service": { + "$ref": "#/definitions/nofiticationService" + } + } + }, + "notificationEndpointItem": { + "type": "object", + "properties": { + "account_id": { + "type": "string" + }, + "service": { + "$ref": "#/definitions/nofiticationService" + }, + "status": { + "type": "string" + } + } + }, "notificationEventType": { "type": "string", "enum": [ @@ -1742,6 +1858,60 @@ func init() { } } }, + "/admin/notification_endpoints": { + "get": { + "tags": [ + "AdminAPI" + ], + "summary": "Returns a list of active notification endpoints", + "operationId": "NotificationEndpointList", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/notifEndpointResponse" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + }, + "post": { + "tags": [ + "AdminAPI" + ], + "summary": "Allows to configure a new notification endpoint", + "operationId": "AddNotificationEndpoint", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/notificationEndpoint" + } + } + ], + "responses": { + "201": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/notificationEndpoint" + } + }, + "default": { + "description": "Generic error response.", + "schema": { + "$ref": "#/definitions/error" + } + } + } + } + }, "/buckets": { "get": { "tags": [ @@ -3089,6 +3259,32 @@ func init() { } } }, + "nofiticationService": { + "type": "string", + "enum": [ + "webhook", + "amqp", + "kafka", + "mqtt", + "nats", + "nsq", + "mysql", + "postgres", + "elasticsearch", + "redis" + ] + }, + "notifEndpointResponse": { + "type": "object", + "properties": { + "notification_endpoints": { + "type": "array", + "items": { + "$ref": "#/definitions/notificationEndpointItem" + } + } + } + }, "notificationConfig": { "type": "object", "required": [ @@ -3118,6 +3314,42 @@ func init() { } } }, + "notificationEndpoint": { + "type": "object", + "required": [ + "service", + "account_id", + "properties" + ], + "properties": { + "account_id": { + "type": "string" + }, + "properties": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "service": { + "$ref": "#/definitions/nofiticationService" + } + } + }, + "notificationEndpointItem": { + "type": "object", + "properties": { + "account_id": { + "type": "string" + }, + "service": { + "$ref": "#/definitions/nofiticationService" + }, + "status": { + "type": "string" + } + } + }, "notificationEventType": { "type": "string", "enum": [ diff --git a/restapi/operations/admin_api/add_notification_endpoint.go b/restapi/operations/admin_api/add_notification_endpoint.go new file mode 100644 index 000000000..7d97c9e7a --- /dev/null +++ b/restapi/operations/admin_api/add_notification_endpoint.go @@ -0,0 +1,90 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" + + "github.com/minio/mcs/models" +) + +// AddNotificationEndpointHandlerFunc turns a function with the right signature into a add notification endpoint handler +type AddNotificationEndpointHandlerFunc func(AddNotificationEndpointParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn AddNotificationEndpointHandlerFunc) Handle(params AddNotificationEndpointParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// AddNotificationEndpointHandler interface for that can handle valid add notification endpoint params +type AddNotificationEndpointHandler interface { + Handle(AddNotificationEndpointParams, *models.Principal) middleware.Responder +} + +// NewAddNotificationEndpoint creates a new http.Handler for the add notification endpoint operation +func NewAddNotificationEndpoint(ctx *middleware.Context, handler AddNotificationEndpointHandler) *AddNotificationEndpoint { + return &AddNotificationEndpoint{Context: ctx, Handler: handler} +} + +/*AddNotificationEndpoint swagger:route POST /admin/notification_endpoints AdminAPI addNotificationEndpoint + +Allows to configure a new notification endpoint + +*/ +type AddNotificationEndpoint struct { + Context *middleware.Context + Handler AddNotificationEndpointHandler +} + +func (o *AddNotificationEndpoint) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewAddNotificationEndpointParams() + + uprinc, aCtx, err := o.Context.Authorize(r, route) + if err != nil { + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + if aCtx != nil { + r = aCtx + } + var principal *models.Principal + if uprinc != nil { + principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise + } + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params, principal) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/admin_api/add_notification_endpoint_parameters.go b/restapi/operations/admin_api/add_notification_endpoint_parameters.go new file mode 100644 index 000000000..8ee765603 --- /dev/null +++ b/restapi/operations/admin_api/add_notification_endpoint_parameters.go @@ -0,0 +1,94 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + + "github.com/minio/mcs/models" +) + +// NewAddNotificationEndpointParams creates a new AddNotificationEndpointParams object +// no default values defined in spec. +func NewAddNotificationEndpointParams() AddNotificationEndpointParams { + + return AddNotificationEndpointParams{} +} + +// AddNotificationEndpointParams contains all the bound params for the add notification endpoint operation +// typically these are obtained from a http.Request +// +// swagger:parameters AddNotificationEndpoint +type AddNotificationEndpointParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: body + */ + Body *models.NotificationEndpoint +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewAddNotificationEndpointParams() beforehand. +func (o *AddNotificationEndpointParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.NotificationEndpoint + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("body", "body")) + } else { + res = append(res, errors.NewParseError("body", "body", "", err)) + } + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Body = &body + } + } + } else { + res = append(res, errors.Required("body", "body")) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/restapi/operations/admin_api/add_notification_endpoint_responses.go b/restapi/operations/admin_api/add_notification_endpoint_responses.go new file mode 100644 index 000000000..89bbabd12 --- /dev/null +++ b/restapi/operations/admin_api/add_notification_endpoint_responses.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/minio/mcs/models" +) + +// AddNotificationEndpointCreatedCode is the HTTP code returned for type AddNotificationEndpointCreated +const AddNotificationEndpointCreatedCode int = 201 + +/*AddNotificationEndpointCreated A successful response. + +swagger:response addNotificationEndpointCreated +*/ +type AddNotificationEndpointCreated struct { + + /* + In: Body + */ + Payload *models.NotificationEndpoint `json:"body,omitempty"` +} + +// NewAddNotificationEndpointCreated creates AddNotificationEndpointCreated with default headers values +func NewAddNotificationEndpointCreated() *AddNotificationEndpointCreated { + + return &AddNotificationEndpointCreated{} +} + +// WithPayload adds the payload to the add notification endpoint created response +func (o *AddNotificationEndpointCreated) WithPayload(payload *models.NotificationEndpoint) *AddNotificationEndpointCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the add notification endpoint created response +func (o *AddNotificationEndpointCreated) SetPayload(payload *models.NotificationEndpoint) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *AddNotificationEndpointCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +/*AddNotificationEndpointDefault Generic error response. + +swagger:response addNotificationEndpointDefault +*/ +type AddNotificationEndpointDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewAddNotificationEndpointDefault creates AddNotificationEndpointDefault with default headers values +func NewAddNotificationEndpointDefault(code int) *AddNotificationEndpointDefault { + if code <= 0 { + code = 500 + } + + return &AddNotificationEndpointDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the add notification endpoint default response +func (o *AddNotificationEndpointDefault) WithStatusCode(code int) *AddNotificationEndpointDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the add notification endpoint default response +func (o *AddNotificationEndpointDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the add notification endpoint default response +func (o *AddNotificationEndpointDefault) WithPayload(payload *models.Error) *AddNotificationEndpointDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the add notification endpoint default response +func (o *AddNotificationEndpointDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *AddNotificationEndpointDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/admin_api/add_notification_endpoint_urlbuilder.go b/restapi/operations/admin_api/add_notification_endpoint_urlbuilder.go new file mode 100644 index 000000000..1f311dd1d --- /dev/null +++ b/restapi/operations/admin_api/add_notification_endpoint_urlbuilder.go @@ -0,0 +1,104 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// AddNotificationEndpointURL generates an URL for the add notification endpoint operation +type AddNotificationEndpointURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *AddNotificationEndpointURL) WithBasePath(bp string) *AddNotificationEndpointURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *AddNotificationEndpointURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *AddNotificationEndpointURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/admin/notification_endpoints" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/api/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *AddNotificationEndpointURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *AddNotificationEndpointURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *AddNotificationEndpointURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on AddNotificationEndpointURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on AddNotificationEndpointURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *AddNotificationEndpointURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/restapi/operations/admin_api/notification_endpoint_list.go b/restapi/operations/admin_api/notification_endpoint_list.go new file mode 100644 index 000000000..f79a329b3 --- /dev/null +++ b/restapi/operations/admin_api/notification_endpoint_list.go @@ -0,0 +1,90 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" + + "github.com/minio/mcs/models" +) + +// NotificationEndpointListHandlerFunc turns a function with the right signature into a notification endpoint list handler +type NotificationEndpointListHandlerFunc func(NotificationEndpointListParams, *models.Principal) middleware.Responder + +// Handle executing the request and returning a response +func (fn NotificationEndpointListHandlerFunc) Handle(params NotificationEndpointListParams, principal *models.Principal) middleware.Responder { + return fn(params, principal) +} + +// NotificationEndpointListHandler interface for that can handle valid notification endpoint list params +type NotificationEndpointListHandler interface { + Handle(NotificationEndpointListParams, *models.Principal) middleware.Responder +} + +// NewNotificationEndpointList creates a new http.Handler for the notification endpoint list operation +func NewNotificationEndpointList(ctx *middleware.Context, handler NotificationEndpointListHandler) *NotificationEndpointList { + return &NotificationEndpointList{Context: ctx, Handler: handler} +} + +/*NotificationEndpointList swagger:route GET /admin/notification_endpoints AdminAPI notificationEndpointList + +Returns a list of active notification endpoints + +*/ +type NotificationEndpointList struct { + Context *middleware.Context + Handler NotificationEndpointListHandler +} + +func (o *NotificationEndpointList) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + r = rCtx + } + var Params = NewNotificationEndpointListParams() + + uprinc, aCtx, err := o.Context.Authorize(r, route) + if err != nil { + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + if aCtx != nil { + r = aCtx + } + var principal *models.Principal + if uprinc != nil { + principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise + } + + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params, principal) // actually handle the request + + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/restapi/operations/admin_api/notification_endpoint_list_parameters.go b/restapi/operations/admin_api/notification_endpoint_list_parameters.go new file mode 100644 index 000000000..ede97a572 --- /dev/null +++ b/restapi/operations/admin_api/notification_endpoint_list_parameters.go @@ -0,0 +1,62 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" +) + +// NewNotificationEndpointListParams creates a new NotificationEndpointListParams object +// no default values defined in spec. +func NewNotificationEndpointListParams() NotificationEndpointListParams { + + return NotificationEndpointListParams{} +} + +// NotificationEndpointListParams contains all the bound params for the notification endpoint list operation +// typically these are obtained from a http.Request +// +// swagger:parameters NotificationEndpointList +type NotificationEndpointListParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewNotificationEndpointListParams() beforehand. +func (o *NotificationEndpointListParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/restapi/operations/admin_api/notification_endpoint_list_responses.go b/restapi/operations/admin_api/notification_endpoint_list_responses.go new file mode 100644 index 000000000..b80793b01 --- /dev/null +++ b/restapi/operations/admin_api/notification_endpoint_list_responses.go @@ -0,0 +1,133 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/minio/mcs/models" +) + +// NotificationEndpointListOKCode is the HTTP code returned for type NotificationEndpointListOK +const NotificationEndpointListOKCode int = 200 + +/*NotificationEndpointListOK A successful response. + +swagger:response notificationEndpointListOK +*/ +type NotificationEndpointListOK struct { + + /* + In: Body + */ + Payload *models.NotifEndpointResponse `json:"body,omitempty"` +} + +// NewNotificationEndpointListOK creates NotificationEndpointListOK with default headers values +func NewNotificationEndpointListOK() *NotificationEndpointListOK { + + return &NotificationEndpointListOK{} +} + +// WithPayload adds the payload to the notification endpoint list o k response +func (o *NotificationEndpointListOK) WithPayload(payload *models.NotifEndpointResponse) *NotificationEndpointListOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the notification endpoint list o k response +func (o *NotificationEndpointListOK) SetPayload(payload *models.NotifEndpointResponse) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *NotificationEndpointListOK) 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 + } + } +} + +/*NotificationEndpointListDefault Generic error response. + +swagger:response notificationEndpointListDefault +*/ +type NotificationEndpointListDefault struct { + _statusCode int + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewNotificationEndpointListDefault creates NotificationEndpointListDefault with default headers values +func NewNotificationEndpointListDefault(code int) *NotificationEndpointListDefault { + if code <= 0 { + code = 500 + } + + return &NotificationEndpointListDefault{ + _statusCode: code, + } +} + +// WithStatusCode adds the status to the notification endpoint list default response +func (o *NotificationEndpointListDefault) WithStatusCode(code int) *NotificationEndpointListDefault { + o._statusCode = code + return o +} + +// SetStatusCode sets the status to the notification endpoint list default response +func (o *NotificationEndpointListDefault) SetStatusCode(code int) { + o._statusCode = code +} + +// WithPayload adds the payload to the notification endpoint list default response +func (o *NotificationEndpointListDefault) WithPayload(payload *models.Error) *NotificationEndpointListDefault { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the notification endpoint list default response +func (o *NotificationEndpointListDefault) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *NotificationEndpointListDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(o._statusCode) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/restapi/operations/admin_api/notification_endpoint_list_urlbuilder.go b/restapi/operations/admin_api/notification_endpoint_list_urlbuilder.go new file mode 100644 index 000000000..cff8e8f3f --- /dev/null +++ b/restapi/operations/admin_api/notification_endpoint_list_urlbuilder.go @@ -0,0 +1,104 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2020 MinIO, Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// + +package admin_api + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// NotificationEndpointListURL generates an URL for the notification endpoint list operation +type NotificationEndpointListURL struct { + _basePath string +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *NotificationEndpointListURL) WithBasePath(bp string) *NotificationEndpointListURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *NotificationEndpointListURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *NotificationEndpointListURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/admin/notification_endpoints" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/api/v1" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *NotificationEndpointListURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *NotificationEndpointListURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *NotificationEndpointListURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on NotificationEndpointListURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on NotificationEndpointListURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *NotificationEndpointListURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/restapi/operations/mcs_api.go b/restapi/operations/mcs_api.go index 294f26fea..02e197fe9 100644 --- a/restapi/operations/mcs_api.go +++ b/restapi/operations/mcs_api.go @@ -66,6 +66,9 @@ func NewMcsAPI(spec *loads.Document) *McsAPI { AdminAPIAddGroupHandler: admin_api.AddGroupHandlerFunc(func(params admin_api.AddGroupParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.AddGroup has not yet been implemented") }), + AdminAPIAddNotificationEndpointHandler: admin_api.AddNotificationEndpointHandlerFunc(func(params admin_api.AddNotificationEndpointParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation admin_api.AddNotificationEndpoint has not yet been implemented") + }), AdminAPIAddPolicyHandler: admin_api.AddPolicyHandlerFunc(func(params admin_api.AddPolicyParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.AddPolicy has not yet been implemented") }), @@ -129,6 +132,9 @@ func NewMcsAPI(spec *loads.Document) *McsAPI { UserAPIMakeBucketHandler: user_api.MakeBucketHandlerFunc(func(params user_api.MakeBucketParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation user_api.MakeBucket has not yet been implemented") }), + AdminAPINotificationEndpointListHandler: admin_api.NotificationEndpointListHandlerFunc(func(params admin_api.NotificationEndpointListParams, principal *models.Principal) middleware.Responder { + return middleware.NotImplemented("operation admin_api.NotificationEndpointList has not yet been implemented") + }), AdminAPIPolicyInfoHandler: admin_api.PolicyInfoHandlerFunc(func(params admin_api.PolicyInfoParams, principal *models.Principal) middleware.Responder { return middleware.NotImplemented("operation admin_api.PolicyInfo has not yet been implemented") }), @@ -216,6 +222,8 @@ type McsAPI struct { // AdminAPIAddGroupHandler sets the operation handler for the add group operation AdminAPIAddGroupHandler admin_api.AddGroupHandler + // AdminAPIAddNotificationEndpointHandler sets the operation handler for the add notification endpoint operation + AdminAPIAddNotificationEndpointHandler admin_api.AddNotificationEndpointHandler // AdminAPIAddPolicyHandler sets the operation handler for the add policy operation AdminAPIAddPolicyHandler admin_api.AddPolicyHandler // AdminAPIAddUserHandler sets the operation handler for the add user operation @@ -258,6 +266,8 @@ type McsAPI struct { UserAPILogoutHandler user_api.LogoutHandler // UserAPIMakeBucketHandler sets the operation handler for the make bucket operation UserAPIMakeBucketHandler user_api.MakeBucketHandler + // AdminAPINotificationEndpointListHandler sets the operation handler for the notification endpoint list operation + AdminAPINotificationEndpointListHandler admin_api.NotificationEndpointListHandler // AdminAPIPolicyInfoHandler sets the operation handler for the policy info operation AdminAPIPolicyInfoHandler admin_api.PolicyInfoHandler // AdminAPIProfilingStartHandler sets the operation handler for the profiling start operation @@ -358,6 +368,9 @@ func (o *McsAPI) Validate() error { if o.AdminAPIAddGroupHandler == nil { unregistered = append(unregistered, "admin_api.AddGroupHandler") } + if o.AdminAPIAddNotificationEndpointHandler == nil { + unregistered = append(unregistered, "admin_api.AddNotificationEndpointHandler") + } if o.AdminAPIAddPolicyHandler == nil { unregistered = append(unregistered, "admin_api.AddPolicyHandler") } @@ -421,6 +434,9 @@ func (o *McsAPI) Validate() error { if o.UserAPIMakeBucketHandler == nil { unregistered = append(unregistered, "user_api.MakeBucketHandler") } + if o.AdminAPINotificationEndpointListHandler == nil { + unregistered = append(unregistered, "admin_api.NotificationEndpointListHandler") + } if o.AdminAPIPolicyInfoHandler == nil { unregistered = append(unregistered, "admin_api.PolicyInfoHandler") } @@ -564,6 +580,10 @@ func (o *McsAPI) initHandlerCache() { if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) } + o.handlers["POST"]["/admin/notification_endpoints"] = admin_api.NewAddNotificationEndpoint(o.context, o.AdminAPIAddNotificationEndpointHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } o.handlers["POST"]["/policies"] = admin_api.NewAddPolicy(o.context, o.AdminAPIAddPolicyHandler) if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) @@ -648,6 +668,10 @@ func (o *McsAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) } + o.handlers["GET"]["/admin/notification_endpoints"] = admin_api.NewNotificationEndpointList(o.context, o.AdminAPINotificationEndpointListHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } o.handlers["GET"]["/policies/{name}"] = admin_api.NewPolicyInfo(o.context, o.AdminAPIPolicyInfoHandler) if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) diff --git a/swagger.yml b/swagger.yml index 16173648d..5b4a63363 100644 --- a/swagger.yml +++ b/swagger.yml @@ -720,6 +720,41 @@ paths: $ref: "#/definitions/error" tags: - AdminAPI + /admin/notification_endpoints: + get: + summary: Returns a list of active notification endpoints + operationId: NotificationEndpointList + responses: + 200: + description: A successful response. + schema: + $ref: "#/definitions/notifEndpointResponse" + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - AdminAPI + post: + summary: Allows to configure a new notification endpoint + operationId: AddNotificationEndpoint + parameters: + - name: body + in: body + required: true + schema: + $ref: '#/definitions/notificationEndpoint' + responses: + 201: + description: A successful response. + schema: + $ref: '#/definitions/notificationEndpoint' + default: + description: Generic error response. + schema: + $ref: "#/definitions/error" + tags: + - AdminAPI definitions: bucketAccess: type: string @@ -1091,3 +1126,47 @@ definitions: type: array items: type: string + nofiticationService: + type: string + enum: + - webhook + - amqp + - kafka + - mqtt + - nats + - nsq + - mysql + - postgres + - elasticsearch + - redis + notificationEndpointItem: + type: object + properties: + service: + $ref: "#/definitions/nofiticationService" + account_id: + type: string + status: + type: string + notificationEndpoint: + type: object + required: + - service + - account_id + - properties + properties: + service: + $ref: "#/definitions/nofiticationService" + account_id: + type: string + properties: + type: object + additionalProperties: + type: string + notifEndpointResponse: + type: object + properties: + notification_endpoints: + type: array + items: + $ref: "#/definitions/notificationEndpointItem"