2020-12-09 15:31:34 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2021-12-06 13:29:39 +00:00
|
|
|
"github.com/snyk/driftctl/pkg/resource"
|
2020-12-09 15:31:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Chain []Middleware
|
|
|
|
|
|
|
|
func NewChain(middlewares ...Middleware) Chain {
|
|
|
|
return middlewares
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:03:04 +00:00
|
|
|
func (c Chain) Execute(remoteResources, resourcesFromState *[]*resource.Resource) error {
|
2020-12-09 15:31:34 +00:00
|
|
|
for _, middleware := range c {
|
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"middleware": fmt.Sprintf("%T", middleware),
|
|
|
|
}).Debug("Starting middleware")
|
|
|
|
err := middleware.Execute(remoteResources, resourcesFromState)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|