mirror of
https://github.com/minio/minio.git
synced 2025-11-09 13:39:46 -05:00
fix: Don't allow to set unconfigured notification ARNs (#8643)
Fixes #8642
This commit is contained in:
@@ -39,15 +39,18 @@ const (
|
||||
|
||||
// TestNotificationTargets is similar to GetNotificationTargets()
|
||||
// avoids explicit registration.
|
||||
func TestNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport) error {
|
||||
_, err := RegisterNotificationTargets(cfg, doneCh, transport, true)
|
||||
func TestNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport,
|
||||
targetIDs []event.TargetID) error {
|
||||
test := true
|
||||
_, err := RegisterNotificationTargets(cfg, doneCh, transport, targetIDs, test)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetNotificationTargets registers and initializes all notification
|
||||
// targets, returns error if any.
|
||||
func GetNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport) (*event.TargetList, error) {
|
||||
return RegisterNotificationTargets(cfg, doneCh, transport, false)
|
||||
test := false
|
||||
return RegisterNotificationTargets(cfg, doneCh, transport, nil, test)
|
||||
}
|
||||
|
||||
// RegisterNotificationTargets - returns TargetList which contains enabled targets in serverConfig.
|
||||
@@ -55,7 +58,7 @@ func GetNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport
|
||||
// * Add a new target in pkg/event/target package.
|
||||
// * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>.
|
||||
// * Handle the configuration in this function to create/add into TargetList.
|
||||
func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, test bool) (*event.TargetList, error) {
|
||||
func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, targetIDs []event.TargetID, test bool) (*event.TargetList, error) {
|
||||
targetList := event.NewTargetList()
|
||||
if err := checkValidNotificationKeys(cfg); err != nil {
|
||||
return nil, err
|
||||
@@ -119,13 +122,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range esTargets {
|
||||
@@ -137,13 +139,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
return nil, err
|
||||
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range kafkaTargets {
|
||||
@@ -155,13 +156,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range mqttTargets {
|
||||
@@ -173,13 +173,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range mysqlTargets {
|
||||
@@ -190,13 +189,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range natsTargets {
|
||||
@@ -207,13 +205,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range nsqTargets {
|
||||
@@ -224,13 +221,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range postgresTargets {
|
||||
@@ -241,13 +237,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range redisTargets {
|
||||
@@ -258,13 +253,12 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err = targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
}
|
||||
}
|
||||
|
||||
for id, args := range webhookTargets {
|
||||
@@ -275,12 +269,24 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if test {
|
||||
newTarget.Close()
|
||||
continue
|
||||
}
|
||||
if err := targetList.Add(newTarget); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if test {
|
||||
// Verify if user is trying to disable already configured
|
||||
// notification targets, based on their target IDs
|
||||
for _, targetID := range targetIDs {
|
||||
if !targetList.Exists(targetID) {
|
||||
return nil, config.Errorf(config.SafeModeKind,
|
||||
"Unable to disable configured targets '%v'",
|
||||
targetID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user