Skip to content

Commit

Permalink
feat: add a diagnostic when enumerating unsuported types
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Guibert committed Nov 7, 2022
1 parent 49cdbc8 commit 3717a53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions enumeration/alerter/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package alerter

import (
"encoding/json"
"fmt"

"github.com/snyk/driftctl/enumeration/resource"
)
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion enumeration/enumerator/cloud_enumerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 3717a53

Please sign in to comment.