2021-01-20 13:01:57 +00:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-02-11 11:21:49 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2021-01-20 13:01:57 +00:00
|
|
|
|
|
|
|
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/alerter"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HandleResourceEnumerationError(err error, alertr *alerter.Alerter) error {
|
|
|
|
listError, ok := err.(*remoteerror.ResourceEnumerationError)
|
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
reqerr, ok := listError.RootCause().(awserr.RequestFailure)
|
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-02-11 11:21:49 +00:00
|
|
|
if reqerr.StatusCode() == 403 || (reqerr.StatusCode() == 400 && strings.Contains(reqerr.Code(), "AccessDenied")) {
|
2021-01-20 13:01:57 +00:00
|
|
|
message := fmt.Sprintf("Ignoring %s from drift calculation: Listing %s is forbidden.", listError.SupplierType(), listError.ListedTypeError())
|
|
|
|
logrus.Debugf(message)
|
|
|
|
alertr.SendAlert(listError.SupplierType(), alerter.Alert{
|
|
|
|
Message: message,
|
|
|
|
ShouldIgnoreResource: true,
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|