From 3717a53fa01c15c9f224796ed2383296282dd41d Mon Sep 17 00:00:00 2001 From: Martin Guibert Date: Wed, 28 Sep 2022 17:15:56 +0200 Subject: [PATCH] feat: add a diagnostic when enumerating unsuported types --- enumeration/alerter/alert.go | 21 +++++++++++++++++++++ enumeration/enumerator/cloud_enumerator.go | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/enumeration/alerter/alert.go b/enumeration/alerter/alert.go index 32ce075a2..badcf28f3 100644 --- a/enumeration/alerter/alert.go +++ b/enumeration/alerter/alert.go @@ -2,6 +2,7 @@ package alerter import ( "encoding/json" + "fmt" "github.com/snyk/driftctl/enumeration/resource" ) @@ -14,6 +15,26 @@ type Alert interface { Resource() *resource.Resource } +type UnsupportedResourcetypeAlert struct { + Typ string +} + +func NewUnsupportedResourcetypeAlert(typ string) *UnsupportedResourcetypeAlert { + return &UnsupportedResourcetypeAlert{Typ: typ} +} + +func (f *UnsupportedResourcetypeAlert) Message() string { + return fmt.Sprintf("%s is not supported...", f.Typ) +} + +func (f *UnsupportedResourcetypeAlert) ShouldIgnoreResource() bool { + return false +} + +func (f *UnsupportedResourcetypeAlert) Resource() *resource.Resource { + return nil +} + type FakeAlert struct { Msg string IgnoreResource bool diff --git a/enumeration/enumerator/cloud_enumerator.go b/enumeration/enumerator/cloud_enumerator.go index 1b962168c..3c8aaed13 100644 --- a/enumeration/enumerator/cloud_enumerator.go +++ b/enumeration/enumerator/cloud_enumerator.go @@ -100,13 +100,18 @@ func (e *CloudEnumerator) Enumerate(input *enumeration.EnumerateInput) (*enumera e.alerter.alerts = alerter.Alerts{} + enumerators := e.remoteLibrary.Enumerators() + types := map[string]struct{}{} for _, resourceType := range input.ResourceTypes { + if !resource.IsResourceTypeSupported(resourceType) { + e.alerter.SendAlert(resourceType, alerter.NewUnsupportedResourcetypeAlert(resourceType)) + } types[resourceType] = struct{}{} } filter := typeFilter{types: types} - for _, enumerator := range e.remoteLibrary.Enumerators() { + for _, enumerator := range enumerators { if filter.IsTypeIgnored(enumerator.SupportedType()) { logrus.WithFields(logrus.Fields{ "type": enumerator.SupportedType(),